AliasField.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. /**
  23.  * CustomField
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class AliasField extends ComplexField {

  30.     private IField field;
  31.     private String alias;
  32.    
  33.     public AliasField(IField field,String alias) throws ExpressionException{
  34.         super(new ConstantField("AliasSimpleField", "AliasSimpleField", String.class),
  35.                 field.getFieldName(), field.getFieldType(), field.getClassName(), field.getClassType());
  36.        
  37.         if(field instanceof ComplexField){
  38.             ComplexField cf = (ComplexField) field;
  39.             super.father = cf.father;
  40.         }

  41.         this.field = field;
  42.         this.alias = alias;
  43.     }
  44.    
  45.     @Override
  46.     public Class<?> getFieldType() {
  47.         return this.field.getFieldType();
  48.     }
  49.     @Override
  50.     public Class<?> getClassType() {
  51.         return this.field.getClassType();
  52.     }
  53.     @Override
  54.     public String getFieldName() {
  55.         return this.field.getFieldName();
  56.     }
  57.     @Override
  58.     public String getClassName() {
  59.         return this.field.getClassName();
  60.     }
  61.    
  62.     public String getAlias() {
  63.         return this.alias;
  64.     }
  65.     public IField getField() {
  66.         return this.field;
  67.     }
  68.    
  69.     // Ridefinisco l'equals, altrimenti nei Converter, gli if che precendono la chiamata al metodo AbstractSQLFieldConverter.toColumn
  70.     // vengono soddisfatti, e quindi non viene usato l'alias
  71.     @Override
  72.     public boolean equals(Object o){
  73.         boolean superEquals = super.equals(o);
  74.         if(superEquals){
  75.             if(o instanceof AliasField){
  76.                 AliasField af = (AliasField) o;
  77.                 return af.getAlias().equals(this.alias);
  78.             }
  79.             else{
  80.                 return false;
  81.             }
  82.         }
  83.         else{
  84.             return false;
  85.         }
  86.     }
  87.    
  88.     @Override
  89.     public int hashCode() {
  90.         return super.hashCode();
  91.     }
  92.    
  93.     @Override
  94.     public String toString(){
  95.         return toString(0);
  96.     }
  97.     @Override
  98.     public String toString(int indent){
  99.        
  100.         StringBuilder indentBuffer = new StringBuilder();
  101.         for (int i = 0; i < indent; i++) {
  102.             indentBuffer.append("   ");
  103.         }
  104.        
  105.         StringBuilder bf = new StringBuilder(this.field.toString(indent));
  106.        
  107.         bf.append(indentBuffer.toString());
  108.         bf.append("- alias: "+this.alias);
  109.         bf.append("\n");
  110.                
  111.         return bf.toString();
  112.     }
  113. }