1 30 package com.genimen.djeneric.tools.scriptengine.core.nodes; 31 32 import com.genimen.djeneric.language.Messages; 33 import com.genimen.djeneric.repository.DjExtent; 34 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException; 35 import com.genimen.djeneric.tools.scriptengine.core.DjScriptParserEngine; 36 import com.genimen.djeneric.tools.scriptengine.core.SimpleNode; 37 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptCompileTimeScope; 38 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptExecutionException; 39 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptExecutionTimeScope; 40 41 public class AssignmentStatementNode extends SimpleNode 42 { 43 44 public AssignmentStatementNode(int i) 45 { 46 super(i); 47 } 48 49 public AssignmentStatementNode(DjScriptParserEngine p, int i) 50 { 51 super(p, i); 52 } 53 54 public String getName() 55 { 56 return "assignment"; 57 } 58 59 public String toString() 60 { 61 return getName(); 62 } 63 64 public void execute(DjScriptExecutionTimeScope context) throws DjScriptExecutionException 65 { 66 PropertyPathNode propNode = (PropertyPathNode) getChild(PropertyPathNode.class); 67 ValueExpression valueExpr = (ValueExpression) getChild(1); 68 69 context.setPropertyValue(propNode.getPath(), valueExpr.getValue(context), this); 70 } 71 72 public String getValidatedTypeName(DjScriptCompileTimeScope context) throws DjScriptExecutionException 73 { 74 PropertyPathNode propNode = (PropertyPathNode) getChild(PropertyPathNode.class); 75 ValueExpression valueExpr = (ValueExpression) getChild(1); 76 77 String leftType = propNode.getValidatedTypeName(context); 78 String rightType = valueExpr.getValidatedTypeName(context); 79 80 DjExtent le = null; 81 DjExtent re = null; 82 83 try 84 { 85 le = context.getPersistenceManager().getExtentByObjectType(leftType); 86 } 87 catch (ObjectNotDefinedException onde) 88 { 89 } 91 92 try 93 { 94 re = context.getPersistenceManager().getExtentByObjectType(rightType); 95 } 96 catch (ObjectNotDefinedException onde) 97 { 98 } 100 101 if (le != null && re != null) 102 { 103 if (!re.isInstanceof(le) && !le.isInstanceof(re)) throw new DjScriptExecutionException(Messages 105 .getString("Variable.CannotAssign", re.getObjectType(), le.getObjectType()), this); 106 return re.getQualifiedObjectType(); 107 } 108 109 if (le != null && PropertyOrFunctionNode.FUNCTION_DETERMINED.equals(rightType)) 112 { 113 return leftType; 114 } 115 116 if (le != null || re != null) 117 { 118 throw new DjScriptExecutionException(Messages.getString("Variable.CannotAssign", rightType, leftType), this); 119 } 120 return rightType; 121 } 122 123 public void validateScript(DjScriptCompileTimeScope ctxt) throws DjScriptExecutionException 124 { 125 getValidatedTypeName(ctxt); 126 } 127 128 } | Popular Tags |