1 package org.jicengine.element.impl; 2 3 import org.jicengine.element.*; 4 import org.jicengine.expression.FactoryInvocationParser; 5 import org.jicengine.operation.*; 6 7 18 public class FactoryElementCompiler extends ElementCompiler { 19 20 public FactoryElementCompiler(String name, Location location) throws ElementException 21 { 22 this(name, location, new String [0]); 23 } 24 25 26 public FactoryElementCompiler(String name, Location location, String [] parameters) throws ElementException 27 { 28 super(name, location); 29 30 String [] parameterNames = new String [parameters.length]; 31 Class [] parameterTypes = new Class [parameters.length]; 32 33 for (int i = 0; i < parameters.length; i++) { 34 try { 35 String paramDef = parameters[i].trim(); 36 int spaceIndex = paramDef.indexOf(" "); 37 parameterTypes[i] = org.jicengine.expression.ClassParser.toClass(paramDef.substring(0, spaceIndex)); 38 parameterNames[i] = paramDef.substring(spaceIndex + 1).trim(); 39 } catch (Exception e){ 40 throw new ElementException("Problems with parameter definition '" + parameters[i] + "'. Expected format '[class] [name]'", getName(), getLocation()); 41 } 42 } 43 getElement().setAction(new RegisterFactoryOperation(name,parameterNames,parameterTypes, FactoryInvocationParser.FACTORY_NAME_PREFIX + name)); 44 } 45 46 52 protected ActionElement handleLooseVariableElement(final VariableElement child) throws ElementException 53 { 54 if( ((RegisterFactoryOperation)getElement().getAction()).getFactoryElement() != null ){ 55 throw new ElementException("Illegal child " + child + ". Only single element is allowed inside element of type 'factory'.", getName(), getLocation()); 56 } 57 58 ((RegisterFactoryOperation)getElement().getAction()).setFactoryElement(child); 59 60 return new ActionElement(){ 62 public void execute(Context context, Object parentInstance) 63 { 64 } 65 public String getName() 66 { 67 return child.getName(); 68 } 69 public Location getLocation() 70 { 71 return child.getLocation(); 72 } 73 public boolean isExecuted(Context outerContext, Object parentInstance) 74 { 75 return false; 76 } 77 }; 78 79 } 80 81 82 93 } 94 | Popular Tags |