KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > element > impl > BeanElementCompiler


1 package org.jicengine.element.impl;
2
3 import org.jicengine.operation.OperationException;
4 import org.jicengine.operation.Context;
5 import org.jicengine.operation.Operation;
6 import org.jicengine.element.*;
7
8 /**
9  *
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 JavaDoc name, Location location)
23     {
24         super(name, location);
25     }
26
27     /**
28      * transforms the child into a property setter action..
29      */

30     protected ActionElement handleLooseVariableElement(final VariableElement child) throws ElementException
31     {
32         if( this.getElement().getConstructor() == null){
33             // the element has no constructor
34
// -> the element has no instance
35
// -> we can't set a property without a bean instance.
36
throw new ElementException("Unused child element: <" + child.getName() + ">", getName(), getLocation());
37         }
38         try {
39             Operation setPropertyAction = org.jicengine.expression.LJEParser.getInstance().parse(getSetPropertyActionExpression(child.getName()) );
40
41             return new WrapperActionElement(child, child.getLocation(), setPropertyAction);
42
43         } catch (org.jicengine.expression.SyntaxException e){
44             throw new ElementException(e,getName(), getLocation());
45         }
46     }
47
48     /**
49      * 'childElement' -> parent.setChildElement(this)
50      */

51     public static String JavaDoc getSetPropertyActionExpression(String JavaDoc propertyName)
52     {
53         return Element.VARIABLE_NAME_PARENT_INSTANCE + ".set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1) + "(" + Element.VARIABLE_NAME_ELEMENT_INSTANCE + ")";
54     }
55 }
56
Popular Tags