1 package org.jicengine.element; 2 3 import org.jicengine.operation.SimpleContext; 4 import org.jicengine.operation.OperationException; 5 import org.jicengine.operation.LocalContext; 6 import org.jicengine.operation.Context; 7 import org.jicengine.operation.Operation; 8 import org.jicengine.expression.*; 9 import java.util.List ; 10 import java.util.ArrayList ; 11 12 34 35 public class WrapperActionElement extends AbstractElement implements ActionElement { 36 37 private Operation action; 38 private VariableElement variableElement; 39 40 public WrapperActionElement(VariableElement variableElement, Location location, Operation action) 41 { 42 super(variableElement.getName(), location); 43 this.action = action; 44 this.variableElement = variableElement; 45 } 46 47 public boolean isExecuted(Context outerContext, Object parentInstance) throws ElementException 48 { 49 return this.variableElement.isExecuted(outerContext,parentInstance); 50 } 51 52 public void execute(Context globalContext, Object parentInstance) throws ElementException 53 { 54 Context actionParameterContext = new SimpleContext(); 56 57 if( parentInstance != null ){ 58 actionParameterContext.addObject(VARIABLE_NAME_PARENT_INSTANCE, parentInstance); 59 } 60 61 Object instance = this.variableElement.getValue(globalContext, parentInstance); 63 64 if( this.action.needsParameter(Element.VARIABLE_NAME_ELEMENT_INSTANCE) ){ 66 actionParameterContext.addObject(Element.VARIABLE_NAME_ELEMENT_INSTANCE, instance); 67 } 68 69 71 72 Context actionContext = new LocalContext( 74 actionParameterContext, 75 globalContext); 76 77 try { 78 this.action.execute(actionContext); 79 } catch (OperationException e){ 80 throw new ElementException("Failed to execute action " + this.action, e, getName(), getLocation()); 82 } 83 } 84 } 85
| Popular Tags
|