01: package org.jicengine.expression;
02:
03: import org.jicengine.operation.FieldValueOperation;
04:
05: import org.jicengine.operation.Operation;
06:
07: /**
08: *
09: * <p>
10: * Copyright (C) 2004 Timo Laitinen
11: * </p>
12: * @author .timo
13: */
14:
15: public class FieldValueParser implements Parser {
16:
17: Parser elementParser;
18:
19: public FieldValueParser(Parser elementParser) {
20: this .elementParser = elementParser;
21: }
22:
23: public Operation parse(String expression) throws SyntaxException {
24: char[] chars = expression.toCharArray();
25: int fieldNameSeparatorIndex = -1;
26: for (int i = chars.length - 1; 0 <= i; i--) {
27: if (chars[i] == METHOD_PARAMS_END
28: || chars[i] == METHOD_PARAMS_START
29: || chars[i] == ARRAY_LENGTH_START
30: || chars[i] == ARRAY_LENGTH_END) {
31: // the existence of method-param-brackets signals that this isn't
32: // a field-value-expression.
33: break;
34: } else if (chars[i] == OPERATION_SEPARATOR) {
35: // we found the field-name
36: fieldNameSeparatorIndex = i;
37: break;
38: } else {
39: continue;
40: }
41: }
42:
43: if (fieldNameSeparatorIndex != -1) {
44: // extract the actor-part (= a name of a variable or a class ).
45: String actorName = expression.substring(0,
46: fieldNameSeparatorIndex);
47: String fieldName = expression
48: .substring(fieldNameSeparatorIndex + 1);
49:
50: Operation actor = elementParser.parse(actorName);
51:
52: return new FieldValueOperation(expression, actor, fieldName);
53: } else {
54: // no field name found, I guess the
55: // expression wasn't a field-value expression.
56: return null;
57: }
58: }
59: }
|