Index: C:/Naidu/Projects/eclipse/june_policy_workspace/apache/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/AnchorMethodInvokeAction.java =================================================================== --- C:/Naidu/Projects/eclipse/june_policy_workspace/apache/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/AnchorMethodInvokeAction.java (revision 669804) +++ C:/Naidu/Projects/eclipse/june_policy_workspace/apache/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/AnchorMethodInvokeAction.java (working copy) @@ -32,6 +32,8 @@ import org.apache.imperius.spl.external.Actuator; import org.apache.imperius.spl.external.Argument; import org.apache.imperius.spl.external.Expression; +import org.apache.imperius.spl.external.TypeConstants; +import org.apache.imperius.spl.parser.compiler.IdentPrimaryTuple; import org.apache.imperius.spl.parser.compiler.symboltable.MethodSymbol; import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable; import org.apache.imperius.spl.parser.exceptions.SPLException; @@ -40,148 +42,271 @@ import org.apache.imperius.spl.parser.statements.BasicActionBlock; import org.apache.imperius.spl.parser.statements.impl.ArgumentImpl; import org.apache.imperius.spl.parser.util.ActuatorFactory; -import org.apache.imperius.spl.parser.util.DataCollectorFactory; import org.apache.imperius.spl.parser.util.ExpressionUtility; +import org.apache.imperius.spl.parser.util.TypeInfo; import org.apache.imperius.spl.parser.util.TypeResolver; import org.apache.imperius.util.SPLLogger; -//import com.ibm.ac.cimspl.CIMSPLTypeConstants; - - -public class AnchorMethodInvokeAction implements BasicActionBlock +public class AnchorMethodInvokeAction implements BasicActionBlock { + + private String _className = null; + private SPLSymbolTable _symTable = null; + private List _identTupleList = null; + private String _operatorType = null; + private Expression _constantExpression = null; private static Logger logger = SPLLogger.getSPLLogger().getLogger(); + private static final String sourceClass = "MethodInvokeAction"; - private static final String sourceClass="MethodInvokeAction"; + public AnchorMethodInvokeAction(String className, List identTupleList, + String operatorType, Expression constExpr, SPLSymbolTable symTable) + { + logger.entering(sourceClass, Thread.currentThread().getName() + " " + + "MethodInvokeAction"); - private String _optClassName; + _className = className; + _identTupleList = identTupleList; + _operatorType = operatorType; + _constantExpression = constExpr; + _symTable = symTable; + _validate(); - private String _methodName; + logger.exiting(sourceClass, Thread.currentThread().getName() + " " + + "MethodInvokeAction"); + } - private SPLSymbolTable _symTab; - - private List _pList; - - private String _operatorType; - - private Expression _constantExpression; - - - - // cexp--->integer, compare action result with that, paramlist format---> - public AnchorMethodInvokeAction(String optClassName, String methodName, - List paramList, String op, Expression cExp, SPLSymbolTable symTab) throws SPLException + private void _validate() + { + try + { + boolean isArray = false; + if (!_identTupleList.isEmpty()) { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MethodInvokeAction"); + TypeInfo returnType = new TypeInfo(TypeConstants.referenceType, + _className, isArray); - - //System.out.println("creating MethodInvokeAction block " + optClassName+ " " + methodName); - _optClassName = optClassName; - _methodName = methodName; - _pList = paramList; - _symTab = symTab; - if ((op != null) && (op != "")) + Iterator identTupleIt = _identTupleList.iterator(); + int i = 0; + while (identTupleIt.hasNext()) + { + if (returnType.getType() == TypeConstants.referenceType) + { + String referenceTypeName = returnType + .getReferenceTypeName(); + IdentPrimaryTuple ipt = (IdentPrimaryTuple) identTupleIt + .next(); + if (i++ == 0) + { + ipt.setSymbolTable(_symTable); + } + returnType = ipt.validate(referenceTypeName); + } + } + } + } + catch (SPLException splex) { - _operatorType = op; + } - _constantExpression = cExp; - _validate(); + } - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MethodInvokeAction"); - - - } - public static void validateActualParameters(SPLSymbolTable symTab, - String classNameOrVariableName, - String methodName, - List pList) throws SPLException - { + String classNameOrVariableName, String methodName, List pList) + throws SPLException + { - MethodSymbol methodSym = - (MethodSymbol)symTab.getSymbol(classNameOrVariableName + "." + methodName); + MethodSymbol methodSym = (MethodSymbol) symTab + .getSymbol(classNameOrVariableName + "." + methodName); List argTypeList = methodSym.getArgumentList(); Iterator formalParamTypeIt = argTypeList.iterator(); Iterator actualParamIt = pList.iterator(); - if(argTypeList.size() == pList.size()) - { - while(formalParamTypeIt.hasNext() && actualParamIt.hasNext()) + if (argTypeList.size() == pList.size()) + { + while (formalParamTypeIt.hasNext() && actualParamIt.hasNext()) { - Argument formalArg = (Argument)formalParamTypeIt.next(); - Expression actualParam = (Expression)actualParamIt.next(); - if(!TypeResolver.isTypeAssignableForEquality(formalArg.getType(),actualParam.getType()) - || formalArg.getIsArray() != actualParam.isArray()) + Argument formalArg = (Argument) formalParamTypeIt.next(); + Expression actualParam = (Expression) actualParamIt.next(); + if (!TypeResolver.isTypeAssignableForEquality(formalArg + .getType(), actualParam.getType()) + || formalArg.getIsArray() != actualParam.isArray()) { - throw new SPLException("Formal and passed parameter types don't match for method " - + methodName); - } + throw new SPLException( + "Formal and passed parameter types don't match for method " + + methodName); + } - } - } - else + } + } + else { - System.err.println("Number of Formal and passed parameters don't match for method " - + methodName); -// throw new SPLException("Number of Formal and passed parameters don't match for method " -// + methodName); - } + System.err + .println("Number of Formal and passed parameters don't match for method " + + methodName); + // throw new SPLException("Number of Formal and passed parameters don't match for method " + // + methodName); + } + } + public boolean execute(Actuator ac) + { + boolean postExprResult = false; + int i = 0; + Object intermediateObject = null; + try + { + if (!_identTupleList.isEmpty()) + { + Iterator idIter = _identTupleList.iterator(); + while (idIter.hasNext()) + { + IdentPrimaryTuple ipt = (IdentPrimaryTuple) idIter.next(); + if (i++ == 0) + { + intermediateObject = ipt.evaluate(); + } + else + { + intermediateObject = ipt.evaluate(intermediateObject); + } + } } - private void _validate() throws SPLException - { + if (intermediateObject != null) + { + if (_constantExpression == null) + { + postExprResult = true; + } + else + { + Expression constexpr = this._constantExpression; + Object constresult; + int compareResult = 0; + try + { + constresult = constexpr.evaluate(); + compareResult = ExpressionUtility.compare( + intermediateObject, constresult); + } + catch (SPLException e) + { + e.printStackTrace(); + logger.severe(Thread.currentThread().getName() + " " + + e.getMessage()); - validateActualParameters(_symTab,_optClassName,_methodName,_pList); + } + String operation = this._operatorType; + if (operation.equalsIgnoreCase("==")) + { + if (compareResult != 0) + postExprResult = false; + else + postExprResult = true; + } + else if (operation.equalsIgnoreCase("!=")) + { + if (compareResult == 0) + postExprResult = false; + else + postExprResult = true; + } + else if (operation.equalsIgnoreCase(">=")) + { + if (compareResult < 0) + postExprResult = false; + else + postExprResult = true; + } + else if (operation.equalsIgnoreCase(">")) + { + if (compareResult <= 0) + postExprResult = false; + else + postExprResult = true; + } + else if (operation.equalsIgnoreCase("<")) + { + if (compareResult >= 0) + postExprResult = false; + else + postExprResult = true; + } + else if (operation.equalsIgnoreCase("<=")) + { + if (compareResult > 0) + postExprResult = false; + else + postExprResult = true; + } + else + { + logger + .severe(Thread.currentThread().getName() + + " " + + "operation did not match any of the standard expressions " + + operation); + } + } + //System.out.println("AnchorMethodInvokeAction returning "+postExprResult); + return postExprResult; + } + } + catch (SPLException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + logger.exiting(sourceClass, Thread.currentThread().getName() + " " + + "execute"); + return false; } - public static Object invokeClassMethod(SPLSymbolTable symTab, - String className, - String qualifier, - String methodName, - List paramList, - Object targetObject) + public static Object invokeClassMethod(SPLSymbolTable symTab, + String className, String qualifier, String methodName, + List paramList, Object targetObject) { - List parameterObjects = new ArrayList(); + List parameterObjects = new ArrayList(); - try + try { - MethodSymbol methodSym = - (MethodSymbol)symTab.getSymbol(className + "." + methodName); + MethodSymbol methodSym = (MethodSymbol) symTab.getSymbol(className + + "." + methodName); List argTypeList = methodSym.getArgumentList(); - - - for (int i = 0; i < paramList.size(); i++) + for (int i = 0; i < paramList.size(); i++) { Expression exp = (Expression) paramList.get(i); - if(exp instanceof AssignmentExpression) - { + if (exp instanceof AssignmentExpression) { //System.out.println("assignment Expression"); Expression lhsExpression = null; Expression rhsExpression = null; - AssignmentExpression assignmentExpression = (AssignmentExpression) exp; - if (assignmentExpression.getLHSExpression() instanceof org.apache.imperius.spl.external.Expression) + if (assignmentExpression.getLHSExpression() instanceof org.apache.imperius.spl.external.Expression) { lhsExpression = (Expression) assignmentExpression - .getLHSExpression(); + .getLHSExpression(); } - if (assignmentExpression.getRHSExpression() instanceof org.apache.imperius.spl.external.Expression) - { + if (assignmentExpression.getRHSExpression() instanceof org.apache.imperius.spl.external.Expression) { rhsExpression = (Expression) assignmentExpression - .getRHSExpression(); + .getRHSExpression(); } - if ((lhsExpression == null) || (rhsExpression == null)) + if ((lhsExpression == null) || (rhsExpression == null)) { - logger.severe("LHS or RHS or argument in method call is null : "+lhsExpression.toString()+" "+rhsExpression); + logger + .severe("LHS or RHS or argument in method call is null : " + + lhsExpression.toString() + + " " + + rhsExpression); - throw new SPLException("LHS or RHS or argument in method call is null : "+lhsExpression.toString()+" "+rhsExpression); + throw new SPLException( + "LHS or RHS or argument in method call is null : " + + lhsExpression.toString() + " " + + rhsExpression); } //System.out.println("lhsExpression class "+ lhsExpression.getClass()); @@ -189,22 +314,26 @@ // ((PrimaryExpression)lhsExpression).getPropertyName(); String keyName = ((PrimaryExpression) lhsExpression) - .getclassNameOrInstanceVariableName(); + .getclassNameOrInstanceVariableName(); //System.out.println("argument name= " + keyName); Object keyValue = rhsExpression.evaluate(); //System.out.println("argument value= " + keyValue); - String referenceTypeName=""; + String referenceTypeName = ""; - if(TypeResolver.isReference(rhsExpression.getType())) - { + if (TypeResolver.isReference(rhsExpression.getType())) + { - referenceTypeName = rhsExpression.getType().getReferenceTypeName(); + referenceTypeName = rhsExpression.getType() + .getReferenceTypeName(); } - if(keyValue!= null){ - Argument arg=new ArgumentImpl(rhsExpression.getType().getType(), keyName, rhsExpression.isArray(), referenceTypeName); + if (keyValue != null) + { + Argument arg = new ArgumentImpl(rhsExpression.getType() + .getType(), keyName, rhsExpression.isArray(), + referenceTypeName); arg.setValue(keyValue); //System.out.println("created new arg :"+keyName+" "+keyValue.toString()); /* @@ -214,219 +343,46 @@ parameterObjects.add(arg); } - } - else + } + else { //System.out.println("argument is not an assignment Expression"); Object result = exp.evaluate(); - Argument arg=new ArgumentImpl(exp.getType().getType(), null, exp.isArray(), null); + Argument arg = new ArgumentImpl(exp.getType().getType(), + null, exp.isArray(), null); arg.setValue(result); parameterObjects.add(arg); - } + } - } + } Actuator ac = ActuatorFactory.getActuator(); Object result = ac.invokeMethod(className, qualifier, targetObject, methodName, parameterObjects); - - //System.out.println("method invokation complete : "+className+" "+qualifier+" "+methodName+" "+targetObject); //System.out.println("method invokation result of invokation : "+result); // TO DO COMPARE RESULT WITH CONSTANT + if (result == null) + result = ""; - return result; - } - catch (SPLException e) + } + catch (SPLException e) { e.printStackTrace(); logger.severe(e.getMessage()); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "execute"); + logger.exiting(sourceClass, Thread.currentThread().getName() + " " + + "execute"); return null; } } - public boolean execute(Actuator ac) - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "execute"); - boolean postExprResult=false; - Object instance = _symTab.getInstance(_optClassName); - String qualifier = _symTab.getQualifierForClass(_optClassName); - Object result = invokeClassMethod(_symTab,_optClassName, qualifier, _methodName,_pList,instance); - - if(result != null ) - { - if(_constantExpression == null) - { - postExprResult = true; - } - else - { - Expression constexpr=this._constantExpression; - Object constresult; - int compareResult=0; - try{ - constresult=constexpr.evaluate(); - compareResult=ExpressionUtility.compare(result, constresult); - } - catch(SPLException e){ - e.printStackTrace(); - logger.severe(Thread.currentThread().getName()+" "+e.getMessage()); - - } - String operation=this._operatorType; - if(operation.equalsIgnoreCase("==")){ - if(compareResult!=0) - postExprResult=false; - else - postExprResult=true; - } - else if(operation.equalsIgnoreCase("!=")){ - if(compareResult==0) - postExprResult=false; - else - postExprResult=true; - } - else if(operation.equalsIgnoreCase(">=")){ - if(compareResult < 0) - postExprResult=false; - else - postExprResult=true; - } - else if(operation.equalsIgnoreCase(">")){ - if(compareResult <= 0) - postExprResult=false; - else - postExprResult=true; - } - else if(operation.equalsIgnoreCase("<")){ - if(compareResult >= 0) - postExprResult=false; - else - postExprResult=true; - } - else if(operation.equalsIgnoreCase("<=")){ - if(compareResult > 0) - postExprResult=false; - else - postExprResult=true; - } - else { - logger.severe(Thread.currentThread().getName()+" "+"operation did not match any of the standard expressions "+operation); - - } - } - //System.out.println("AnchorMethodInvokeAction returning "+postExprResult); - return postExprResult; - } - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "execute"); - return false; - - } - - public String getMethodName() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMethodName"); - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMethodName"); - - return _methodName; - } - - public void setMethodName(String methodName) - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setMethodName"); - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setMethodName"); - - _methodName = methodName; - } - - public String getOptClassName() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getOptClassName"); - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getOptClassName"); - - return _optClassName; - } - - public void setOptClassName(String optClassName) - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setOptClassName"); - - _optClassName = optClassName; - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setOptClassName"); - - } - - public List getPList() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPList"); - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPList"); - - return _pList; - } - - public void setPList(ArrayList list) - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setPList"); - - _pList = list; - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setPList"); - - } - - public Expression getConstantExpression() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getConstantExpression"); - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getConstantExpression"); - - return _constantExpression; - } - - public void setConstantExpression(Expression constantExpression) - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setConstantExpression"); - - _constantExpression = constantExpression; - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setConstantExpression"); - - } - - public String getOperatorType() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getOperatorType"); - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getOperatorType"); - - return _operatorType; - } - - public void setOperatorType(String operatorType) - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setOperatorType"); - - _operatorType = operatorType; - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setOperatorType"); - - } - - - -} +} \ No newline at end of file