1 package org.jicengine.element.impl; 2 3 import org.jicengine.expression.SyntaxException; 4 import org.jicengine.operation.Operation; 5 import org.jicengine.operation.Context; 6 import org.jicengine.operation.OperationException; 7 import org.jicengine.element.*; 8 9 import java.util.Collection ; 10 import java.util.Map ; 11 12 19 20 public class MapCompiler extends ElementCompiler { 21 22 public MapCompiler(String name, Location location) 23 { 24 super(name, location); 25 } 26 27 public void setInstanceClass(String className) throws ElementException 28 { 29 super.setInstanceClass(className); 30 31 if( !Map .class.isAssignableFrom(getElement().getInstanceClass())){ 32 throw new ElementException("Class '" + getElement().getInstanceClass().getName() + "' is not a Map.",getElement().getName(), getLocation()); 33 } 34 } 35 36 protected ActionElement handleLooseVariableElement(VariableElement child) throws org.jicengine.element.ElementException 37 { 38 final String childName = child.getName(); 39 40 Operation putToMapOperation = new Operation(){ 44 public boolean needsParameter(String name) 45 { 46 return (name.equals(Element.VARIABLE_NAME_PARENT_INSTANCE) || name.equals(Element.VARIABLE_NAME_ELEMENT_INSTANCE) ); 47 } 48 public boolean needsParameters() 49 { 50 return true; 51 } 52 53 public Object execute(Context context) throws OperationException 54 { 55 Map parent = (Map ) org.jicengine.operation.VariableValueOperation.lookup(Element.VARIABLE_NAME_PARENT_INSTANCE, context); 56 Object elementInstance = org.jicengine.operation.VariableValueOperation.lookup(Element.VARIABLE_NAME_ELEMENT_INSTANCE, context); 57 return parent.put(childName, elementInstance); 58 } 59 60 }; 61 62 return new WrapperActionElement(child,child.getLocation(),putToMapOperation); 63 } 64 } 65 | Popular Tags |