ProtocolPropertiesFactory.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. import org.openspcoop2.protocol.sdk.constants.ConsoleItemValueType;

  24. /**
  25.  * ProtocolPropertiesFactory
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class ProtocolPropertiesFactory {
  32.    
  33.     private ProtocolPropertiesFactory() {}

  34.     public static BaseConsoleItem newTitleItem(String id, String label) throws ProtocolException{
  35.         return new TitleConsoleItem(id, label);
  36.     }
  37.     public static BaseConsoleItem newSubTitleItem(String id, String label) throws ProtocolException{
  38.         return new SubtitleConsoleItem(id, label);
  39.     }
  40.     public static BaseConsoleItem newNoteItem(String id, String label) throws ProtocolException{
  41.         return new BaseConsoleItem(id, label, ConsoleItemType.NOTE);
  42.     }
  43.    
  44.     public static AbstractConsoleItem<?> newConsoleItem(ConsoleItemType itemType, String id, String label) throws ProtocolException{
  45.         return newConsoleItem(ConsoleItemValueType.STRING, itemType, id, label);
  46.     }
  47.     public static AbstractConsoleItem<?> newConsoleItem(ConsoleItemValueType type, ConsoleItemType itemType, String id, String label) throws ProtocolException{
  48.         switch (type) {
  49.             case STRING:
  50.                 return new StringConsoleItem(id, label, itemType);
  51.             case NUMBER:
  52.                 return new NumberConsoleItem(id, label, itemType);
  53.             case BOOLEAN:
  54.                 return new BooleanConsoleItem(id, label, itemType);
  55.             case BINARY:
  56.                 return new BinaryConsoleItem(id, label, itemType);
  57.         }
  58.         throw new ProtocolException("Type ["+type+"] unsupported");
  59.     }
  60.     public static AbstractConsoleItem<?> newBinaryConsoleItem(ConsoleItemType itemType, String id, String label, String fileName, String fileId) throws ProtocolException{
  61.         return new BinaryConsoleItem(id, label, itemType, fileName, fileId);
  62.     }
  63.     public static BinaryProperty newProperty(String id, byte[] value, String fileName, String fileId){
  64.         return new BinaryProperty(id, value, fileName, fileId);
  65.     }
  66.     public static NumberProperty newProperty(String id, Long value){
  67.         return new NumberProperty(id, value);
  68.     }
  69.     public static NumberProperty newProperty(String id, Integer value){
  70.         return new NumberProperty(id, (value != null ? value.longValue() : null));
  71.     }
  72.     public static BooleanProperty newProperty(String id, Boolean value){
  73.         return new BooleanProperty(id, value);
  74.     }
  75.     public static StringProperty newProperty(String id, String value){
  76.         return new StringProperty(id, value);
  77.     }
  78. }