You are viewing a plain text version of this content. The canonical link for it is here.
Posted to imperius-commits@incubator.apache.org by jn...@apache.org on 2008/07/21 14:26:14 UTC

svn commit: r678437 - in /incubator/imperius/trunk: imperius-javaspl/src/main/java/org/apache/imperius/javaspl/ imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/ imperius-splcore/src/main/java/org/apache/imperius/spl/evaluator/impl...

Author: jneeraj
Date: Mon Jul 21 07:26:14 2008
New Revision: 678437

URL: http://svn.apache.org/viewvc?rev=678437&view=rev
Log:
Commited changes for IMPERIUS-11 and IMPERIUS-12 - Thread safe controls and API refactoring by Naidu J

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/datastore/impl/PolicyCache.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyDataStoreImpl.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyRepositoryImpl.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/evaluator/impl/PolicyEvaluatorImpl.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/windowscomputersystem/WindowsSystemManager.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=678437&r1=678436&r2=678437&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 Mon Jul 21 07:26:14 2008
@@ -17,16 +17,13 @@
  * under the License.  
  */
 
-
 /**
  * @author Prashant Baliga <pr...@in.ibm.com>
  *
  */
 
-
 package org.apache.imperius.javaspl;
 
-
 import java.util.List;
 import java.util.Map;
 
@@ -38,119 +35,128 @@
 import org.apache.imperius.spl.parser.exceptions.SPLException;
 import org.apache.imperius.spl.parser.util.InternalClientFactory;
 
+public class Java_SPLPolicyRuleProvider {
 
-
-
-
-public class Java_SPLPolicyRuleProvider 
-{
-
-    
-    private PolicyManager _policyManager= null;
+    private PolicyManager _policyManager = null;
     
+    private static Java_SPLPolicyRuleProvider javaSPLPolicyRuleProvider = null;
     
-    public Java_SPLPolicyRuleProvider() throws SPLException
-    {
+    private Java_SPLPolicyRuleProvider() throws SPLException {
         initialize();
-        
     }
     
-    public void cleanup() throws SPLException {
-        
+    public static synchronized Java_SPLPolicyRuleProvider getInstance() throws SPLException {
         
+        if(javaSPLPolicyRuleProvider == null) {
+            
+            javaSPLPolicyRuleProvider = new Java_SPLPolicyRuleProvider();
+        }
         
+        return javaSPLPolicyRuleProvider;
     }
 
-    public void initialize() throws SPLException
-    {
-     
-        
+//  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);
-        
+        _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);
 
-    public boolean createPolicy(String name, String policyString) throws SPLException 
-    {
-        
-        boolean result = _policyManager.createPolicy(name,policyString);
-       
         return result;
     }
-    
-    public boolean validatePolicyString(String policyString) throws SPLException 
-    {
-        
+
+    public boolean validatePolicyString(String policyString)
+            throws SPLException {
+
         boolean result = _policyManager.validatePolicyString(policyString);
-       
+
         return result;
     }
 
-    public void deletePolicy(String name) throws SPLException 
-    {
-        
+    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;
     }
 
-    public Map enumeratePolicies() throws SPLException 
-    {
+    public Map enumeratePolicies() throws SPLException {
 
         Map policyInstances = _policyManager.getAllPolicies();
-        
+
         return policyInstances;
 
     }
 
-    
-    public String getPolicy(String policyName) throws SPLException 
-    {
+    public String getPolicy(String policyName) throws SPLException {
 
         String policy = _policyManager.getPolicy(policyName);
-        
+
         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 
-    {
-     
-        
-        Object retVal = _policyManager.evaluatePolicy(policyName,instanceObjectMap);
-    
-        
+    public Object executePolicy(String policyName, Map instanceObjectMap)
+            throws SPLException {
+
+        Object retVal = _policyManager.evaluatePolicy(policyName,
+                instanceObjectMap);
+
         return retVal;
     }
     
-    public static void main(String [] args)
-    {
-        
+    
+    public boolean isPolicyExists(String policyName) {
+        boolean returnFlag = false;
+        try
+        {
+            List policyNamesList = _policyManager.getAllPolicyNames();
+            if(policyNamesList != null && policyNamesList.size() > 0)
+            {
+                if(policyNamesList.contains(policyName)) {
+                    returnFlag = true;
+                }
+            }
+        } catch(SPLException splex) {
+            
+        }
+        return returnFlag;
+    }
+    
+
+    public static void main(String[] args) {
 
     }
 

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyCache.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyCache.java?rev=678437&r1=678436&r2=678437&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyCache.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyCache.java Mon Jul 21 07:26:14 2008
@@ -34,78 +34,83 @@
 
 public class PolicyCache 
 {
-	private Map _policyCache = new Hashtable();
-	
-	public boolean policyExists(String policyName)
-	{
-		if (!_policyCache.containsKey(policyName))
-        {
-			return false;
-        }
-		return true;
-		
-		
-	}
-	
-	public boolean insertPolicy(String policyName, SPLPolicy policyObject)
-	{
-		if (!policyExists(policyName))
+    private Map _policyCache = new Hashtable();
+    private static PolicyCache singletonObj = null;
+
+    private PolicyCache()
+    {
+        
+    }
+    
+    public static synchronized PolicyCache getInstance()
+    {
+        if(singletonObj == null)
+        {
+            singletonObj = new PolicyCache();
+        }
+        return singletonObj;
+    }
+    
+    public boolean policyExists(String policyName)
+    {
+        if (!_policyCache.containsKey(policyName))
+        {
+            return false;
+        }
+        return true;
+    }
+    
+    public synchronized boolean insertPolicy(String policyName, SPLPolicy policyObject)
+    {
+        if (!policyExists(policyName))
         {
-            
             _policyCache.put(policyName,policyObject);
             return true;
-            
         }
         else
         {
-        	return false;
-            
+            return false;
+        }
+    }
+    
+    public boolean updatePolicy(String policyName, SPLPolicy policyObject)
+        throws SPLException
+    {
+        if(policyExists(policyName))
+        {
+            _policyCache.remove(policyName);
+            _policyCache.put(policyName, policyObject);
+            return true;
+        }
+        else
+        {
+            throw new SPLException("policy does not exist in cache");
         }
-    	
-	}
-	public boolean updatePolicy(String policyName, SPLPolicy policyObject)
-		throws SPLException
-	{
-		if(policyExists(policyName))
-		{
-			_policyCache.remove(policyName);
-			_policyCache.put(policyName, policyObject);
-			return true;
-		}
-		else
-		{
-			throw new SPLException("policy does not exist in cache");
-		}
-		
-	}
-	public boolean deletePolicy(String policyName) throws SPLException
-	{
-		if(policyExists(policyName))
-		{
-			_policyCache.remove(policyName);
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-		
-		
-	}
-	public SPLPolicy getPolicy(String policyName) throws SPLException
-	{
-		if(policyExists(policyName))
-		{
-			SPLPolicy pol = (SPLPolicy)_policyCache.get(policyName);
-			return pol;
-		}
-		else
-		{
-			throw new SPLException("policy does not exist in cache");
-		}
-		
-	}
-	
-	
+    }
 
+    public synchronized boolean deletePolicy(String policyName) throws SPLException
+    {
+        if(policyExists(policyName))
+        {
+            _policyCache.remove(policyName);
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    public synchronized SPLPolicy getPolicy(String policyName) throws SPLException
+    {
+        if(policyExists(policyName))
+        {
+            SPLPolicy pol = (SPLPolicy)_policyCache.get(policyName);
+            return pol;
+        }
+        else
+        {
+            throw new SPLException("policy does not exist in cache");
+        }
+    }
 }

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyDataStoreImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyDataStoreImpl.java?rev=678437&r1=678436&r2=678437&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyDataStoreImpl.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyDataStoreImpl.java Mon Jul 21 07:26:14 2008
@@ -49,454 +49,462 @@
 
 
 
-	private PolicyCache _policyCache = null;
+    private PolicyCache _policyCache = null;
 
-	private PolicyParser _policyParser = null;
+    private PolicyParser _policyParser = null;
 
-	private PolicyRepository _policyRepository = null;
+    private PolicyRepository _policyRepository = null;
 
+    private static final String sourceClass = "PolicyDataStoreImpl";
 
-	private static final String sourceClass = "PolicyDataStoreImpl";
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+    private static PolicyDataStoreImpl singletonObj = null;
+    
+    private PolicyDataStoreImpl()
+    {
+        init();
+    }
+
+    public void init()
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
+
+        _policyCache = PolicyCache.getInstance();
+        _policyRepository = PolicyRepositoryImpl.getInstance();
+        _policyParser = PolicyParserImpl.getInstance();
+    
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
+    }
+    
+    public static synchronized PolicyDataStoreImpl getInstance()
+    {
+        if(singletonObj == null)
+        {
+            singletonObj = new PolicyDataStoreImpl();
+        }
+        return singletonObj;
+    }
+
+    public void shutdown()
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
+        _policyParser.shutDown();
+        _policyRepository.shutdown();
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
+    }
+
+    public boolean createPolicy(String policyName, String policyString) 
+    throws SPLException
+    {
+
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createPolicy");
+        // check to see if class name and namespace are valid
+        boolean res = false;
+
+        if ((policyName != null) && (policyString != null))
+        {
+            // check if Policy already exists in Repository
+            if (!_policyRepository.policyExists(policyName))
+            {
+                SPLPolicy internalPolicyObject = 
+                    _policyParser.createInternalPolicyObject(policyName,policyString);
+
+                if (internalPolicyObject != null)
+                {
+                    if (logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " created internal SPLPolicy");
+                    }    
+                    // create CIMObjectPath that is to be returned
+                    res = _policyRepository.insertPolicy(
+                            policyName, policyString);
+                    if (logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " inserted Policy into PolicyRepository");
+                    }    
+                    
+                    _policyCache.insertPolicy(policyName,internalPolicyObject);
+                    
+
+                }
+
+            }
+            else
+            {
+                logger
+                .severe(Thread.currentThread().getName() +" " +
+                        "Cannot create new Policy asPolicy already exists . Try updating.");
+                throw new PolicyAlreadyExistsInRepositoryException(
+                "Cannot create new Policy asPolicy already exists");
+            }
+        }
+        else
+        {
+            logger.severe(Thread.currentThread().getName()+" " + 
+            "Policy Parameter is null");
+            throw new InvalidPolicyParameterException( "Policy Parameter is null");
+        }
+
+
+
+
+        return res;
+    }
+
+    public void deletePolicy(String policyName)
+    throws SPLException
+    {
+        // logger.entry("deletePolicy");
+
+        // check to see if they r null
+        // check if it already exists
+        // put in a utility to check a cim object
+
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "deletePolicy");
+
+        // get name of Policy to be deleted
+
+        if (policyName != null)
+        {
+            //_readSerializedCimPolicyStorage();
+            if (logger.isLoggable(Level.FINE))
+            {   
+                logger.fine(Thread.currentThread().getName() + 
+                        " Deleting Policy Object from cache");
+            }    
+            // delete Policy from cache
+            _policyCache.deletePolicy(policyName);
+
+            if (logger.isLoggable(Level.FINE))
+            {   
+                logger.fine(Thread.currentThread().getName() + 
+                        " Deleting Policy from policyRepository");
+            }    
+            // delete policy from Repository
+            if (_policyRepository.policyExists(policyName))
+            {
+                _policyRepository.deletePolicy(policyName);
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "deletePolicy");
+            }
+            else
+            {
+                logger.severe(Thread.currentThread().getName()+" " + 
+                "The Policy cannot be deleted as it does not exist in the Repository");
+                throw new PolicyDoesNotExistException(
+                "The Policy cannot be deleted as it does not exist in the Repository");
+            }
+        }
+        else
+        {
+            logger.severe(Thread.currentThread().getName()+" " + 
+            "The Policy cannot be found due to Invalid Policy Parameters");
+            throw new InvalidPolicyParameterException(
+            "The Policy cannot be found due to Invalid Policy Parameters");
+        }
+
+    }
+
+    public Map getAllPolicies()
+    throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicies");
+
+        // enumerating Policies from policyRepository
+        if (logger.isLoggable(Level.FINE))
+            logger.fine(Thread.currentThread().getName() + 
+                    " enumerating Policies from policyRepository");
+        // USE equalscase instead
+
+        Map policies = _policyRepository.getAllPolicies();
+
+        return policies;
+
+
+
+    }
+
+    public List getAllPolicyNames() throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicyNames");
+        List policyNames = _policyRepository.getAllPolicyNames(); 
+
+        return policyNames;
+
+    }
+
+    public synchronized SPLPolicy getInternalPolicyObject(String policyRuleName)
+            throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ 
+        "getInternalPolicyObject");
+        if (policyRuleName != null)
+        {
+            //_readSerializedCimPolicyStorage();
+            // get Policy object from Cache
+            if (logger.isLoggable(Level.FINE))
+                logger.fine(Thread.currentThread().getName()+" get Policy object from Cache");
+
+            if (_policyCache.policyExists(policyRuleName))
+            {
+                SPLPolicy policyObject = _policyCache.getPolicy(policyRuleName);
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" " +
+                        "getInternalPolicyObject");
+                return policyObject;
+            }
+            // get Policy from Repository,cache it and then return the Policy
+            // Object
+
+            else if (_policyRepository.policyExists(policyRuleName))
+            {
+                if (logger.isLoggable(Level.FINE))
+                {   
+                    logger.fine(Thread.currentThread().getName() + 
+                            " get Policy from Repository,cache it and then return the Policy Object");
+                }    
+                String PolicyString = _policyRepository.getPolicyString(policyRuleName);
+                SPLPolicy internalPolicyObject = 
+                    _policyParser.createInternalPolicyObject(policyRuleName,PolicyString);
+                _policyCache.insertPolicy(policyRuleName, internalPolicyObject);
+                //_serializeCimPolicyStorage();
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" " 
+                        + "getInternalPolicyObject");
+                return internalPolicyObject;
+            }
+            else
+            {
+                logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
+                throw new PolicyDoesNotExistException(
+                "The Policy does not exist");
+            }
+        }
+        else
+        {
+            logger
+            .severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+            throw new InvalidCIMParameterException(
+            "This CIM class is not handled by the Policy Provider");
+        }
+
+    }
+
+    public String getPolicy(String policyRuleName)
+    throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
+
+
+        if (policyRuleName != null)
+        {
+            // check to see if Policy exists, if so then return it
+            if (_policyRepository.policyExists(policyRuleName))
+            {
+                String policyString = _policyRepository.getPolicyString(policyRuleName);
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
+                return policyString;
+            }
+            else
+            {
+                logger.severe(Thread.currentThread().getName()+" " + 
+                "The Policy does not exist");
+                throw new PolicyDoesNotExistException(
+                "The Policy does not exist");
+            }
+        }
+        else
+        {
+            logger
+            .severe(Thread.currentThread().getName()+" " + 
+                    "The Policy cannot be found due to Invalid Policy Parameters");
+            throw new InvalidPolicyParameterException(
+            "The Policy cannot be found due to Invalid Policy Parameters");
+        }
+
+
+    }
+
+
+
+    public void updatePolicy(String policyRuleName, String policyString) throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "updatePolicy");
+
+        if ((policyRuleName != null) && (policyString != null))
+        {
+            //_readSerializedCimPolicyStorage();
+
+            // NEED TO CHECK FOR PRESENCE IN CACHE, DELETE IF ONE EXISTS
+            if (_policyRepository.policyExists(policyRuleName))
+            {
+                if (logger.isLoggable(Level.FINE))
+                {   
+                    logger.fine(Thread.currentThread().getName()  + 
+                            " Updating Policy in Repository");
+                }    
+                SPLPolicy internalPolicyObject = 
+                    _policyParser.createInternalPolicyObject(policyRuleName,policyString);
+                // CALL CREATEINTERNALPOLICYOBJECT validate is for future
+                // use
+                if (internalPolicyObject != null)
+                {
+                    _policyRepository.updatePolicy(policyRuleName,
+                            policyString);
+                    if (_policyCache.policyExists(policyRuleName))
+                    {
+                        _policyCache.deletePolicy(policyRuleName);
+                        //_serializeCimPolicyStorage();
+                        if (logger.isLoggable(Level.FINE))
+                        {   
+                            logger.fine(Thread.currentThread().getName() +
+                                    " Removing old Policy Object from cache");
+                        }    
+                    }
+                    if (logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " Adding new Policy Object to cache");
+                    }    
+                    _policyCache.insertPolicy(policyRuleName, internalPolicyObject);
+                    //_serializeCimPolicyStorage();
+
+                    logger.exiting(sourceClass,Thread.currentThread().getName() + 
+                            " "+ "updatePolicy");
+                }
+            }
+            else
+            {
+                logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
+                throw new PolicyDoesNotExistException("The Policy does not exist");
+            }
+        }
+        else
+        {
+            logger
+            .severe(Thread.currentThread().getName()+" "+ 
+                    "The Policy cannot be found due to Invalid Policy Parameters");
+            throw new InvalidPolicyParameterException(
+            "The Policy cannot be found due to Invalid Policy Parameters");
+        }
+
+
+
+    }
+
+    public PolicyInfo getPolicyInfo(String policyRuleName) throws SPLException {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ 
+        "getInternalPolicyObject");
+        
+        if (policyRuleName != null)
+        {
+            
+            if (logger.isLoggable(Level.FINE))
+                logger.fine(Thread.currentThread().getName()+" get Policy object from Cache");
+
+        
+            if (_policyCache.policyExists(policyRuleName))
+            {
+        
+                
+                SPLPolicy policyObject = _policyCache.getPolicy(policyRuleName);
+                List importStmtList=policyObject.getImportStmtList();
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" " +"getInternalPolicyObject");
+                PolicyInfo pi=new PolicyInfo( importStmtList);
+        
+                return pi;
+            }
+            // get Policy from Repository,cache it and then return the Policy
+            // Object
+
+            else if (_policyRepository.policyExists(policyRuleName))
+            {
+            
+                if (logger.isLoggable(Level.FINE))
+                {   
+                    logger.fine(Thread.currentThread().getName() + 
+                            " get Policy from Repository,cache it and then return the Policy Object");
+                }    
+                String PolicyString = _policyRepository.getPolicyString(policyRuleName);
+                
+                SPLPolicy internalPolicyObject = 
+                    _policyParser.createInternalPolicyObject(policyRuleName,PolicyString);
+                
+                _policyCache.insertPolicy(policyRuleName, internalPolicyObject);
+                
+
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" " 
+                        + "getInternalPolicyObject");
+                List importStmtList=internalPolicyObject.getImportStmtList();
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" " +"getInternalPolicyObject");
+                PolicyInfo pi=new PolicyInfo( importStmtList);
+                return pi;
+            }
+            else
+            {
+
+            
+                logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
+                throw new PolicyDoesNotExistException(
+                "The Policy does not exist");
+            }
+        }
+        else
+        {
+
+            logger.severe(Thread.currentThread().getName()+" "+"policy name is null");
+            throw new InvalidCIMParameterException("policy name is null");
+        }
+
+    }
+
+    
+    public SPLPolicy createSPLPolicyObject(String policyName, String policyString) 
+    throws SPLException
+    {
+
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createPolicy");
+        // check to see if class name and name space are valid
+        
+        if ((policyName != null) && (policyString != null))
+        {
+            // check if Policy already exists in Repository
+                SPLPolicy internalPolicyObject = 
+                    _policyParser.createInternalPolicyObject(policyName,policyString);
+
+                if (internalPolicyObject != null)
+                {
+                    if (logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " created internal SPLPolicy");
+                    }    
+                    // create CIMObjectPath that is to be returned
+                    return internalPolicyObject;
+                }
+
+            
+        }
+        else
+        {
+            logger.severe(Thread.currentThread().getName()+" " + 
+            "Policy Parameter is null");
+            throw new InvalidPolicyParameterException( "Policy Parameter is null");
+        }
+
+
+
+
+        return null;
+    }
+
+    public boolean validatePolicyString(String policyString) throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName() + " " + "validatePolicyString");
+        boolean pi=this._policyParser.validatePolicyString(policyString);
+        logger.exiting(sourceClass,Thread.currentThread().getName() + " " + "validatePolicyString");
 
-	private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-
-	public PolicyDataStoreImpl()
-	{
-
-		init();
-	}
-
-	public void init()
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
-
-		_policyCache = new PolicyCache();
-		_policyRepository = new PolicyRepositoryImpl();
-		_policyParser = new PolicyParserImpl();
-	
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
-	}
-
-
-	public void shutdown()
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
-		_policyParser.shutDown();
-		_policyRepository.shutdown();
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
-	}
-
-	public boolean createPolicy(String policyName, String policyString) 
-	throws SPLException
-	{
-
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createPolicy");
-		// check to see if class name and namespace are valid
-		boolean res = false;
-
-		if ((policyName != null) && (policyString != null))
-		{
-			// check if Policy already exists in Repository
-			if (!_policyRepository.policyExists(policyName))
-			{
-				SPLPolicy internalPolicyObject = 
-					_policyParser.createInternalPolicyObject(policyName,policyString);
-
-				if (internalPolicyObject != null)
-				{
-					if (logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" created internal SPLPolicy");
-					}    
-					// create CIMObjectPath that is to be returned
-					res = _policyRepository.insertPolicy(
-							policyName, policyString);
-					if (logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" inserted Policy into PolicyRepository");
-					}    
-					
-					_policyCache.insertPolicy(policyName,internalPolicyObject);
-					
-
-				}
-
-			}
-			else
-			{
-				logger
-				.severe(Thread.currentThread().getName() +" " +
-						"Cannot create new Policy asPolicy already exists . Try updating.");
-				throw new PolicyAlreadyExistsInRepositoryException(
-				"Cannot create new Policy asPolicy already exists");
-			}
-		}
-		else
-		{
-			logger.severe(Thread.currentThread().getName()+" " + 
-			"Policy Parameter is null");
-			throw new InvalidPolicyParameterException( "Policy Parameter is null");
-		}
-
-
-
-
-		return res;
-	}
-
-	public void deletePolicy(String policyName)
-	throws SPLException
-	{
-		// logger.entry("deletePolicy");
-
-		// check to see if they r null
-		// check if it already exists
-		// put in a utility to check a cim object
-
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "deletePolicy");
-
-		// get name of Policy to be deleted
-
-		if (policyName != null)
-		{
-			//_readSerializedCimPolicyStorage();
-			if (logger.isLoggable(Level.FINE))
-			{	
-				logger.fine(Thread.currentThread().getName() + 
-						" Deleting Policy Object from cache");
-			}    
-			// delete Policy from cache
-			_policyCache.deletePolicy(policyName);
-
-			if (logger.isLoggable(Level.FINE))
-			{	
-				logger.fine(Thread.currentThread().getName() + 
-						" Deleting Policy from policyRepository");
-			}    
-			// delete policy from Repository
-			if (_policyRepository.policyExists(policyName))
-			{
-				_policyRepository.deletePolicy(policyName);
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "deletePolicy");
-			}
-			else
-			{
-				logger.severe(Thread.currentThread().getName()+" " + 
-				"The Policy cannot be deleted as it does not exist in the Repository");
-				throw new PolicyDoesNotExistException(
-				"The Policy cannot be deleted as it does not exist in the Repository");
-			}
-		}
-		else
-		{
-			logger.severe(Thread.currentThread().getName()+" " + 
-			"The Policy cannot be found due to Invalid Policy Parameters");
-			throw new InvalidPolicyParameterException(
-			"The Policy cannot be found due to Invalid Policy Parameters");
-		}
-
-	}
-
-	public Map getAllPolicies()
-	throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicies");
-
-		// enumerating Policies from policyRepository
-		if (logger.isLoggable(Level.FINE))
-			logger.fine(Thread.currentThread().getName() + 
-					" enumerating Policies from policyRepository");
-		// USE equalscase instead
-
-		Map policies = _policyRepository.getAllPolicies();
-
-		return policies;
-
-
-
-	}
-
-	public List getAllPolicyNames() throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicyNames");
-		List policyNames = _policyRepository.getAllPolicyNames(); 
-
-		return policyNames;
-
-	}
-
-	public SPLPolicy getInternalPolicyObject(String policyRuleName)
-	throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ 
-		"getInternalPolicyObject");
-		if (policyRuleName != null)
-		{
-			//_readSerializedCimPolicyStorage();
-			// get Policy object from Cache
-			if (logger.isLoggable(Level.FINE))
-				logger.fine(Thread.currentThread().getName()+" get Policy object from Cache");
-
-			if (_policyCache.policyExists(policyRuleName))
-			{
-				SPLPolicy policyObject = _policyCache.getPolicy(policyRuleName);
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" " +
-						"getInternalPolicyObject");
-				return policyObject;
-			}
-			// get Policy from Repository,cache it and then return the Policy
-			// Object
-
-			else if (_policyRepository.policyExists(policyRuleName))
-			{
-				if (logger.isLoggable(Level.FINE))
-				{	
-					logger.fine(Thread.currentThread().getName() + 
-							" get Policy from Repository,cache it and then return the Policy Object");
-				}    
-				String PolicyString = _policyRepository.getPolicyString(policyRuleName);
-				SPLPolicy internalPolicyObject = 
-					_policyParser.createInternalPolicyObject(policyRuleName,PolicyString);
-				_policyCache.insertPolicy(policyRuleName, internalPolicyObject);
-				//_serializeCimPolicyStorage();
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" " 
-						+ "getInternalPolicyObject");
-				return internalPolicyObject;
-			}
-			else
-			{
-				logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
-				throw new PolicyDoesNotExistException(
-				"The Policy does not exist");
-			}
-		}
-		else
-		{
-			logger
-			.severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
-			throw new InvalidCIMParameterException(
-			"This CIM class is not handled by the Policy Provider");
-		}
-
-	}
-
-	public String getPolicy(String policyRuleName)
-	throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
-
-
-		if (policyRuleName != null)
-		{
-			// check to see if Policy exists, if so then return it
-			if (_policyRepository.policyExists(policyRuleName))
-			{
-				String policyString = _policyRepository.getPolicyString(policyRuleName);
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
-				return policyString;
-			}
-			else
-			{
-				logger.severe(Thread.currentThread().getName()+" " + 
-				"The Policy does not exist");
-				throw new PolicyDoesNotExistException(
-				"The Policy does not exist");
-			}
-		}
-		else
-		{
-			logger
-			.severe(Thread.currentThread().getName()+" " + 
-					"The Policy cannot be found due to Invalid Policy Parameters");
-			throw new InvalidPolicyParameterException(
-			"The Policy cannot be found due to Invalid Policy Parameters");
-		}
-
-
-	}
-
-
-
-	public void updatePolicy(String policyRuleName, String policyString) throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "updatePolicy");
-
-		if ((policyRuleName != null) && (policyString != null))
-		{
-			//_readSerializedCimPolicyStorage();
-
-			// NEED TO CHECK FOR PRESENCE IN CACHE, DELETE IF ONE EXISTS
-			if (_policyRepository.policyExists(policyRuleName))
-			{
-				if (logger.isLoggable(Level.FINE))
-				{	
-					logger.fine(Thread.currentThread().getName()  + 
-							" Updating Policy in Repository");
-				}    
-				SPLPolicy internalPolicyObject = 
-					_policyParser.createInternalPolicyObject(policyRuleName,policyString);
-				// CALL CREATEINTERNALPOLICYOBJECT validate is for future
-				// use
-				if (internalPolicyObject != null)
-				{
-					_policyRepository.updatePolicy(policyRuleName,
-							policyString);
-					if (_policyCache.policyExists(policyRuleName))
-					{
-						_policyCache.deletePolicy(policyRuleName);
-						//_serializeCimPolicyStorage();
-						if (logger.isLoggable(Level.FINE))
-						{	
-							logger.fine(Thread.currentThread().getName() +
-									" Removing old Policy Object from cache");
-						}    
-					}
-					if (logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" Adding new Policy Object to cache");
-					}    
-					_policyCache.insertPolicy(policyRuleName, internalPolicyObject);
-					//_serializeCimPolicyStorage();
-
-					logger.exiting(sourceClass,Thread.currentThread().getName() + 
-							" "+ "updatePolicy");
-				}
-			}
-			else
-			{
-				logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
-				throw new PolicyDoesNotExistException("The Policy does not exist");
-			}
-		}
-		else
-		{
-			logger
-			.severe(Thread.currentThread().getName()+" "+ 
-					"The Policy cannot be found due to Invalid Policy Parameters");
-			throw new InvalidPolicyParameterException(
-			"The Policy cannot be found due to Invalid Policy Parameters");
-		}
-
-
-
-	}
-
-	public PolicyInfo getPolicyInfo(String policyRuleName) throws SPLException {
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ 
-		"getInternalPolicyObject");
-		
-		if (policyRuleName != null)
-		{
-			
-			if (logger.isLoggable(Level.FINE))
-				logger.fine(Thread.currentThread().getName()+" get Policy object from Cache");
-
-		
-			if (_policyCache.policyExists(policyRuleName))
-			{
-		
-				
-				SPLPolicy policyObject = _policyCache.getPolicy(policyRuleName);
-				List importStmtList=policyObject.getImportStmtList();
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" " +"getInternalPolicyObject");
-				PolicyInfo pi=new PolicyInfo( importStmtList);
-		
-				return pi;
-			}
-			// get Policy from Repository,cache it and then return the Policy
-			// Object
-
-			else if (_policyRepository.policyExists(policyRuleName))
-			{
-			
-				if (logger.isLoggable(Level.FINE))
-				{	
-					logger.fine(Thread.currentThread().getName() + 
-							" get Policy from Repository,cache it and then return the Policy Object");
-				}    
-				String PolicyString = _policyRepository.getPolicyString(policyRuleName);
-				
-				SPLPolicy internalPolicyObject = 
-					_policyParser.createInternalPolicyObject(policyRuleName,PolicyString);
-				
-				_policyCache.insertPolicy(policyRuleName, internalPolicyObject);
-				
-
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" " 
-						+ "getInternalPolicyObject");
-				List importStmtList=internalPolicyObject.getImportStmtList();
-				logger.exiting(sourceClass,Thread.currentThread().getName()+" " +"getInternalPolicyObject");
-				PolicyInfo pi=new PolicyInfo( importStmtList);
-				return pi;
-			}
-			else
-			{
-
-			
-				logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
-				throw new PolicyDoesNotExistException(
-				"The Policy does not exist");
-			}
-		}
-		else
-		{
-
-			logger.severe(Thread.currentThread().getName()+" "+"policy name is null");
-			throw new InvalidCIMParameterException("policy name is null");
-		}
-
-	}
-
-	
-	public SPLPolicy createSPLPolicyObject(String policyName, String policyString) 
-	throws SPLException
-	{
-
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createPolicy");
-		// check to see if class name and name space are valid
-		
-		if ((policyName != null) && (policyString != null))
-		{
-			// check if Policy already exists in Repository
-				SPLPolicy internalPolicyObject = 
-					_policyParser.createInternalPolicyObject(policyName,policyString);
-
-				if (internalPolicyObject != null)
-				{
-					if (logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" created internal SPLPolicy");
-					}    
-					// create CIMObjectPath that is to be returned
-					return internalPolicyObject;
-				}
-
-			
-		}
-		else
-		{
-			logger.severe(Thread.currentThread().getName()+" " + 
-			"Policy Parameter is null");
-			throw new InvalidPolicyParameterException( "Policy Parameter is null");
-		}
-
-
-
-
-		return null;
-	}
-
-	public boolean validatePolicyString(String policyString) throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName() + " " + "validatePolicyString");
-		boolean pi=this._policyParser.validatePolicyString(policyString);
-		logger.exiting(sourceClass,Thread.currentThread().getName() + " " + "validatePolicyString");
-
-		return pi;
-	}
+        return pi;
+    }
 
 }

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java?rev=678437&r1=678436&r2=678437&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java Mon Jul 21 07:26:14 2008
@@ -55,12 +55,12 @@
 
     static boolean showTree = false;
 
+    private static PolicyParserImpl singletonObj = null;
         
-    public PolicyParserImpl()
+    private PolicyParserImpl()
     {
-    	//System.out.println("in policyparserimpl ctor");
-    	logger = SPLLogger.getSPLLogger().getLogger();
-    	init();
+        logger = SPLLogger.getSPLLogger().getLogger();
+        init();
     }
 
     public void init() 
@@ -70,7 +70,16 @@
         logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
 
     }
-
+    
+    public static synchronized PolicyParserImpl getInstance()
+    {
+        if(singletonObj == null)
+        {
+            singletonObj = new PolicyParserImpl();
+        }
+        return singletonObj;
+    }
+    
     public void shutDown()
     {
         logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "shutDown");
@@ -78,15 +87,15 @@
 
     }
 
-    public SPLPolicy createInternalPolicyObject(String policyRuleName,
+    public synchronized SPLPolicy createInternalPolicyObject(String policyRuleName,
             String policyString) throws SPLException
     {
         logger.entering(sourceClass,Thread.currentThread().getName()+" "
-        		+ "CreateInternalPolicyObject");
+                + "CreateInternalPolicyObject");
         try
         {
             logger.exiting(sourceClass,Thread.currentThread().getName()+" " 
-            		+ "CreateInternalPolicyObject");
+                    + "CreateInternalPolicyObject");
             StringReader policyStringReader = new StringReader(policyString);
             SPLPolicy pol =parseFile(policyRuleName, policyStringReader); 
             return pol;
@@ -96,7 +105,7 @@
         {
             e.printStackTrace();
             logger.severe(Thread.currentThread().getName()+" " + 
-            		"Error encountered while parsing PolicyString");
+                    "Error encountered while parsing PolicyString");
             throw new SPLException("Error encountered while parsing PolicyString");
 
         }
@@ -164,12 +173,12 @@
 
     }
 
-    public static SPLPolicy doTreeAction(String f, AST t, String[] tokenNames) throws SPLException
+    public static synchronized SPLPolicy doTreeAction(String f, AST t, String[] tokenNames) throws SPLException
     {
         logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "doTreeAction");
   
         if (t == null)
-        {	
+        {   
             return null;
         }    
        
@@ -194,15 +203,15 @@
 
     }
     
-	public boolean validatePolicyString(String policyString) throws SPLException
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName() + " " + "validatePolicyString");
-		try
+    public boolean validatePolicyString(String policyString) throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName() + " " + "validatePolicyString");
+        try
         {
             StringReader policyStringReader = new StringReader(policyString);
             SPLPolicy pol =parseFile("validate",policyStringReader); 
             logger.exiting(sourceClass,Thread.currentThread().getName()+" " 
-            		+ "CreateInternalPolicyObject");
+                    + "CreateInternalPolicyObject");
             
             return true;
 
@@ -211,10 +220,10 @@
         {
             e.printStackTrace();
             logger.severe(Thread.currentThread().getName()+" " + 
-            		"Error encountered while parsing PolicyString "+e.getMessage());
+                    "Error encountered while parsing PolicyString "+e.getMessage());
             return false;
         }
-		
-		
-	}
+        
+        
+    }
 }

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyRepositoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyRepositoryImpl.java?rev=678437&r1=678436&r2=678437&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyRepositoryImpl.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyRepositoryImpl.java Mon Jul 21 07:26:14 2008
@@ -46,18 +46,14 @@
 {
 
     private static HashMap _policyMap = new HashMap();
-
-  
     private static String _fileName = null;
-
-
     private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-
     private static final String sourceClass = "PolicyRepositoryImpl";
+    private static PolicyRepositoryImpl singletonObj = null;
     
-    PolicyRepositoryImpl()
+    private PolicyRepositoryImpl()
     {
-    	init();
+        init();
     }
 
     public void init() 
@@ -69,6 +65,15 @@
         _readSerializedPolicyStorage();
         logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
     }
+    
+    public static synchronized PolicyRepositoryImpl getInstance()
+    {
+        if(singletonObj == null)
+        {
+            singletonObj = new PolicyRepositoryImpl();
+        }
+        return singletonObj;
+    }
 
     public void shutdown()
     {
@@ -125,7 +130,7 @@
             if (_policyMap.containsKey(policyRuleName))
             {
                 if (logger.isLoggable(Level.FINE))
-                {	
+                {   
                     logger.fine(Thread.currentThread().getName()+" updating Repository");
                 }    
                 // updating Repository
@@ -144,7 +149,7 @@
         else
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-            		"The Policy cannot be found due to Invalid Policy Parameters");
+                    "The Policy cannot be found due to Invalid Policy Parameters");
             throw new InvalidPolicyParameterException(
                     "The Policy cannot be found due to Invalid Policy Parameters");
         }
@@ -160,9 +165,9 @@
             if (_policyMap.containsKey(policyRuleName))
             {
                 if (logger.isLoggable(Level.FINE))
-                {	
+                {   
                     logger.fine(Thread.currentThread().getName()+ 
-                    		" return Policy from policyMap");
+                            " return Policy from policyMap");
                 }    
                 logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
                 // return Policy from policyMap
@@ -179,13 +184,13 @@
         else
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-                    		"The Policy cannot be found due to Invalid Policy Parameters");
+                            "The Policy cannot be found due to Invalid Policy Parameters");
             throw new InvalidPolicyParameterException(
                     "The Policy cannot be found due to Invalid Policy Parameters");
         }
     }
 
-    public boolean insertPolicy(String policyRuleName, String policyString)
+    public synchronized boolean insertPolicy(String policyRuleName, String policyString)
             throws SPLException
     {
         logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "insertPolicy");
@@ -216,7 +221,7 @@
         else
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-            		"The Policy cannot be found due to Invalid Policy Parameters");
+                    "The Policy cannot be found due to Invalid Policy Parameters");
             throw new InvalidPolicyParameterException(
                     "The Policy cannot be found due to Invalid Policy Parameters");
         }
@@ -245,9 +250,9 @@
             else
             {
                 if (logger.isLoggable(Level.FINE))
-                {	
+                {   
                     logger.fine(Thread.currentThread().getName() + 
-                    		" removing policy from policyMap");
+                            " removing policy from policyMap");
                 }    
                 // removing policy from policyMap
                 _policyMap.remove(policyRuleName);
@@ -258,7 +263,7 @@
         else
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-                    		"The Policy cannot be found due to Invalid Policy Parameters");
+                            "The Policy cannot be found due to Invalid Policy Parameters");
             throw new InvalidPolicyParameterException(
                     "The Policy cannot be found due to Invalid Policy Parameters");
         }
@@ -272,9 +277,9 @@
         if (PolicyRuleName != null)
         {
             if (logger.isLoggable(Level.FINE))
-            {	
+            {   
                 logger.fine(Thread.currentThread().getName()+ 
-                		" check to see if Policy exists in policyMap");
+                        " check to see if Policy exists in policyMap");
             }    
             // check to see if Policy exists in policyMap
             
@@ -294,7 +299,7 @@
         else
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-                    		"The Policy cannot be found due to Invalid Policy Parameters");
+                            "The Policy cannot be found due to Invalid Policy Parameters");
             throw new InvalidPolicyParameterException(
                     "The Policy cannot be found due to Invalid Policy Parameters");
         }
@@ -307,17 +312,17 @@
     synchronized private static void _readSerializedPolicyStorage()
     {
         logger.entering(sourceClass,Thread.currentThread().getName()+" " +
-        		"_readSerializedPolicyStorage");
+                "_readSerializedPolicyStorage");
         FileInputStream fis = null;
         ObjectInputStream in = null;
         File file = new File(_fileName);
         try
         {
             if (logger.isLoggable(Level.FINE))
-            {	
+            {   
                 logger.fine(Thread.currentThread().getName() + 
-                		" read from the serialized file if it exists, else create" +
-                		"it and serialize an empty policyMap to it");
+                        " read from the serialized file if it exists, else create" +
+                        "it and serialize an empty policyMap to it");
             }    
             // read from the serialized file if it exists, else create it and
             // serialize an empty policyMap to it
@@ -338,18 +343,18 @@
             in.close();
             fis.close();
             logger.exiting(sourceClass,Thread.currentThread().getName()+" " + 
-            		"_readSerializedPolicyStorage");
+                    "_readSerializedPolicyStorage");
         }
         catch (IOException ex)
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-            		"Error reading serialized policyMap");
+                    "Error reading serialized policyMap");
             ex.printStackTrace();
         }
         catch (ClassNotFoundException ex)
         {
             logger.severe(Thread.currentThread().getName()+" " + 
-                    		"Error reading seralized policyMap Object: class not found");
+                            "Error reading seralized policyMap Object: class not found");
             ex.printStackTrace();
         }
 
@@ -365,9 +370,9 @@
         try
         {
             if (logger.isLoggable(Level.FINE))
-            {	
+            {   
                 logger.fine(Thread.currentThread().getName() + 
-                		" serialize an policyMap to File System");
+                        " serialize an policyMap to File System");
             }    
             // serialize an policyMap to File System
 
@@ -378,7 +383,7 @@
             out.close();
             fos.close();
             logger.exiting(sourceClass,Thread.currentThread().getName()+" " +
-            		"_serializePolicyStorage");
+                    "_serializePolicyStorage");
         }
         catch (IOException ex)
         {
@@ -387,5 +392,5 @@
         }
     }
 
-	
+    
 }

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/evaluator/impl/PolicyEvaluatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/evaluator/impl/PolicyEvaluatorImpl.java?rev=678437&r1=678436&r2=678437&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/evaluator/impl/PolicyEvaluatorImpl.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/evaluator/impl/PolicyEvaluatorImpl.java Mon Jul 21 07:26:14 2008
@@ -44,150 +44,157 @@
 
 public class PolicyEvaluatorImpl implements PolicyEvaluator 
 {
+    private static final String sourceClass = "PolicyEvaluatorImpl";
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+    private static Logger auditLogger = SPLLogger.getSPLLogger()
+            .getAuditLogger();
+    private DataCollector _dataCollector;
+    private Actuator _actuator;
+    public static final int SUCCESS = 1;
+    public static final int FAILURE = -1;
+    public static final int NOT_EVALUATED = 0;
+    private static PolicyEvaluatorImpl singletonObj = null;
+
+    private PolicyEvaluatorImpl() 
+    {
+        init();
+    }
+
+    public void init() 
+    {
+        logger.entering(sourceClass, Thread.currentThread().getName() + " "
+                + "init");
+
+        _dataCollector = DataCollectorFactory.getDataCollector();
+        _actuator = ActuatorFactory.getActuator();
+
+        logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+                + "init");
+    }
+
+    public static PolicyEvaluatorImpl getInstance() 
+    {
+        if (singletonObj == null)
+            singletonObj = new PolicyEvaluatorImpl();
+        return singletonObj;
+    }
+    
+    public void shutdown() 
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
+        //PolicyLogger.log("PolicyEvaluatorImpl::shutdown");
+        // TODO Auto-generated method stub
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
+
+    }
+
+    public Object evaluatePolicy(SPLPolicy cp, Map instances) throws SPLException 
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluatePolicy");
+        try
+        {   
+            //testing out actual datacollector
+
+            if(logger.isLoggable(Level.FINE))
+            {   
+                logger.fine(Thread.currentThread().getName()+
+                " Policy Evaluator calling evaluate method of SPLPolicy");
+            }   
+            int result= FAILURE;
+            if(instances != null)
+            {
+
+                if(logger.isLoggable(Level.FINE))
+                {   
+                    logger.fine(Thread.currentThread().getName()+" copList!=null ");
+                }    
+                if(!instances.isEmpty() && instances.size()>0)
+                {
+                    if(logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " evaluating policy against instances");
+                    }    
+                    result = cp.evaluate(_dataCollector,_actuator,instances); 
+                    if(auditLogger.isLoggable(Level.FINE))
+                    {   
+                        auditLogger.fine(Thread.currentThread().getName() + "\n"+ 
+                                cp.getAuditLogString());
+                    }
+                    if(logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " policy evaluation result = "+result);
+                    } 
+                }
+                else
+                {
+                    if(logger.isLoggable(Level.FINE))
+                    {   
+                        logger.fine(Thread.currentThread().getName() + 
+                                " copList!=null but size="+instances.size()+" "+instances.toString());
+                    }    
+                }
+            }
+            else
+            {
+
+                if(logger.isLoggable(Level.FINE))
+                {   
+                    logger.fine(Thread.currentThread().getName()+" copList=null");
+                }    
+                throw new SPLException("Zero instances passed for evaluation");
+
+
+            }
+
+            if(logger.isLoggable(Level.FINE))
+            {   
+                logger.fine(Thread.currentThread().getName() + 
+                        " PolicyEvaluator is done evaluating, result : "+result);
+            }   
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluatePolicy");
+            if(logger.isLoggable(Level.FINE))
+            {   
+                logger.fine(Thread.currentThread().getName()+" returned 1 to client");
+            }   
+            if(result==SUCCESS)
+            {
+
+                if(!ReturnObjectStore.hasReturnValues())
+                {   
+                    return new Integer(1);
+                }
+                else
+                {
+                    Object returnObjectList = ReturnObjectStore.getReturnValues();
+
+                    return returnObjectList;
+                }
+            }
+            else
+            {
+
+
+
+                return new Integer(FAILURE);
+            }
+
+        }
+        catch (SPLException e) 
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            return null;
+        }
+        catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            return null;
+        }
 
-	private static final String sourceClass="PolicyEvaluatorImpl";
-	private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-	private static Logger auditLogger = SPLLogger.getSPLLogger().getAuditLogger();
-	
-	private DataCollector _dataCollector;
-	private Actuator _actuator;
-
-	public static final int SUCCESS = 1;
-	public static final int FAILURE = -1;
-	public static final int NOT_EVALUATED = 0;
-
-	public PolicyEvaluatorImpl()
-	{
-		init();
-	}
-
-	public void init() 
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
-		_dataCollector = DataCollectorFactory.getDataCollector();
-
-		_actuator = ActuatorFactory.getActuator();
-
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
-
-	}
-
-	public void shutdown() 
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
-		//PolicyLogger.log("PolicyEvaluatorImpl::shutdown");
-		// TODO Auto-generated method stub
-		logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
-
-	}
-
-	public Object evaluatePolicy(SPLPolicy cp, Map instances) throws SPLException 
-	{
-		logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluatePolicy");
-		try
-		{	
-			//testing out actual datacollector
-
-			if(logger.isLoggable(Level.FINE))
-			{	
-				logger.fine(Thread.currentThread().getName()+
-				" Policy Evaluator calling evaluate method of SPLPolicy");
-			}	
-			int result= FAILURE;
-			if(instances != null)
-			{
-
-				if(logger.isLoggable(Level.FINE))
-				{	
-					logger.fine(Thread.currentThread().getName()+" copList!=null ");
-				}    
-				if(!instances.isEmpty() && instances.size()>0)
-				{
-					if(logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" evaluating policy against instances");
-					}    
-					result = cp.evaluate(_dataCollector,_actuator,instances); 
-					if(auditLogger.isLoggable(Level.FINE))
-					{	
-						auditLogger.fine(Thread.currentThread().getName() + "\n"+ 
-								cp.getAuditLogString());
-					}
-					if(logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" policy evaluation result = "+result);
-					} 
-				}
-				else
-				{
-					if(logger.isLoggable(Level.FINE))
-					{	
-						logger.fine(Thread.currentThread().getName() + 
-								" copList!=null but size="+instances.size()+" "+instances.toString());
-					}    
-				}
-			}
-			else
-			{
-
-				if(logger.isLoggable(Level.FINE))
-				{	
-					logger.fine(Thread.currentThread().getName()+" copList=null");
-				}    
-				throw new SPLException("Zero instances passed for evaluation");
-
-
-			}
-
-			if(logger.isLoggable(Level.FINE))
-			{	
-				logger.fine(Thread.currentThread().getName() + 
-						" PolicyEvaluator is done evaluating, result : "+result);
-			}	
-			logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluatePolicy");
-			if(logger.isLoggable(Level.FINE))
-			{	
-				logger.fine(Thread.currentThread().getName()+" returned 1 to client");
-			}	
-			if(result==SUCCESS)
-			{
-
-				if(!ReturnObjectStore.hasReturnValues())
-				{	
-					return new Integer(1);
-				}
-				else
-				{
-					Object returnObjectList = ReturnObjectStore.getReturnValues();
-
-					return returnObjectList;
-				}
-			}
-			else
-			{
-
-
-
-				return new Integer(FAILURE);
-			}
-
-		}
-		catch (SPLException e) 
-		{
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			return null;
-		}
-		catch (Exception e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			return null;
-		}
+    }
 
-	}
-
-	
+    
 
 }

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=678437&r1=678436&r2=678437&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 Mon Jul 21 07:26:14 2008
@@ -53,7 +53,7 @@
         try 
         {
             
-            Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider();
+            Java_SPLPolicyRuleProvider jspl = Java_SPLPolicyRuleProvider.getInstance();
             String aFile = policyFolder + policyName + ".spl";
             //System.out.println("starting test");
             StringBuffer contents = new StringBuffer();

Modified: incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java?rev=678437&r1=678436&r2=678437&view=diff
==============================================================================
--- incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java (original)
+++ incubator/imperius/trunk/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java Mon Jul 21 07:26:14 2008
@@ -40,77 +40,77 @@
 
 public class WindowsSystemManager 
 {
-	
-	public static void main(String[] args) throws IOException, SPLException
-	{
-				
-		WindowsComputerSystem system1=new WindowsComputerSystem();
-		String policyToExecute = "Java_FileSystem";	
-		
-		try 
-		{
-			if(args.length == 1)
-			{
-				policyToExecute = args[0];
-			}
-			Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider();
-			String aFile = "policies/" + policyToExecute + ".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(policyToExecute);
-		    }
-		    catch(Exception e)
-		    {
-		    	
-		    }
-		    
-		    boolean createReturn=jspl.createPolicy(policyToExecute, contents.toString());
-		    System.out.println("Policy Created : " + policyToExecute +createReturn);
-		    System.out.println("");
-		    
-		    Map objMap = new Hashtable();
-		    
-		   /* List instanceInfoList = new ArrayList();
-		    
-		    InstanceInfo ii1 = new InstanceInfo("system1",system1);
-		    instanceInfoList.add(ii1);	    
-	    
-		    objMap.put("org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsComputerSystem", instanceInfoList);*/
-		    objMap.put("system1", system1);
-		    
-		      
-		    Object result = jspl.executePolicy(policyToExecute, objMap);
-		   System.out.println("Result is " + result);
-			
-		} 
-		catch (SPLException e) 
-		{
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
+    
+    public static void main(String[] args) throws IOException, SPLException
+    {
+                
+        WindowsComputerSystem system1=new WindowsComputerSystem();
+        String policyToExecute = "Java_FileSystem"; 
+        
+        try 
+        {
+            if(args.length == 1)
+            {
+                policyToExecute = args[0];
+            }
+            Java_SPLPolicyRuleProvider jspl = Java_SPLPolicyRuleProvider.getInstance();
+            String aFile = "policies/" + policyToExecute + ".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(policyToExecute);
+            }
+            catch(Exception e)
+            {
+                
+            }
+            
+            boolean createReturn=jspl.createPolicy(policyToExecute, contents.toString());
+            System.out.println("Policy Created : " + policyToExecute +createReturn);
+            System.out.println("");
+            
+            Map objMap = new Hashtable();
+            
+           /* List instanceInfoList = new ArrayList();
+            
+            InstanceInfo ii1 = new InstanceInfo("system1",system1);
+            instanceInfoList.add(ii1);      
+        
+            objMap.put("org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsComputerSystem", instanceInfoList);*/
+            objMap.put("system1", system1);
+            
+              
+            Object result = jspl.executePolicy(policyToExecute, objMap);
+           System.out.println("Result is " + result);
+            
+        } 
+        catch (SPLException e) 
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
 
 
 }