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