1 18 package org.objectweb.medor.expression.lib; 19 20 import org.objectweb.medor.expression.api.Expression; 21 import org.objectweb.medor.expression.api.Operand; 22 import org.objectweb.medor.expression.api.ParameterOperand; 23 import org.objectweb.medor.expression.api.ExpressionException; 24 import org.objectweb.medor.expression.api.MalformedExpressionException; 25 import org.objectweb.medor.expression.api.TypingException; 26 import org.objectweb.jorm.type.api.PType; 27 import org.objectweb.jorm.type.api.PTypeSpace; 28 29 34 public class StringUpper extends BasicUnaryOperator { 35 36 public StringUpper() { 37 super(PTypeSpace.STRING); 38 } 39 public StringUpper(Expression strOperand) { 40 super(PTypeSpace.STRING, strOperand); 41 } 42 43 public String getOperatorString() { 44 return STRING_UPPER; 45 } 46 47 public Operand evaluate(ParameterOperand[] pos, Object o) 48 throws ExpressionException { 49 if (expressions[0] == null) { 50 throw new MalformedExpressionException("Null children value"); 51 } 52 if (result == null) { 53 throw new ExpressionException("Expression not compiled"); 54 } 55 result.setValue( 56 evaluate(getExpression(0).evaluate(pos, o).getString())); 57 return result; 58 } 59 60 public Operand compileExpression() 61 throws ExpressionException, MalformedExpressionException { 62 if (expressions[0] == null) { 63 throw new MalformedExpressionException("Null children value"); 64 } 65 expressions[0].compileExpression(); 66 PType opType = expressions[0].getType(); 67 if (opType == null) { 68 throw new TypingException("Argument type not defined (null)"); 69 } 70 if (opType.getTypeCode() != PType.TYPECODE_STRING) { 71 throw new TypingException("Bad Argument type, expected String, found: " 72 + expressions[0].getType().getJavaName()); 73 } 74 result = new BasicVariableOperand(type); 75 verified = true; 76 return result; 77 } 78 79 public String evaluate(String str) { 80 return (str == null ? null : str.toUpperCase()); 81 } 82 } 83 | Popular Tags |