BooleanConsoleItem.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.protocol.sdk.properties;

  21. import org.openspcoop2.protocol.sdk.ProtocolException;
  22. import org.openspcoop2.protocol.sdk.constants.ConsoleItemType;

  23. /**
  24.  * BooleanConsoleItem
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class BooleanConsoleItem extends AbstractConsoleItem<Boolean> {

  31.     // serve per gestire i 3 stati null, false e true
  32.     // Tale opzione non e' utilizzabile se il default di una checkbox e' true ed e' abilitato il reload
  33.     private boolean convertFalseAsNull = true; // lascio il default attuale
  34.     public void setConvertFalseAsNull(boolean convertFalseAsNull) {
  35.         this.convertFalseAsNull = convertFalseAsNull;
  36.     }
  37.     public boolean isConvertFalseAsNull() {
  38.         if(ConsoleItemType.CHECKBOX.equals(this.getType()) && this.getDefaultValue()!=null && this.getDefaultValue() && this.isReloadOnChange()) {
  39.             return false;
  40.         }
  41.         else {
  42.             return this.convertFalseAsNull;
  43.         }
  44.     }

  45.     protected BooleanConsoleItem(String id, String label, ConsoleItemType type) throws ProtocolException {
  46.         super(id, label, type);
  47.     }
  48.    
  49.     @Override
  50.     protected Boolean cloneValue(Boolean value) throws ProtocolException {
  51.         try {
  52.             return Boolean.valueOf(value.booleanValue()+"");
  53.         }catch(Exception e) {
  54.             throw new ProtocolException(e.getMessage(),e);
  55.         }
  56.     }
  57. }