1 23 package org.objectweb.medor.expression.lib; 24 25 import org.objectweb.jorm.type.api.PType; 26 import org.objectweb.jorm.type.api.PTypeSpace; 27 import org.objectweb.medor.expression.api.CalculatedParameterOperand; 28 import org.objectweb.medor.expression.api.ExpressionException; 29 import org.objectweb.medor.expression.api.ParameterOperand; 30 31 38 public class StringComparatorParameterOperand 39 extends BasicParameterOperand 40 implements CalculatedParameterOperand { 41 42 String prefix; 43 String suffix; 44 45 public StringComparatorParameterOperand(BasicParameterOperand po, String prefix, String suffix) { 46 super(po); 47 this.prefix = prefix; 48 this.suffix = suffix; 49 } 50 51 public StringComparatorParameterOperand(String name, String prefix, String suffix) { 52 super(PTypeSpace.STRING, name); 53 this.prefix = prefix; 54 this.suffix = suffix; 55 } 56 57 58 61 public void evaluate(ParameterOperand[] pos) throws ExpressionException { 62 String res = null; 63 for (int i = 0; i < pos.length; i++) { 64 if (pos[i] != null 65 && name.equals(pos[i].getName()) 66 && pos[i].getType().getTypeCode() == PType.TYPECODE_STRING) { 67 res = pos[i].getString(); 68 } 69 } 70 if (res == null) { 71 throw new ExpressionException("Impossible to evaluate this parameter wihtout the parameter " + name); 72 } 73 if (suffix != null) { 74 res += suffix; 75 } 76 if (prefix != null) { 77 res = prefix + res; 78 } 79 this.setValue(res); 80 } 81 } 82 | Popular Tags |