1 package org.jicengine.element.impl; 2 3 import org.jicengine.element.VariableElement; 4 import org.jicengine.operation.Context; 5 import org.jicengine.operation.DuplicateNameException; 6 import org.jicengine.operation.Factory; 7 import org.jicengine.operation.LocalContext; 8 import org.jicengine.operation.Operation; 9 import org.jicengine.operation.OperationException; 10 11 19 public class RegisterFactoryOperation implements Operation { 20 private String factoryName; 21 private String [] parameterNames; 22 private Class [] parameterTypes; 23 private VariableElement factoryElement; 24 25 private String contextVariableName; 26 27 public RegisterFactoryOperation(String factoryName, String [] parameterNames, Class [] parameterTypes, String contextVariableName) 28 { 29 this.factoryName = factoryName; 30 this.parameterNames = parameterNames; 31 this.parameterTypes = parameterTypes; 32 this.contextVariableName = contextVariableName; 33 } 34 35 public void setFactoryElement(VariableElement factoryElement) 36 { 37 this.factoryElement = factoryElement; 38 } 39 40 public VariableElement getFactoryElement() 41 { 42 return this.factoryElement; 43 } 44 45 public boolean needsParameters() 46 { 47 return false; 48 } 49 public boolean needsParameter(String name) 50 { 51 return false; 52 } 53 54 public Object execute(Context context) throws OperationException 55 { 56 58 Context elementContext = ((LocalContext)context).getParent(); 61 62 Context executionContext = elementContext.replicate(); 66 67 Context parentElementContext = ((LocalContext)elementContext).getParent(); 69 70 71 Factory factory = new ElementExecutionFactory(this.factoryName, this.parameterNames, this.parameterTypes, getFactoryElement(), executionContext); 72 73 try { 75 parentElementContext.addObject(this.contextVariableName, factory); 76 } catch (DuplicateNameException e){ 77 throw new OperationException("Duplicate factory definition: '" + this.factoryName + "' ('" + this.contextVariableName + "')"); 78 } 79 80 return null; 81 } 82 } | Popular Tags |