incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jnee...@apache.org
Subject svn commit: r667539 - in /incubator/imperius/trunk: imperius-javaspl/src/main/java/org/apache/imperius/javaspl/ imperius-splcore/src/main/java/org/apache/imperius/spl/external/ imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/ac...
Date Fri, 13 Jun 2008 13:44:13 GMT
Author: jneeraj
Date: Fri Jun 13 06:44:12 2008
New Revision: 667539

URL: http://svn.apache.org/viewvc?rev=667539&view=rev
Log:
Commited changes for IMPERIUS-9 - Cascaded policy invocation changes by Naidu J

Added:
    incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/InvokePolicySample.spl
    incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/SimpleInvokePolicy.spl
Modified:
    incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/external/InternalClient.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java
    incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
    incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java

Modified: incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java?rev=667539&r1=667538&r2=667539&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java
(original)
+++ incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java
Fri Jun 13 06:44:12 2008
@@ -32,9 +32,11 @@
 
 import org.apache.imperius.spl.external.Actuator;
 import org.apache.imperius.spl.external.DataCollector;
+import org.apache.imperius.spl.external.InternalClient;
 import org.apache.imperius.spl.manager.PolicyManager;
 import org.apache.imperius.spl.manager.impl.PolicyManagerImpl;
 import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.InternalClientFactory;
 
 
 
@@ -43,109 +45,113 @@
 public class Java_SPLPolicyRuleProvider 
 {
 
-	
-	private PolicyManager _policyManager= null;
-	
-	
-	public Java_SPLPolicyRuleProvider() throws SPLException
-	{
-		initialize();
-		
-	}
-	
-	public void cleanup() throws SPLException {
-		
-        
-		
-	}
-
-	public void initialize() throws SPLException
-	{
-	 
-		
-		DataCollector dc = new JavaDataCollectorImpl();
-		Actuator ac = new JavaActuatorImpl();
-		
-		
-		_policyManager= new PolicyManagerImpl(dc,ac);
-			
-		
-	}
-
-
-	public boolean createPolicy(String name, String policyString) throws SPLException 
-	{
-		
+    
+    private PolicyManager _policyManager= null;
+    
+    
+    public Java_SPLPolicyRuleProvider() throws SPLException
+    {
+        initialize();
+        
+    }
+    
+    public void cleanup() throws SPLException {
+        
+        
+        
+    }
+
+    public void initialize() throws SPLException
+    {
+     
+        
+        DataCollector dc = new JavaDataCollectorImpl();
+        Actuator ac = new JavaActuatorImpl();
+        
+        
+        _policyManager= new PolicyManagerImpl(dc,ac);
+        
+        // registering internal client
+        InternalClient oInternalClientObj = new InternalClient(_policyManager);
+        InternalClientFactory.registerInternalClient(oInternalClientObj);
+            
+        
+    }
+
+
+    public boolean createPolicy(String name, String policyString) throws SPLException 
+    {
+        
         boolean result = _policyManager.createPolicy(name,policyString);
        
-		return result;
-	}
-	
-	public boolean validatePolicyString(String policyString) throws SPLException 
-	{
-		
+        return result;
+    }
+    
+    public boolean validatePolicyString(String policyString) throws SPLException 
+    {
+        
         boolean result = _policyManager.validatePolicyString(policyString);
        
-		return result;
-	}
+        return result;
+    }
 
-	public void deletePolicy(String name) throws SPLException 
-	{
-		
-		_policyManager.deletePolicy(name);
-		
-		return;
-	}
+    public void deletePolicy(String name) throws SPLException 
+    {
+        
+        _policyManager.deletePolicy(name);
+        
+        return;
+    }
 
-	public List enumeratePolicyNames() throws SPLException 
-	{
+    public List enumeratePolicyNames() throws SPLException 
+    {
 
         List policyNames = _policyManager.getAllPolicyNames();
-		
-		return policyNames;
-	}
+        
+        return policyNames;
+    }
 
-	public Map enumeratePolicies() throws SPLException 
-	{
+    public Map enumeratePolicies() throws SPLException 
+    {
 
         Map policyInstances = _policyManager.getAllPolicies();
-		
-		return policyInstances;
+        
+        return policyInstances;
 
-	}
+    }
 
-	
-	public String getPolicy(String policyName) throws SPLException 
-	{
+    
+    public String getPolicy(String policyName) throws SPLException 
+    {
 
         String policy = _policyManager.getPolicy(policyName);
-		
-		return policy;
+        
+        return policy;
 
-	}
+    }
 
-	public void modifyPolicy(String name, String policyString) throws SPLException {
+    public void modifyPolicy(String name, String policyString) throws SPLException {
 
-		
-		_policyManager.updatePolicy(name,policyString);
+        
+        _policyManager.updatePolicy(name,policyString);
         
 
-	}
+    }
 
-	public Object executePolicy(String policyName, Map instanceObjectMap) throws SPLException

-	{
-	 
+    public Object executePolicy(String policyName, Map instanceObjectMap) throws SPLException

+    {
+     
+        
+        Object retVal = _policyManager.evaluatePolicy(policyName,instanceObjectMap);
+    
         
-		Object retVal = _policyManager.evaluatePolicy(policyName,instanceObjectMap);
+        return retVal;
+    }
     
+    public static void main(String [] args)
+    {
         
-		return retVal;
-	}
-	
-	public static void main(String [] args)
-	{
-		
 
-	}
+    }
 
 }

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/external/InternalClient.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/external/InternalClient.java?rev=667539&r1=667538&r2=667539&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/external/InternalClient.java
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/external/InternalClient.java
Fri Jun 13 06:44:12 2008
@@ -26,7 +26,6 @@
 
 package org.apache.imperius.spl.external;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -35,19 +34,16 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.apache.imperius.spl.external.*;
 import org.apache.imperius.spl.manager.PolicyManager;
 import org.apache.imperius.spl.parser.exceptions.SPLException;
 import org.apache.imperius.spl.parser.statements.impl.PolicyInfo;
 import org.apache.imperius.spl.parser.util.DataCollectorFactory;
-import org.apache.imperius.spl.parser.util.TypeInfo;
-//import org.pegasus.jmpi.CIMObjectPath;
 import org.apache.imperius.util.SPLLogger;
 
 public class InternalClient
 {
-	private List inputParams =null;
-	private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+    private List inputParams =null;
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
 
 
 //    private static InvokePolicy internalClient=null;
@@ -62,6 +58,45 @@
     private static final String sourceClass="InternalClient";
     
 
+    public int invokePolicy(String policyName, Map instanceMap)
+    {
+        int returnValue = 0;
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+"InvokePolicy");
+        try
+        {
+            PolicyInfo policyInfo = pm.getPolicyInfo(policyName);
+            if(policyInfo == null)
+            {
+                throw new SPLException("policy with this name "+policyName+" is not found
in repository");
+            }
+            
+            if(instanceMap != null && instanceMap.size() > 0)
+            {
+                Integer retVal = (Integer) pm.evaluatePolicy(policyName,instanceMap);
+                if (logger.isLoggable(Level.FINE))
+                    logger.fine(Thread.currentThread().getName()+" return value is = "+retVal);
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokePolicy");

+                
+                if (retVal.intValue() == POLICY_EVALUATION_FAILED)
+                {
+                    logger.severe("POLICY_EVALUATION_FAILED "+policyName+" "+retVal);
+                    returnValue++;
+                }
+                if(logger.isLoggable(Level.FINE))
+                    logger.fine(Thread.currentThread().getName()+" Internal client return
value="+returnValue);
+            }
+            return 0;
+        }
+        catch(SPLException e)
+        {
+            logger.severe(e.getMessage());
+        }
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"InvokeMethod");
+        if(logger.isLoggable(Level.FINE))
+            logger.fine(Thread.currentThread().getName()+" Internal client return value is
-1");
+        
+        return -1;
+    }
    
     public int invokePolicy(String policyName, List paramList, boolean boo)
     {
@@ -73,123 +108,123 @@
         {
             if(objectrefList==null )
             {
-            	Map objectMap=new HashMap();
-            	PolicyInfo policyInfo=pm.getPolicyInfo(policyName);
-				Map classQuaifierMap=policyInfo.getClassQualifierMap();
-				Iterator classit=classQuaifierMap.keySet().iterator();
-				logger.fine("number of classes in policy = "+classQuaifierMap.size());
-
-				
-				if(classQuaifierMap.size()==0 || classQuaifierMap.size()>1)
-				{
-					logger.fine("number of classes in policy should be one");
-				}
-				while(classit.hasNext())
-				{
-					String className=(String)classit.next();
-					String nameSpace=(String)classQuaifierMap.get(className);
-					List copList=dc.enumerateInstanceNames(className, nameSpace);
-					Iterator it=copList.iterator();
-					while(it.hasNext())
-					{	
-						Object copI=(Object)it.next();
-												
-						String objectName=className;
-						
-						InstanceInfo iI=new InstanceInfo(objectName,copI);
-						
-						List instanceInfoList = new ArrayList();
-						instanceInfoList.add(iI);
-
-						objectMap.put(objectName, instanceInfoList);
-						
-						Integer retVal=(Integer)pm.evaluatePolicy(policyName,objectMap);
-						if (logger.isLoggable(Level.FINE))
-							logger.fine(Thread.currentThread().getName()+" return value is = "+retVal);
-						
-						logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokePolicy"); 
-						
-						if (retVal.intValue() ==POLICY_EVALUATION_FAILED)
-						{
-							logger.severe("POLICY_EVALUATION_FAILED "+policyName+" "+copI.toString()+" "+retVal);
-							returnValue++;
-						}
-						else
-						{
-							logger.severe("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+copI.toString()+" "+retVal);
-							
-						}
-			            if(logger.isLoggable(Level.FINE))
-			                logger.fine(Thread.currentThread().getName()+" Internal client return
value="+returnValue);
-			            objectMap.remove(instanceInfoList);
-						
-					}
-					logger.fine("internal client finished iterating over all instances ");
-					break;
-				}
+                Map objectMap=new HashMap();
+                PolicyInfo policyInfo=pm.getPolicyInfo(policyName);
+                Map classQuaifierMap=policyInfo.getClassQualifierMap();
+                Iterator classit=classQuaifierMap.keySet().iterator();
+                logger.fine("number of classes in policy = "+classQuaifierMap.size());
+
+                
+                if(classQuaifierMap.size()==0 || classQuaifierMap.size()>1)
+                {
+                    logger.fine("number of classes in policy should be one");
+                }
+                while(classit.hasNext())
+                {
+                    String className=(String)classit.next();
+                    String nameSpace=(String)classQuaifierMap.get(className);
+                    List copList=dc.enumerateInstanceNames(className, nameSpace);
+                    Iterator it=copList.iterator();
+                    while(it.hasNext())
+                    {   
+                        Object copI=(Object)it.next();
+                                                
+                        String objectName=className;
+                        
+                        InstanceInfo iI=new InstanceInfo(objectName,copI);
+                        
+                        List instanceInfoList = new ArrayList();
+                        instanceInfoList.add(iI);
+
+                        objectMap.put(objectName, instanceInfoList);
+                        
+                        Integer retVal=(Integer)pm.evaluatePolicy(policyName,objectMap);
+                        if (logger.isLoggable(Level.FINE))
+                            logger.fine(Thread.currentThread().getName()+" return value is
= "+retVal);
+                        
+                        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokePolicy");

+                        
+                        if (retVal.intValue() ==POLICY_EVALUATION_FAILED)
+                        {
+                            logger.severe("POLICY_EVALUATION_FAILED "+policyName+" "+copI.toString()+"
"+retVal);
+                            returnValue++;
+                        }
+                        else
+                        {
+                            logger.severe("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+copI.toString()+"
"+retVal);
+                            
+                        }
+                        if(logger.isLoggable(Level.FINE))
+                            logger.fine(Thread.currentThread().getName()+" Internal client
return value="+returnValue);
+                        objectMap.remove(instanceInfoList);
+                        
+                    }
+                    logger.fine("internal client finished iterating over all instances ");
+                    break;
+                }
             }
             else
             {
-            	
-            	Map objectMap=new HashMap();
-            	PolicyInfo policyInfo=pm.getPolicyInfo(policyName); 
-				Map classQuaifierMap=policyInfo.getClassQualifierMap();
-				Iterator classit=classQuaifierMap.keySet().iterator();
-				logger.fine("number of classes in policy = "+classQuaifierMap.size());
-				
-				if(classQuaifierMap.size()==0 || classQuaifierMap.size()>1)
-				{
-					logger.fine("number of classes in policy should be one");
-				}
-				while(classit.hasNext()){
-					String className=(String)classit.next();
-					String nameSpace=(String)classQuaifierMap.get(className);
-					List copList=objectrefList;
-					Iterator it=copList.iterator();
-					while(it.hasNext())
-					{	
-						Object copI=(Object)it.next();
-						logger.fine("instance objectpath= "+copI.toString());
-						
-						String objectName=className;
-						
-						//InstanceInfo iI=new InstanceInfo(objectName,copI);
-						
-						//List instanceInfoList = new ArrayList();
-						//instanceInfoList.add(iI);
-
-						objectMap.put(objectName, copI);
-						
-						Integer retVal=(Integer)pm.evaluatePolicy(policyName,objectMap);
-						if (logger.isLoggable(Level.FINE))
-							logger.fine(Thread.currentThread().getName()+" return value is = "+retVal);
-						
-						logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokeMethod"); 
-						
-						if (retVal.intValue() ==POLICY_EVALUATION_FAILED )
-						{
-							logger.fine("POLICY_EVALUATION_FAILED || POLICY_NOT_EVALUATED "+policyName+" "+copI.toString()+"
"+retVal);
-							returnValue++;
-						}
-						else
-						{
-							logger.fine("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+copI.toString()+" "+retVal);
-							
-						}
-			            if(logger.isLoggable(Level.FINE))
-			                logger.fine(Thread.currentThread().getName()+" Internal client return
value="+returnValue);
-			            objectMap.remove(copI);
-						
-					}
-					logger.fine("internal client finished iterating over all instances ");
-					break;
-				}
+                
+                Map objectMap=new HashMap();
+                PolicyInfo policyInfo=pm.getPolicyInfo(policyName); 
+                Map classQuaifierMap=policyInfo.getClassQualifierMap();
+                Iterator classit=classQuaifierMap.keySet().iterator();
+                logger.fine("number of classes in policy = "+classQuaifierMap.size());
+                
+                if(classQuaifierMap.size()==0 || classQuaifierMap.size()>1)
+                {
+                    logger.fine("number of classes in policy should be one");
+                }
+                while(classit.hasNext()){
+                    String className=(String)classit.next();
+                    String nameSpace=(String)classQuaifierMap.get(className);
+                    List copList=objectrefList;
+                    Iterator it=copList.iterator();
+                    while(it.hasNext())
+                    {   
+                        Object copI=(Object)it.next();
+                        logger.fine("instance objectpath= "+copI.toString());
+                        
+                        String objectName=className;
+                        
+                        //InstanceInfo iI=new InstanceInfo(objectName,copI);
+                        
+                        //List instanceInfoList = new ArrayList();
+                        //instanceInfoList.add(iI);
+
+                        objectMap.put(objectName, copI);
+                        
+                        Integer retVal=(Integer)pm.evaluatePolicy(policyName,objectMap);
+                        if (logger.isLoggable(Level.FINE))
+                            logger.fine(Thread.currentThread().getName()+" return value is
= "+retVal);
+                        
+                        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokeMethod");

+                        
+                        if (retVal.intValue() ==POLICY_EVALUATION_FAILED )
+                        {
+                            logger.fine("POLICY_EVALUATION_FAILED || POLICY_NOT_EVALUATED
"+policyName+" "+copI.toString()+" "+retVal);
+                            returnValue++;
+                        }
+                        else
+                        {
+                            logger.fine("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+copI.toString()+"
"+retVal);
+                            
+                        }
+                        if(logger.isLoggable(Level.FINE))
+                            logger.fine(Thread.currentThread().getName()+" Internal client
return value="+returnValue);
+                        objectMap.remove(copI);
+                        
+                    }
+                    logger.fine("internal client finished iterating over all instances ");
+                    break;
+                }
             }
 
 
-			
-			
-			return 0;
+            
+            
+            return 0;
               
         }
         catch(SPLException e)
@@ -232,7 +267,4 @@
         
     }  
   
-
-
-    
 }

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java?rev=667539&r1=667538&r2=667539&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/actions/impl/InvokePolicyAction.java
Fri Jun 13 06:44:12 2008
@@ -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;
@@ -44,166 +46,157 @@
 public class InvokePolicyAction implements BasicActionBlock
 {
 
-	private List _paramList;
+    private List _paramList;
 
-	private String _className;
+    private String _className;
 
-	private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
 
-	public static final int POLICY_EVALUATED_SUCCESSFULLY = 0;
-	public static final int POLICY_NOT_EVALUATED = 1;
-	public static final int POLICY_EVALUATION_FAILED = -1;
+    public static final int POLICY_EVALUATED_SUCCESSFULLY = 0;
+    public static final int POLICY_NOT_EVALUATED = 1;
+    public static final int POLICY_EVALUATION_FAILED = -1;
+
+
+    private static final String sourceClass="InvokePolicyAction";
+
+
+    public InvokePolicyAction(List paramList)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "InvokePolicyAction");
+        //System.out.println("creating InvokePolicyAction ");
+
+//      _className = className;
+        _paramList = paramList;
+
+
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "InvokePolicyAction");
+
+    }
+
+    public boolean execute(Actuator ac)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "execute");
+
+        Expression _lhsExp = null;
+        Expression _rhsExp = null;
+        TypeInfo lType = null;
+        
+        try
+        {
+            InternalClient internalClientObj = null;
+            // System.out.println("parameters List " + _paramList);
+            if(_paramList.size() == 0)
+            {
+                logger.severe("number of parameters passed to a InvokePolicyAction should
be 2 or more");
+                throw new SPLException("Last Expression should be a collection");
+            } 
+            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 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();
+                
+                if(_paramList.size() > 1)
+                {
+                    // 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");
+                        }
+                    }
+                }
+                else
+                {
+                    internalClientObj.invokePolicy(policyName, null, true);
+                }
+            }
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "execute");
+            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");
+
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getClassName");
+
+        return _className;
+    }
+
+    public void setClassName(String className)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setClassName");
+
+
+        _className = className;
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setClassName");
+
+    }
+
+    public List getParamList()
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getParamList");
+
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getParamList");
+
+        return _paramList;
+    }
+
+    public void setParamList(ArrayList paramList)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setParamList");
 
 
-	private static final String sourceClass="InvokePolicyAction";
+        _paramList = paramList;
 
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setParamList");
 
-	public InvokePolicyAction(List paramList)
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "InvokePolicyAction");
-		//System.out.println("creating InvokePolicyAction ");
-
-//		_className = className;
-		_paramList = paramList;
-
-
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "InvokePolicyAction");
-
-	}
-
-	public boolean execute(Actuator ac)
-	{
-		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;
-
-		try
-		{
-			//System.out.println("size of parameters in InvokePolicy action block :"+ this._paramList.size());
-			if(_paramList.size() > 2 || _paramList.size() == 0)
-			{
-				logger.severe(
-						"number of parameters passed to a InvokePolicyAction shoul be 2");
-
-				throw new SPLException("Last Expression should be a collection");
-			}
-			if(_paramList.size()==1)
-			{
-				_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");
-				}
-
-				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)
-				{
-					logger.severe(
-							"first Expression should be a string describing the Operation");
-					throw new SPLException(
-							"first Expression should be a string describing the Operation");
-				}
-				String policyName=(String)_lhsExp.evaluate();
-
-				Object rhsResult = _rhsExp.evaluate();
-				//System.out.println("rhsResult , class " + rhsResult + " "+ rhsResult.getClass());
-				if (!(rhsResult instanceof java.util.List))
-				{
-
-					logger.severe(
-							"rhsResult is not of type List");
-
-					throw new SPLException("rhsResult is not of type List");
-				}
-				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;
-		}
-		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");
-
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getClassName");
-
-		return _className;
-	}
-
-	public void setClassName(String className)
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setClassName");
-
-
-		_className = className;
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setClassName");
-
-	}
-
-	public List getParamList()
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getParamList");
-
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getParamList");
-
-		return _paramList;
-	}
-
-	public void setParamList(ArrayList paramList)
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setParamList");
-
-
-		_paramList = paramList;
-
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setParamList");
-
-	}
-
+    }
 
 }

Added: incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/InvokePolicySample.spl
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/InvokePolicySample.spl?rev=667539&view=auto
==============================================================================
--- incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/InvokePolicySample.spl
(added)
+++ incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/InvokePolicySample.spl
Fri Jun 13 06:44:12 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+Import  Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te;
+Strategy Execute_All_Applicable;
+Policy 
+{
+Declaration
+{
+    four = 4;
+}
+Condition 
+{  
+    SquareRoot(16) == four && te.privateVariable == 0
+}
+Decision 
+{   
+	InvokePolicy("SimpleInvokePolicy", "sc1", te.sampleClassInstance) == 0
+}
+}:1;
\ No newline at end of file

Added: incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/SimpleInvokePolicy.spl
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/SimpleInvokePolicy.spl?rev=667539&view=auto
==============================================================================
--- incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/SimpleInvokePolicy.spl
(added)
+++ incubator/imperius/trunk/javaspl-samples/resources/samples/simple/policies/SimpleInvokePolicy.spl
Fri Jun 13 06:44:12 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+// 
+Import  Class org.apache.imperius.javaspl.samples.simplepolicies.SampleClass:sc1;
+Strategy Execute_All_Applicable;
+Policy 
+{
+Declaration
+{
+    four = 4;
+}
+Condition 
+{  
+
+     SquareRoot(16) == four
+}
+Decision 
+{   
+	Set(sc1.sampleClassProperty2 = 4) 
+}
+}:1;
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Modified: incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java?rev=667539&r1=667538&r2=667539&view=diff
==============================================================================
--- incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
(original)
+++ incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
Fri Jun 13 06:44:12 2008
@@ -29,130 +29,130 @@
 import org.apache.imperius.spl.parser.exceptions.SPLException;
 
 public class RunSamples {
-	
-	public static String policyFolder = "policies/";
+    
+    public static String policyFolder = "policies/";
 
-	/**
-	 * @param args
-	 */
-	public static void main(String[] args) 
-	{
-		if(args.length == 0)
-		{	
-			RunSamples.test();
-		}
-		else
-		{
-			RunSamples.testPolicy(args[0]);
-		}
-
-	}
-	
-	public static void _test(String policyName, Map objMap)
-	{
-		try 
-		{
-			
-			Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider();
-			String aFile = policyFolder + policyName + ".spl";
-			//System.out.println("starting test");
-			StringBuffer contents = new StringBuffer();
-			BufferedReader input = null;
-			try
-			{
-				input = new BufferedReader( new FileReader(aFile) );
-				String line = null; 
-		     
-				while (( line = input.readLine()) != null)
-				{
-					contents.append(line);
-					contents.append(System.getProperty("line.separator"));
-				}
-				input.close();
-		    }
-		    catch (FileNotFoundException ex) 
-		    {
-		      ex.printStackTrace();
-		    }
-		    catch (IOException ex){
-		      ex.printStackTrace();
-		    }
-		    try
-		    {
-		    	jspl.deletePolicy(policyName);
-		    }
-		    catch(Exception e)
-		    {
-		    	
-		    }
-		    
-		    boolean createReturn=jspl.createPolicy(policyName, contents.toString());
-		    System.out.println("Policy Created : " + policyName +createReturn);
-		    System.out.println("");
-		    Object result = jspl.executePolicy(policyName, objMap);
-			System.out.println("Result is " + result);
-		}   
-		catch (SPLException e) 
-		{				// TODO Auto-generated catch block
-			e.printStackTrace();
-		}  
-		
-	}
-	public static void testPolicy(String policyToExecute)
-	{
-		TestElement te=new TestElement();
-		
-	    Map objMap = new Hashtable();
-	    objMap.put("te", te);
-	    	    
-		_test(policyToExecute,objMap);      
-			
-				
-		
-	}
-	
-	public static void testBasicPolicy() 
-	{
-	
-		String policyToExecute = "BasicPolicy";	
-			
-			
-	    Map objMap = new Hashtable();
-	    
-	    SampleClass sc1 = new SampleClass(1,2);
-	    objMap.put("sc1", sc1);
-	    
-	    SampleClass sc2 = new SampleClass(3,4);
-	    objMap.put("sc2", sc2);
-	    
-	    AnotherClass ac1 = new AnotherClass(5,6);
-	    objMap.put("ac1", ac1);
-	
-		_test(policyToExecute,objMap);
-		
-		
-	}	
-	public static void test()
-	{
-		String [] policiesToTest = {"SimplePolicy","ComplexPolicy",
-				"MultiplePolicySample","InvokeMethodSample","DateTime","MacroSample"};
-			
-		for (int i=0 ; i < policiesToTest.length; i++)
-		{
-			String policy = policiesToTest[i];
-			testPolicy(policy);
-		}
-		testBasicPolicy();
-
-		
-	}
-
-	public static void test(String pFolder) {
-		
-		policyFolder = pFolder;
-		test();
-	
-		
-	}
+    /**
+     * @param args
+     */
+    public static void main(String[] args) 
+    {
+        if(args.length == 0)
+        {   
+            RunSamples.test();
+        }
+        else
+        {
+            RunSamples.testPolicy(args[0]);
+        }
+
+    }
+    
+    public static void _test(String policyName, Map objMap)
+    {
+        try 
+        {
+            
+            Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider();
+            String aFile = policyFolder + policyName + ".spl";
+            //System.out.println("starting test");
+            StringBuffer contents = new StringBuffer();
+            BufferedReader input = null;
+            try
+            {
+                input = new BufferedReader( new FileReader(aFile) );
+                String line = null; 
+             
+                while (( line = input.readLine()) != null)
+                {
+                    contents.append(line);
+                    contents.append(System.getProperty("line.separator"));
+                }
+                input.close();
+            }
+            catch (FileNotFoundException ex) 
+            {
+              ex.printStackTrace();
+            }
+            catch (IOException ex){
+              ex.printStackTrace();
+            }
+            try
+            {
+                jspl.deletePolicy(policyName);
+            }
+            catch(Exception e)
+            {
+                
+            }
+            
+            boolean createReturn=jspl.createPolicy(policyName, contents.toString());
+            System.out.println("Policy Created : " + policyName +createReturn);
+            System.out.println("");
+            Object result = jspl.executePolicy(policyName, objMap);
+            System.out.println("Result is " + result);
+        }   
+        catch (SPLException e) 
+        {               // TODO Auto-generated catch block
+            e.printStackTrace();
+        }  
+        
+    }
+    public static void testPolicy(String policyToExecute)
+    {
+        TestElement te=new TestElement();
+        
+        Map objMap = new Hashtable();
+        objMap.put("te", te);
+                
+        _test(policyToExecute,objMap);      
+            
+                
+        
+    }
+    
+    public static void testBasicPolicy() 
+    {
+    
+        String policyToExecute = "BasicPolicy"; 
+            
+            
+        Map objMap = new Hashtable();
+        
+        SampleClass sc1 = new SampleClass(1,2);
+        objMap.put("sc1", sc1);
+        
+        SampleClass sc2 = new SampleClass(3,4);
+        objMap.put("sc2", sc2);
+        
+        AnotherClass ac1 = new AnotherClass(5,6);
+        objMap.put("ac1", ac1);
+    
+        _test(policyToExecute,objMap);
+        
+        
+    }   
+    public static void test()
+    {
+        String [] policiesToTest = {"SimplePolicy","ComplexPolicy",
+                "MultiplePolicySample","InvokeMethodSample","DateTime","MacroSample","SimpleInvokePolicy","InvokePolicySample"};
+            
+        for (int i=0 ; i < policiesToTest.length; i++)
+        {
+            String policy = policiesToTest[i];
+            testPolicy(policy);
+        }
+        testBasicPolicy();
+
+        
+    }
+
+    public static void test(String pFolder) {
+        
+        policyFolder = pFolder;
+        test();
+    
+        
+    }
 
 }

Modified: incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java?rev=667539&r1=667538&r2=667539&view=diff
==============================================================================
--- incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
(original)
+++ incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
Fri Jun 13 06:44:12 2008
@@ -23,54 +23,55 @@
 
 public class TestElement 
 {
-	public String ElementName;
+    public String ElementName;
 
-	public String s; 
-	public char c;
-	public double r64;
-	public float r32;
-	public Calendar d;
-	public long s64;
-	public int s32;
-	public short s16;
-	public byte s8;
-	public boolean b;
-	private int privateVariable;
-	
-	public void setPrivateVariable(int s)
-	{
-	    privateVariable = s;
-	}
-	
-	public int getPrivateVariable()
-	{
-	    return privateVariable;
-	}
+    public String s; 
+    public char c;
+    public double r64;
+    public float r32;
+    public Calendar d;
+    public long s64;
+    public int s32;
+    public short s16;
+    public byte s8;
+    public boolean b;
+    private int privateVariable;
+    public SampleClass sampleClassInstance = new SampleClass(5, 10);
+    
+    public void setPrivateVariable(int s)
+    {
+        privateVariable = s;
+    }
+    
+    public int getPrivateVariable()
+    {
+        return privateVariable;
+    }
 
-	public String childProperty;
+    public String childProperty;
     
     public int testMethod(int a, int b)
     {
-    	return a + b;
+        return a + b;
     }
     
     public TestElement()
     {
-    	ElementName = "Element1";
+        ElementName = "Element1";
 
-    	s="string5"; 
-    	c='d';
-       	r64=54.0;
-    	r32=54.0f;
-    	d= new GregorianCalendar();
-    	s64=-530;
-    	s32=-530;
-    	s16=-50;
-    	s8=-10;
-    	b=false;
-    	childProperty="child property5";
+        s="string5"; 
+        c='d';
+        r64=54.0;
+        r32=54.0f;
+        d= new GregorianCalendar();
+        s64=-530;
+        s32=-530;
+        s16=-50;
+        s8=-10;
+        b=false;
+        childProperty="child property5";
 
-    	
+        
     }
 
 



Mime
View raw message