Index: C:/Naidu/Projects/eclipse/policy_workspace/apache/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java =================================================================== --- C:/Naidu/Projects/eclipse/policy_workspace/apache/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java (revision 656122) +++ C:/Naidu/Projects/eclipse/policy_workspace/apache/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java (working copy) @@ -25,7 +25,9 @@ package org.apache.imperius.spl.parser.statements.actions.impl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import org.apache.imperius.spl.external.Actuator; @@ -75,97 +77,89 @@ { logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "execute"); - //System.out.println("Executing InvokePolicy action on "+this.getClassName()); - Expression _lhsExp = null; Expression _rhsExp = null; - - TypeInfo lType=null; - TypeInfo rType=null; - + TypeInfo lType = null; + try { - //System.out.println("size of parameters in InvokePolicy action block :"+ this._paramList.size()); - if(_paramList.size() > 2 || _paramList.size() == 0) + InternalClient internalClientObj = null; + // System.out.println("parameters List " + _paramList); + if(_paramList.size() == 0) { - logger.severe( - "number of parameters passed to a InvokePolicyAction shoul be 2"); - + logger.severe("number of parameters passed to a InvokePolicyAction should be 2 or more"); throw new SPLException("Last Expression should be a collection"); - } - if(_paramList.size()==1) + } + else { + internalClientObj = InternalClientFactory.getInternalClient(); _lhsExp = (Expression)_paramList.get(0); - lType=_lhsExp.getType(); - - if (lType.getType() != TypeConstants.stringType) { - logger.severe( - "first Expression should be a string describing the Operation"); - throw new SPLException( - "first Expression should be a string describing the Operation"); + logger.severe("first Expression should be a string describing the name of the policy to invoke"); + throw new SPLException("first Expression should be a string describing the name of the policy to invoke"); } - - String policyName=(String)_lhsExp.evaluate(); - InternalClient ic=InternalClientFactory.getInternalClient(); - int returnValue=ic.invokePolicy(policyName, null, true); - //System.out.println("policy evaluations return val="+returnValue); - return true; - } - if(_paramList.size()==2) - { - _lhsExp = (Expression)_paramList.get(0); - _rhsExp = (Expression)_paramList.get(1); - - lType=_lhsExp.getType(); - rType=_rhsExp.getType(); - - - if (lType.getType() != TypeConstants.stringType) + String policyName = (String)_lhsExp.evaluate(); + + if(_paramList.size() > 1) { - logger.severe( - "first Expression should be a string describing the Operation"); - throw new SPLException( - "first Expression should be a string describing the Operation"); + // get second parameter + _rhsExp = (Expression)_paramList.get(1); + Object rhsResult = _rhsExp.evaluate(); + if ((rhsResult instanceof java.util.List)) + { + List instanceInfoList = (List)rhsResult; + internalClientObj.invokePolicy(policyName, instanceInfoList, true); + } + else + { + Map instanceInfoMap = new HashMap(); + Expression tempExpr = null; + Object keyObj = null; + Object valueObj = null; + if(((_paramList.size()-1) % 2) == 0) + { + for(int i=1;i<_paramList.size();i++) + { + tempExpr = (Expression)_paramList.get(i); + keyObj = tempExpr.evaluate(); + if(++i < _paramList.size()) + { + tempExpr = (Expression)_paramList.get(i); + valueObj = tempExpr.evaluate(); + } + else + { + logger.severe("instance names and instances passed are not same"); + throw new SPLException("instance names and instances passed are not same"); + } + instanceInfoMap.put(keyObj,valueObj); + } + internalClientObj.invokePolicy(policyName, instanceInfoMap); + } + else + { + throw new SPLException("number of parameters passed is insufficient to invoke the policy"); + } + } } - String policyName=(String)_lhsExp.evaluate(); - - Object rhsResult = _rhsExp.evaluate(); - //System.out.println("rhsResult , class " + rhsResult + " "+ rhsResult.getClass()); - if (!(rhsResult instanceof java.util.List)) + else { - - logger.severe( - "rhsResult is not of type List"); - - throw new SPLException("rhsResult is not of type List"); + internalClientObj.invokePolicy(policyName, null, true); } - List instanceList=(List)rhsResult; - InternalClient ic=InternalClientFactory.getInternalClient(); - int returnValue=ic.invokePolicy(policyName, instanceList, true); - //System.out.println("policy evaluations return val="+returnValue); - return true; - } - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "execute"); - - return false; + return true; } catch (SPLException e) { logger.severe(e.getMessage()); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "execute"); - return false; } - - } - + public String getClassName() { logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getClassName");