InExpressionImpl.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.List;

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

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

  35.     private List<Object> objects;
  36.    
  37.     public InExpressionImpl(IObjectFormatter objectFormatter,IField field,List<Object> objects){
  38.         super(objectFormatter, field);
  39.         this.objects = objects;
  40.     }
  41.    
  42.     public List<Object> getObjects() {
  43.         return this.objects;
  44.     }

  45.     public void setObjects(List<Object> objects) {
  46.         this.objects = objects;
  47.     }

  48.     @Override
  49.     public String toString(){
  50.         StringBuilder bf = new StringBuilder();
  51.         if(isNot()){
  52.             bf.append("( NOT ");
  53.         }
  54.         bf.append("( ");
  55.         if(this.field instanceof ComplexField){
  56.             ComplexField cf = (ComplexField) this.field;
  57.             if(cf.getFather()!=null){
  58.                 bf.append(cf.getFather().getFieldName());
  59.             }else{
  60.                 bf.append(this.field.getClassName());
  61.             }
  62.         }else{
  63.             bf.append(this.field.getClassName());
  64.         }
  65.         bf.append(".");
  66.         bf.append(this.field.getFieldName());
  67.         bf.append(" IN (");
  68.         for (int i = 0; i < this.objects.size(); i++) {
  69.             bf.append(" ");
  70.             if(i>0){
  71.                 bf.append(", ");
  72.             }
  73.             try{
  74.                 bf.append(super.getObjectFormatter().toString(this.objects.get(i)));
  75.             }catch(Exception e){
  76.                 return "ERROR["+i+"]: "+e.getMessage();
  77.             }
  78.         }
  79.         bf.append(" )"); // in
  80.         bf.append(" )");
  81.         if(isNot()){
  82.             bf.append(" )");
  83.         }
  84.         return bf.toString();
  85.     }
  86.    


  87.     @Override
  88.     public List<Object> getFieldValues(IField field) throws ExpressionNotImplementedException, ExpressionException{
  89.         List<Object> l = null;
  90.         if(this.field==null){
  91.             return l;
  92.         }
  93.         if(this.field.equals(field)){
  94.             return this.objects;
  95.         }
  96.         return l;
  97.     }


  98. }