1 23 24 package org.objectweb.medor.expression.lib; 25 26 import org.objectweb.jorm.type.api.PType; 27 import org.objectweb.jorm.type.api.PTypeSpace; 28 import org.objectweb.medor.expression.api.BinaryOperator; 29 import org.objectweb.medor.expression.api.Expression; 30 import org.objectweb.medor.expression.api.ExpressionException; 31 import org.objectweb.medor.expression.api.MalformedExpressionException; 32 import org.objectweb.medor.expression.api.Operand; 33 import org.objectweb.medor.expression.api.Operator; 34 import org.objectweb.medor.expression.api.ParameterOperand; 35 import org.objectweb.medor.expression.api.TypingException; 36 37 public class Concat extends BasicBinaryOperator implements BinaryOperator { 38 39 44 public Concat(Expression e0, Expression e1) { 45 super(PTypeSpace.STRING, e0, e1); 46 } 47 48 public Concat() { 49 super(PTypeSpace.STRING); 50 } 51 52 public org.objectweb.medor.expression.api.Operand evaluate(ParameterOperand[] pos, Object o) 53 throws ExpressionException { 54 try { 55 result.setValue( 56 evaluate( 57 expressions[0].evaluate(pos, o).getString(), 58 expressions[1].evaluate(pos, o).getString())); 59 } 60 catch (NullPointerException e) { 61 throw new IllegalStateException ("Unevaluable Expression: Not compiled"); 63 } 64 return result; 65 } 66 67 public String evaluate(String op1, String op2) { 68 return op1.concat(op2); 69 } 70 71 public Operand compileExpression() 72 throws ExpressionException, MalformedExpressionException { 73 if ((expressions[0] != null) && (expressions[1] != null)) { 74 expressions[0].compileExpression(); 75 expressions[1].compileExpression(); 76 if (!(expressions[0].getType() == null || expressions[1].getType() == null)) { 77 if ((expressions[0].getType().getTypeCode() == PType.TYPECODE_STRING) && 78 (expressions[1].getType().getTypeCode() == PType.TYPECODE_STRING)) { 79 type = PTypeSpace.STRING; 80 result = new BasicVariableOperand(type); 81 verified = true; 82 } 83 else 84 throw new TypingException("Attempt arg type : String, String"); 86 } 87 else 88 throw new MalformedExpressionException("null children value"); 89 } 90 else 91 throw new MalformedExpressionException("null children value"); 93 return result; 94 } 95 96 public String getOperatorString() { 97 return Operator.CONCAT; 98 } 99 } 100 | Popular Tags |