AbstractCommonFieldBaseExpressionImpl.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.expression.impl;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.generic_project.beans.ComplexField;
  24. import org.openspcoop2.generic_project.beans.IField;
  25. import org.openspcoop2.generic_project.beans.IModel;
  26. import org.openspcoop2.generic_project.exception.ExpressionException;
  27. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  28. import org.openspcoop2.generic_project.expression.impl.formatter.IObjectFormatter;

  29. /**
  30.  * AbstractCommonFieldBaseExpressionImpl
  31.  *
  32.  * @author Poli Andrea (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public abstract class AbstractCommonFieldBaseExpressionImpl extends AbstractBaseExpressionImpl {

  37.    
  38.     protected IField field;
  39.    
  40.     protected AbstractCommonFieldBaseExpressionImpl(IObjectFormatter objectFormatter,IField field){
  41.         super(objectFormatter);
  42.         this.field = field;
  43.     }
  44.    
  45.     public IField getField() {
  46.         return this.field;
  47.     }
  48.     public void setField(IField field) {
  49.         this.field = field;
  50.     }
  51.    
  52.    
  53.     @Override
  54.     public boolean inUseField(IField field)
  55.             throws ExpressionNotImplementedException, ExpressionException {
  56.         if(this.field==null){
  57.             return false;
  58.         }
  59.         return this.field.equals(field);
  60.     }
  61.    
  62.     @Override
  63.     public boolean inUseModel(IModel<?> model)
  64.             throws ExpressionNotImplementedException, ExpressionException {
  65.         if(this.field==null){
  66.             return false;
  67.         }
  68.         if(model.getBaseField()!=null){
  69.             // Modello di un elemento non radice
  70.             if(this.field instanceof ComplexField){
  71.                 ComplexField c = (ComplexField) this.field;
  72.                 return c.getFather().equals(model.getBaseField());
  73.             }else{
  74.                 String modeClassName = model.getModeledClass().getName() + "";
  75.                 return modeClassName.equals(this.field.getClassType().getName());
  76.             }
  77.         }
  78.         else{
  79.             String modeClassName = model.getModeledClass().getName() + "";
  80.             return modeClassName.equals(this.field.getClassType().getName());
  81.         }
  82.     }

  83.     @Override
  84.     public List<IField> getFields()
  85.             throws ExpressionNotImplementedException, ExpressionException {
  86.         List<IField> lista = null;
  87.         if(this.field==null){
  88.             return lista;
  89.         }
  90.         lista = new ArrayList<>();
  91.         lista.add(this.field);
  92.         return lista;
  93.     }
  94. }