1:
31: package ;
32:
33: import ;
34:
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46:
47:
52: public abstract class AbstractExpressionReadHandler
53: extends AbstractXmlReadHandler
54: {
55: private Expression expression;
56: private BeanUtility expressionBeanUtility;
57: private CharacterEntityParser characterEntityParser;
58:
59: public AbstractExpressionReadHandler()
60: {
61: this.characterEntityParser = CharacterEntityParser.createXMLEntityParser();
62: }
63:
64: protected String getDefaultClassName()
65: {
66: return null;
67: }
68:
69:
75: protected void startParsing(final Attributes attrs) throws SAXException
76: {
77: final String name = attrs.getValue(getUri(), "name");
78: String className = attrs.getValue(getUri(), "class");
79: final String formula = attrs.getValue(getUri(), "formula");
80: if (className == null)
81: {
82: if (formula != null)
83: {
84: final String initial = attrs.getValue(getUri(), "initial");
85: if (initial != null)
86: {
87: final FormulaFunction function = new FormulaFunction();
88: function.setInitial(initial);
89: function.setFormula(formula);
90: this.expression = function;
91: }
92: else
93: {
94: final FormulaExpression expression = new FormulaExpression();
95: expression.setFormula(formula);
96: this.expression = expression;
97: }
98: }
99: else
100: {
101: className = getDefaultClassName();
102: if (className == null)
103: {
104: throw new ParseException("Required attribute 'class' is missing.",
105: getRootHandler().getDocumentLocator());
106: }
107: }
108: }
109:
110: if (expression == null)
111: {
112: expression = (Expression) ObjectUtilities.loadAndInstantiate
113: (className, AbstractExpressionReadHandler.class, Expression.class);
114: if (expression == null)
115: {
116: throw new ParseException("Expression '" + className +
117: "' is not valid. The specified class is not an expression or function.",
118: getRootHandler().getDocumentLocator());
119: }
120: }
121:
122: expression.setName(name);
123: expression.setDeepTraversing("true".equals(attrs.getValue(getUri(), "deep-traversing")));
124: expression.setPrecompute("true".equals(attrs.getValue(getUri(), "precompute")));
125: expression.setPreserve("true".equals(attrs.getValue(getUri(), "preserve")));
126:
127: try
128: {
129: expressionBeanUtility = new BeanUtility(expression);
130: }
131: catch (ClassCastException e)
132: {
133: throw new ParseException("Expression '" + className +
134: "' is not valid. The specified class is not an expression or function.",
135: e, getRootHandler().getDocumentLocator());
136: }
137: catch (IntrospectionException e)
138: {
139: throw new ParseException("Expression '" + className +
140: "' is not valid. Introspection failed for this expression.",
141: e, getRootHandler().getDocumentLocator());
142: }
143:
144: }
145:
146:
154: protected XmlReadHandler getHandlerForChild(final String uri,
155: final String tagName,
156: final Attributes atts)
157: throws SAXException
158: {
159: if (isSameNamespace(uri) == false)
160: {
161: return null;
162: }
163: if ("property".equals(tagName))
164: {
165: return new TypedPropertyReadHandler
166: (expressionBeanUtility, expression.getName(),
167: characterEntityParser);
168: }
169: return null;
170: }
171:
172: public Expression getExpression()
173: {
174: return expression;
175: }
176:
177:
184: public Object getObject() throws SAXException
185: {
186: return expression;
187: }
188: }