incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jnee...@apache.org
Subject svn commit: r608597 - in /incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl: ImportStatement.java SPLPolicy.java
Date Thu, 03 Jan 2008 19:10:20 GMT
Author: jneeraj
Date: Thu Jan  3 11:10:13 2008
New Revision: 608597

URL: http://svn.apache.org/viewvc?rev=608597&view=rev
Log:
1) The user provides a map 
with instancename -> instanceobject
and 2) the evaluator will silently ignore instances that are not imported 
inside the policy

Modified:
    incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/ImportStatement.java
    incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java

Modified: incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/ImportStatement.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/ImportStatement.java?rev=608597&r1=608596&r2=608597&view=diff
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/ImportStatement.java
(original)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/ImportStatement.java
Thu Jan  3 11:10:13 2008
@@ -36,6 +36,7 @@
 	private List _importInstanceInfoList;
 	private Expression _expr;
 	private SPLSymbolTable _symTab;
+	private String _anchorClassName;
 	private static Logger logger = SPLLogger.getSPLLogger().getLogger();
     private static final String sourceClass="ImportStatement";
     
@@ -58,11 +59,12 @@
         
 	}
 
-	public ImportStatement(List importInstanceInfoList, Expression e,SPLSymbolTable symTab)
+	public ImportStatement(String anchorClassName, 
+	        List importInstanceInfoList, Expression e,SPLSymbolTable symTab)
 	{
         logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "ImportStatement");
         
-		
+		this._anchorClassName = anchorClassName;
 		this._expr = e;
 		this._symTab = symTab;
 		_importInstanceInfoList=new ArrayList();
@@ -104,6 +106,16 @@
 		return _importInstanceInfoList;
 		
 	}
+
+    public String getAnchorClassName()
+    {
+        return _anchorClassName;
+    }
+
+    public void setAnchorClassName(String className)
+    {
+        _anchorClassName = className;
+    }
 
 	
 

Modified: incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java?rev=608597&r1=608596&r2=608597&view=diff
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java
(original)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java
Thu Jan  3 11:10:13 2008
@@ -343,7 +343,7 @@
 	}
 
 
-	public int evaluate(DataCollector dc, Actuator ac, Map instanceMap) throws SPLException

+	/*public int evaluate(DataCollector dc, Actuator ac, Map instanceMap) throws SPLException

 	{
 		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate2");
 		this.auditloggerString="";
@@ -414,9 +414,134 @@
 		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate2");
 
 		return result;
-	}
+	}*/
 	
-	public String getAuditLogString() {
+	public int evaluate(DataCollector dc, Actuator ac, Map iMap) throws SPLException 
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate2");
+        this.auditloggerString="";
+        if (logger.isLoggable(Level.FINE))
+            logger.fine(Thread.currentThread().getName()+"evaluating policy against instances
cimPolicy");
+        Map instanceMap = new HashMap();
+        Map filteredInstanceMap = _filterUnusedInstances(iMap);
+        // List inputInstanceSymbols = new ArrayList();
+        Iterator instanceDataIterator = filteredInstanceMap.keySet().iterator();
+
+        while(instanceDataIterator.hasNext())
+        {
+            String instanceName = (String)instanceDataIterator.next();
+            Object instance = filteredInstanceMap.get(instanceName);
+            String instanceClassName = instance.getClass().getName();
+            
+
+            if(true/*_instancesPassImportFilter(dc,instanceInfoList)*/) // TBD
+            {
+                InstanceInfo instanceInfo = new InstanceInfo(instanceName,instance);
+                               
+                String qualifier = _symTab.getQualifierForClass(instanceClassName);
+                Map symbolsForInstance = dc.getSymbolsForInstance(instanceClassName,
+                            qualifier,
+                            instance);
+                instanceInfo.setInstanceSymbolsMap(symbolsForInstance);
+                if(instanceMap.containsKey(instanceClassName))
+                {
+                    List instanceInfoList = (List)instanceMap.get(instanceClassName);
+                    instanceInfoList.add(instanceInfo);
+                    
+                }
+                else
+                {
+                    List instanceInfoList = new ArrayList();
+                    instanceInfoList.add(instanceInfo);
+                    instanceMap.put(instanceClassName, instanceInfoList);
+                    
+                }   
+                
+            }
+            else
+            {
+                //instances don't pass import filters
+                break;
+            }
+
+        }
+        int result = POLICY_EVALUATION_FAILED;
+        if(!instanceMap.isEmpty())
+        {
+            if (logger.isLoggable(Level.FINE))
+            {   
+                logger.fine(Thread.currentThread().getName()+
+                        "number of instances passed in for evaluation is "+instanceMap.size());
+            }    
+            System.out.println(">>>>>>>>>>>"+"number of
instances passed in for evaluation is :"+instanceMap.size()+"<<<<<<<<<<<");
+            
+            auditloggerString+=">>>>>>>>>>>"+"number of
instances passed in for evaluation is :"+instanceMap.size()+"<<<<<<<<<<<"+"\n";
+                
+            
+            result = _evaluatePolicies(instanceMap,dc,ac);
+            
+            System.out.println(">>>>>>>>>>>"+"policy evaluation
complete, result :"+result+"<<<<<<<<<<<");
+            auditloggerString+=">>>>>>>>>>>"+"policy evaluation
complete, result :"+result+"<<<<<<<<<<<"+"\n";
+            
+            
+        }
+        else
+        {
+            
+            logger.warning(Thread.currentThread().getName()+" "+"No valid instances for policy
evaluation");
+            //throw new SPLException("Out of the Instances that were passed in for Evaluation,
none have passed the filter");
+        }
+        if (logger.isLoggable(Level.FINE))
+            logger.fine(Thread.currentThread().getName()+"result of evaluation is "+result);
+
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate2");
+
+        return result;
+    }
+    
+	/**
+	 * This method filters out instances passed to the evaluate method
+	 * that are not present in the import statement of the policy
+	 * @param instanceMap
+	 * @return
+	 */
+	private Map _filterUnusedInstances(Map instanceMap)
+    {
+	    Map filteredMap = new HashMap();
+        Iterator instNameIt = instanceMap.keySet().iterator();
+        while(instNameIt.hasNext())
+        {
+            String instanceName = (String)instNameIt.next();
+            Object instance = instanceMap.get(instanceName);
+            String instanceClassName = instance.getClass().getName();
+            Iterator importIt = _importStmtList.iterator();
+            while(importIt.hasNext())
+            {
+                ImportStatement importStmt = (ImportStatement)importIt.next();
+                // check if class of the passed instance has been imported
+                if(importStmt.getAnchorClassName().equals(instanceClassName))
+                {
+                    
+                    List instanceList = importStmt.getImportInstanceInfoList();
+                    Iterator instanceListIt = instanceList.iterator();
+                    // iterate over all the instances of this class to see if 
+                    // there is a match
+                    while(instanceListIt.hasNext())
+                    {
+                        InstanceInfo instanceInfo = (InstanceInfo)instanceListIt.next();
+                        if(instanceInfo.getInstanceName().equals(instanceName))
+                        {
+                            filteredMap.put(instanceName, instance);
+                        }
+                    }
+                }
+                    
+            }
+        }
+        return filteredMap;
+    }
+
+    public String getAuditLogString() {
 		
 		return this.auditloggerString;
 	}



Mime
View raw message