1 package org.jicengine.operation; 2 3 13 14 public class PushVariableOperation implements Operation { 15 16 String localContextName; 17 String parentContextName; 18 19 public PushVariableOperation(String localContextName, String parentContextName) 20 { 21 this.parentContextName = parentContextName; 22 this.localContextName = localContextName; 23 } 24 25 public boolean needsParameters() 26 { 27 return true; 28 } 29 30 public boolean needsParameter(String name) 31 { 32 return (this.localContextName.equals(name)); 33 } 34 35 public Object execute(Context context) throws OperationException 36 { 37 Context parentContext; 38 try { 39 parentContext = ((LocalContext)context).getParent(); 40 } catch (ClassCastException e){ 41 throw new RuntimeException ("Expected " + LocalContext.class.getName() + ", was " + context.getClass().getName()); 42 } 43 44 try { 45 Object value = context.getObject(this.localContextName); 46 47 parentContext.addObject(this.parentContextName, value); 48 return null; 49 } catch (ObjectNotFoundException e){ 50 throw new OperationException(e.getMessage(), e); 51 } catch (DuplicateNameException e2){ 52 throw new OperationException(e2.getMessage(), e2); 53 } 54 } 55 } 56 | Popular Tags |