1 43 44 package org.exolab.jms.selector; 45 46 import java.util.HashSet ; 47 48 import org.exolab.jms.selector.parser.SelectorTokenTypes; 49 50 51 59 public final class DefaultExpressionFactory implements ExpressionFactory { 60 61 70 public Expression binaryOperator(final int operator, final Expression left, 71 final Expression right) 72 throws SelectorException { 73 74 Expression result = null; 75 switch (operator) { 76 case SelectorTokenTypes.LITERAL_and: 77 result = new And(left, right); 78 break; 79 case SelectorTokenTypes.LITERAL_or: 80 result = new Or(left, right); 81 break; 82 case SelectorTokenTypes.EQUAL: 83 result = new Equal(left, right); 84 break; 85 case SelectorTokenTypes.NOT_EQUAL: 86 result = new NotEqual(left, right); 87 break; 88 case SelectorTokenTypes.LT: 89 result = new Less(left, right); 90 break; 91 case SelectorTokenTypes.GT: 92 result = new Greater(left, right); 93 break; 94 case SelectorTokenTypes.LE: 95 result = new LessEqual(left, right); 96 break; 97 case SelectorTokenTypes.GE: 98 result = new GreaterEqual(left, right); 99 break; 100 case SelectorTokenTypes.PLUS: 101 result = new Add(left, right); 102 break; 103 case SelectorTokenTypes.MINUS: 104 result = new Subtract(left, right); 105 break; 106 case SelectorTokenTypes.MULTIPLY: 107 result = new Multiply(left, right); 108 break; 109 case SelectorTokenTypes.DIVIDE: 110 result = new Divide(left, right); 111 break; 112 default: 113 throw new SelectorException("Unknown binary operator type: " 114 + operator); 115 } 116 return result; 117 } 118 119 127 public Expression unaryOperator(final int operator, 128 final Expression operand) 129 throws SelectorException { 130 Expression result = null; 131 switch (operator) { 132 case SelectorTokenTypes.LITERAL_not: 133 result = new Not(operand); 134 break; 135 case SelectorTokenTypes.UNARY_MINUS: 136 result = new UnaryMinus(operand); 137 break; 138 default: 139 throw new SelectorException("Unknown unary operator type: " 140 + operator); 141 } 142 return result; 143 } 144 145 152 public Expression identifier(final String name) throws SelectorException { 153 return new Identifier(name); 154 } 155 156 163 public Expression isNull(final Expression identifier) 164 throws SelectorException { 165 return new IsExpression((Identifier) identifier); 166 } 167 168 177 public Expression like(final Expression identifier, final String pattern, 178 final String escape) throws SelectorException { 179 return new LikeExpression((Identifier) identifier, pattern, escape); 180 } 181 182 193 public Expression between(final Expression num1, final Expression num2, 194 final Expression num3) throws SelectorException { 195 return new BetweenExpression(num1, num2, num3); 196 } 197 198 206 public Expression in(final Expression identifier, final HashSet set) 207 throws SelectorException { 208 return new InExpression((Identifier) identifier, set); 209 } 210 211 219 public Expression literal(final int type, final String text) 220 throws SelectorException { 221 Expression result = null; 222 switch (type) { 223 case SelectorTokenTypes.NUM_FLOAT: 224 result = Literal.approxNumericLiteral(text); 225 break; 226 case SelectorTokenTypes.NUM_INT: 227 result = Literal.exactNumericLiteral(text); 228 break; 229 case SelectorTokenTypes.STRING_LITERAL: 230 result = Literal.stringLiteral(text); 231 break; 232 case SelectorTokenTypes.LITERAL_true: 233 result = Literal.booleanLiteral(true); 234 break; 235 case SelectorTokenTypes.LITERAL_false: 236 result = Literal.booleanLiteral(false); 237 break; 238 default: 239 throw new SelectorException("Unknown literal type: " + type); 240 } 241 242 return result; 243 } 244 245 } | Popular Tags |