ConstantField.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.generic_project.beans;

  21. import org.openspcoop2.generic_project.exception.ExpressionException;
  22. import org.openspcoop2.generic_project.expression.impl.formatter.BooleanTypeFormatter;
  23. import org.openspcoop2.generic_project.expression.impl.formatter.ByteTypeFormatter;
  24. import org.openspcoop2.generic_project.expression.impl.formatter.CalendarTypeFormatter;
  25. import org.openspcoop2.generic_project.expression.impl.formatter.CharacterTypeFormatter;
  26. import org.openspcoop2.generic_project.expression.impl.formatter.DateTypeFormatter;
  27. import org.openspcoop2.generic_project.expression.impl.formatter.DoubleTypeFormatter;
  28. import org.openspcoop2.generic_project.expression.impl.formatter.FloatTypeFormatter;
  29. import org.openspcoop2.generic_project.expression.impl.formatter.IntegerTypeFormatter;
  30. import org.openspcoop2.generic_project.expression.impl.formatter.LongTypeFormatter;
  31. import org.openspcoop2.generic_project.expression.impl.formatter.NullTypeFormatter;
  32. import org.openspcoop2.generic_project.expression.impl.formatter.ObjectFormatter;
  33. import org.openspcoop2.generic_project.expression.impl.formatter.ShortTypeFormatter;
  34. import org.openspcoop2.generic_project.expression.impl.formatter.StringTypeFormatter;
  35. import org.openspcoop2.generic_project.expression.impl.formatter.TimestampTypeFormatter;
  36. import org.openspcoop2.generic_project.expression.impl.formatter.URITypeFormatter;
  37. import org.openspcoop2.utils.TipiDatabase;

  38. /**
  39.  * ConstantField
  40.  *
  41.  * @author Poli Andrea (apoli@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class ConstantField extends Field {

  46.     private Object fieldValue;
  47.     private ObjectFormatter objectFormatter= null;
  48.    
  49.     public ConstantField(String fieldName, Object fieldValue, Class<?> fieldType) throws ExpressionException{
  50.         super(fieldName, fieldType, ConstantField.class.getSimpleName(), ConstantField.class);
  51.        
  52.         this.fieldValue = fieldValue;
  53.        
  54.         // Creo un formatte con alcuni tipi tra quelli supportati complessivamente
  55.         this.objectFormatter = new ObjectFormatter(new BooleanTypeFormatter(),
  56.                 new CalendarTypeFormatter(), new DateTypeFormatter(), new TimestampTypeFormatter(),
  57.                 new CharacterTypeFormatter(), new StringTypeFormatter(),
  58.                 new ByteTypeFormatter(), new ShortTypeFormatter(),
  59.                 new IntegerTypeFormatter(), new LongTypeFormatter(),
  60.                 new DoubleTypeFormatter(), new FloatTypeFormatter(),
  61.                 new URITypeFormatter(), new NullTypeFormatter());
  62.        
  63.         this.objectFormatter.isSupported(this.fieldValue);
  64.            
  65.     }

  66.     public String getConstantValue(TipiDatabase databaseType) throws ExpressionException {
  67.        
  68.         return this.objectFormatter.toSQLString(this.fieldValue, databaseType);
  69.        
  70.     }
  71.     public String getAlias() {
  72.         return this.getFieldName();
  73.     }
  74.    

  75.     @Override
  76.     public String toString(int indent){
  77.        
  78.         StringBuilder indentBuffer = new StringBuilder();
  79.         for (int i = 0; i < indent; i++) {
  80.             indentBuffer.append("   ");
  81.         }
  82.        
  83.         StringBuilder bf = new StringBuilder(super.toString(indent));
  84.        
  85.         bf.append(indentBuffer.toString());
  86.         bf.append("- fieldValue: "+this.fieldValue);
  87.         bf.append("\n");
  88.                
  89.         return bf.toString();
  90.     }

  91. }