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

  29.     protected String fieldName;
  30.     protected Class<?> fieldType;
  31.    
  32.     protected String className;
  33.     protected Class<?> classType;
  34.    
  35.     protected IField father;
  36.    
  37.     public ComplexField(IField father,
  38.             String fieldName,Class<?> fieldType,String className,Class<?> classType){
  39.        
  40.         this.fieldName = fieldName;
  41.         this.fieldType = fieldType;
  42.        
  43.         this.className = className;
  44.         this.classType = classType;
  45.        
  46.         this.father = father;
  47.     }

  48.     @Override
  49.     public String getFieldName() {
  50.         return this.fieldName;
  51.     }

  52.     @Override
  53.     public Class<?> getFieldType() {
  54.         return this.fieldType;
  55.     }

  56.     @Override
  57.     public String getClassName() {
  58.         return this.className;
  59.     }

  60.     @Override
  61.     public Class<?> getClassType() {
  62.         return this.classType;
  63.     }

  64.     public IField getFather() {
  65.         return this.father;
  66.     }
  67.    
  68.     @Override
  69.     public boolean equals(Object o){
  70.         if(o==null){
  71.             return false;
  72.         }
  73.         if(! (o instanceof ComplexField) ){
  74.             if(o instanceof IField)
  75.                 return false;
  76.             else
  77.                 throw new RuntimeException("Expected type ["+ComplexField.class.getName()+"] different from the type found ["+o.getClass().getName()+"]");
  78.         }
  79.         ComplexField f = (ComplexField) o;
  80.        
  81.         String thisClassTypeName = this.getClassType().getName() + "";
  82.         String fClassTypeName = f.getClassType().getName() + "";
  83.        
  84.         String thisFieldTypeName = this.getFieldType().getName() + "";
  85.         String fFieldTypeName = f.getFieldType().getName() + "";
  86.        
  87.         return this.getClassName().equals(f.getClassName()) &&
  88.                 thisClassTypeName.equals(fClassTypeName) &&
  89.             this.getFieldName().equals(f.getFieldName()) &&
  90.             thisFieldTypeName.equals(fFieldTypeName) &&
  91.             this.father.equals(f.getFather());
  92.     }
  93.    
  94.     @Override
  95.     public int hashCode() {
  96.         return super.hashCode();
  97.     }
  98.    
  99.     @Override
  100.     public String toString(){
  101.         return toString(0);
  102.     }
  103.     @Override
  104.     public String toString(int indent){
  105.        
  106.         StringBuilder indentBuffer = new StringBuilder();
  107.         for (int i = 0; i < indent; i++) {
  108.             indentBuffer.append("   ");
  109.         }
  110.        
  111.         StringBuilder bf = new StringBuilder();
  112.        
  113.         bf.append(indentBuffer.toString());
  114.         bf.append("- field name: "+this.fieldName);
  115.         bf.append("\n");
  116.         bf.append(indentBuffer.toString());
  117.         bf.append("- field type: "+this.fieldType);
  118.         bf.append("\n");
  119.         bf.append(indentBuffer.toString());
  120.         bf.append("- class name: "+this.className);
  121.         bf.append("\n");
  122.         bf.append(indentBuffer.toString());
  123.         bf.append("- class type: "+this.classType);
  124.         bf.append("\n");
  125.        
  126.         bf.append(indentBuffer.toString());
  127.         bf.append("- father: ");
  128.         bf.append("\n");
  129.         if(this.father instanceof ComplexField){
  130.             bf.append( ((ComplexField)this.father).toString(++indent) );
  131.         }else if(this.father instanceof Field){
  132.             bf.append( ((Field)this.father).toString(++indent) );
  133.         }else{
  134.             throw new RuntimeException("Type ["+this.father.getClass().getName()+"] not supported");
  135.         }
  136.        
  137.         return bf.toString();
  138.     }
  139.    
  140. }