01: package org.jicengine.element.impl;
02:
03: import org.jicengine.operation.OperationException;
04: import org.jicengine.operation.Context;
05: import org.jicengine.operation.Operation;
06: import org.jicengine.element.*;
07:
08: /**
09: *
10: *
11: * <p>
12: * Copyright (C) 2004 Timo Laitinen
13: * </p>
14: * @author Timo Laitinen
15: * @created 2004-09-20
16: * @since JICE-0.10
17: *
18: */
19:
20: public class BeanElementCompiler extends ElementCompiler {
21:
22: public BeanElementCompiler(String name, Location location) {
23: super (name, location);
24: }
25:
26: /**
27: * transforms the child into a property setter action..
28: */
29: protected ActionElement handleLooseVariableElement(
30: final VariableElement child) throws ElementException {
31: if (this .getElement().getConstructor() == null) {
32: // the element has no constructor
33: // -> the element has no instance
34: // -> we can't set a property without a bean instance.
35: throw new ElementException("Unused child element: <"
36: + child.getName() + ">", getName(), getLocation());
37: }
38: try {
39: Operation setPropertyAction = org.jicengine.expression.LJEParser
40: .getInstance().parse(
41: getSetPropertyActionExpression(child
42: .getName()));
43:
44: return new WrapperActionElement(child, child.getLocation(),
45: setPropertyAction);
46:
47: } catch (org.jicengine.expression.SyntaxException e) {
48: throw new ElementException(e, getName(), getLocation());
49: }
50: }
51:
52: /**
53: * 'childElement' -> parent.setChildElement(this)
54: */
55: public static String getSetPropertyActionExpression(
56: String propertyName) {
57: return Element.VARIABLE_NAME_PARENT_INSTANCE + ".set"
58: + Character.toUpperCase(propertyName.charAt(0))
59: + propertyName.substring(1) + "("
60: + Element.VARIABLE_NAME_ELEMENT_INSTANCE + ")";
61: }
62: }
|