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/08/18 12:50:42 UTC
svn commit: r686743 [3/10] - in /incubator/imperius/trunk:
imperius-javaspl/src/main/java/org/apache/imperius/javaspl/
imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/
imperius-splcore/src/main/java/org/apache/imperius/spl/datas...
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=686743&r1=686742&r2=686743&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 Aug 18 05:50:36 2008
@@ -17,7 +17,6 @@
* under the License.
*/
-
/**
* @author Prashant Baliga <pr...@in.ibm.com>
*
@@ -25,486 +24,404 @@
package org.apache.imperius.spl.datastore.impl;
-
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.imperius.spl.datastore.PolicyDataStore;
import org.apache.imperius.spl.datastore.PolicyParser;
import org.apache.imperius.spl.datastore.PolicyRepository;
-import org.apache.imperius.spl.parser.exceptions.InvalidCIMParameterException;
import org.apache.imperius.spl.parser.exceptions.InvalidPolicyParameterException;
import org.apache.imperius.spl.parser.exceptions.PolicyAlreadyExistsInRepositoryException;
import org.apache.imperius.spl.parser.exceptions.PolicyDoesNotExistException;
import org.apache.imperius.spl.parser.exceptions.SPLException;
import org.apache.imperius.spl.parser.statements.impl.PolicyInfo;
import org.apache.imperius.spl.parser.statements.impl.SPLPolicy;
+import org.apache.imperius.util.Messages;
import org.apache.imperius.util.SPLLogger;
-
-public class PolicyDataStoreImpl implements PolicyDataStore
+public class PolicyDataStoreImpl implements PolicyDataStore
{
+ private PolicyCache _policyCache = null;
+ private PolicyParser _policyParser = null;
+ private PolicyRepository _policyRepository = null;
- private PolicyCache _policyCache = null;
-
- private PolicyParser _policyParser = 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();
+
+ 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");
+
+ 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)
+ {
+ logger
+ .fine(Thread.currentThread().getName()
+ + " "
+ + Messages
+ .getString("SPL_CREATED_INTERNAL_POLICY_OBJ_MSG"));
+
+ res = _policyRepository.insertPolicy(policyName, policyString);
+
+ logger
+ .fine(Thread.currentThread().getName()
+ + " "
+ + Messages
+ .getString("SPL_POLICY_INSERTION_INTO_REPOSITORY_MSG"));
+
+ _policyCache.insertPolicy(policyName, internalPolicyObject);
+ }
+ }
+ else
+ {
+ throw new PolicyAlreadyExistsInRepositoryException(Messages
+ .getString("SPL_POLICY_ALREADY_EXISTS_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ return res;
+ }
+
+ public void deletePolicy(String policyName) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "deletePolicy");
+
+ if (policyName != null)
+ {
+ logger.fine(Thread.currentThread().getName() + " "
+ + Messages.getString("SPL_DELETE_POLICY_FROM_CACHE_MSG"));
+
+ // delete Policy from cache
+ _policyCache.deletePolicy(policyName);
+
+ logger
+ .fine(Thread.currentThread().getName()
+ + " "
+ + Messages
+ .getString("SPL_DELETE_POLICY_FROM_REPOSITORY_MSG"));
+
+ // delete policy from Repository
+ if (_policyRepository.policyExists(policyName))
+ {
+ _policyRepository.deletePolicy(policyName);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "deletePolicy");
+ }
+ else
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public Map getAllPolicies() throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicies");
+
+ Map policies = _policyRepository.getAllPolicies();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicies");
+
+ return policies;
+ }
+
+ public List getAllPolicyNames() throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicyNames");
+
+ List policyNames = _policyRepository.getAllPolicyNames();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicyNames");
+
+ return policyNames;
+ }
+
+ public synchronized SPLPolicy getInternalPolicyObject(String policyRuleName)
+ throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getInternalPolicyObject");
+
+ if (policyRuleName != null)
+ {
+ if (_policyCache.policyExists(policyRuleName))
+ {
+ // get policy object from cache if exists
+ SPLPolicy policyObject = _policyCache.getPolicy(policyRuleName);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "getInternalPolicyObject");
+
+ return policyObject;
+ }
+ else if (_policyRepository.policyExists(policyRuleName))
+ {
+ // get policy string from repository
+ String PolicyString = _policyRepository
+ .getPolicyString(policyRuleName);
+
+ // create internal policy object from the policy string
+ SPLPolicy internalPolicyObject = _policyParser
+ .createInternalPolicyObject(policyRuleName,
+ PolicyString);
+
+ // insert the policy into internal cache
+ _policyCache.insertPolicy(policyRuleName, internalPolicyObject);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "getInternalPolicyObject");
+
+ return internalPolicyObject;
+ }
+ else
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ 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
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public void updatePolicy(String policyRuleName, String policyString)
+ throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "updatePolicy");
+
+ if ((policyRuleName != null) && (policyString != null))
+ {
+ if (_policyRepository.policyExists(policyRuleName))
+ {
+ // create internal policy from the policy string
+ SPLPolicy internalPolicyObject = _policyParser.createInternalPolicyObject(policyRuleName, policyString);
+ if (internalPolicyObject != null)
+ {
+ // update the policy repository
+ _policyRepository.updatePolicy(policyRuleName, policyString);
+
+ // update the internal cache with the current policy object
+ if (_policyCache.policyExists(policyRuleName))
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " deleting old Policy Object from cache");
+
+ _policyCache.deletePolicy(policyRuleName);
+ }
+
+ logger.fine(Thread.currentThread().getName()
+ + " adding new Policy Object to cache");
+
+ _policyCache.insertPolicy(policyRuleName, internalPolicyObject);
+
+ logger.exiting(sourceClass, Thread.currentThread()
+ .getName()
+ + " " + "updatePolicy");
+ }
+ }
+ else
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public PolicyInfo getPolicyInfo(String policyRuleName) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getPolicyInfo");
+
+ if (policyRuleName != null)
+ {
+ // check if policy exists in cache
+ if (_policyCache.policyExists(policyRuleName))
+ {
+ SPLPolicy policyObject = _policyCache.getPolicy(policyRuleName);
+ List importStmtList = policyObject.getImportStmtList();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "getPolicyInfo");
+
+ PolicyInfo pi = new PolicyInfo(importStmtList);
+ return pi;
+ }
+ else if (_policyRepository.policyExists(policyRuleName))
+ {
+ String PolicyString = _policyRepository.getPolicyString(policyRuleName);
+
+ SPLPolicy internalPolicyObject = _policyParser.createInternalPolicyObject(policyRuleName, PolicyString);
+ _policyCache.insertPolicy(policyRuleName, internalPolicyObject);
+
+ List importStmtList = internalPolicyObject.getImportStmtList();
+ PolicyInfo pi = new PolicyInfo(importStmtList);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "getPolicyInfo");
+
+ return pi;
+ }
+ else
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public SPLPolicy createSPLPolicyObject(String policyName,
+ String policyString) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "createSPLPolicyObject");
+
+ if ((policyName != null) && (policyString != null))
+ {
+ // check if Policy already exists in Repository
+ SPLPolicy internalPolicyObject = _policyParser
+ .createInternalPolicyObject(policyName, policyString);
+
+ if (internalPolicyObject != null)
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " internal Policy object created successfully");
+
+ return internalPolicyObject;
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ 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=686743&r1=686742&r2=686743&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 Aug 18 05:50:36 2008
@@ -17,7 +17,6 @@
* under the License.
*/
-
/**
* @author Prashant Baliga <pr...@in.ibm.com>
*
@@ -39,191 +38,194 @@
import org.apache.imperius.spl.parser.exceptions.SPLException;
import org.apache.imperius.spl.parser.statements.impl.SPLPolicy;
import org.apache.imperius.spl.parser.util.DataCollectorFactory;
+import org.apache.imperius.util.Messages;
import org.apache.imperius.util.SPLLogger;
+
import antlr.RecognitionException;
import antlr.collections.AST;
-
-public class PolicyParserImpl implements PolicyParser
+public class PolicyParserImpl implements PolicyParser
{
+ private static final String sourceClass = "PolicyParserImpl";
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
- private static final String sourceClass = "PolicyParserImpl";
+ static boolean showTree = false;
- private static Logger logger = null; //SPLLogger.getSPLLogger().getLogger();
+ private static PolicyParserImpl singletonObj = null;
- static boolean showTree = false;
+ private PolicyParserImpl()
+ {
+ init();
+ }
+
+ public void init()
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "init");
+
+ 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");
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "shutDown");
+ }
+
+ public synchronized SPLPolicy createInternalPolicyObject(
+ String policyRuleName, String policyString) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "CreateInternalPolicyObject");
+ StringReader policyStringReader = new StringReader(policyString);
+ SPLPolicy pol = parseFile(policyRuleName, policyStringReader);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "CreateInternalPolicyObject");
+
+ return pol;
+ }
+
+ public boolean validate(String PolicyRuleName, String PolicyString)
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "validate");
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "validate");
+
+ return true;
+ }
+
+ public static SPLPolicy parseFile(String f, Reader r) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "parseFile");
+
+ try
+ {
+ // Create a scanner that reads from the input stream passed to us
+ SPLLexer lexer = new SPLLexer(r);
+ lexer.setFilename(f);
+
+ // Create a parser that reads from the scanner
+ SPLParser parser = new SPLParser(lexer);
+ parser.setASTNodeClass("org.apache.imperius.spl.parser.compiler.ASTWithLineNumber");
+ parser.setFilename(f);
+
+ logger.fine(Thread.currentThread().getName() + " parsing file started...");
+
+ // start parsing at the compilationUnit rule
+ parser.splpolicy();
+
+ if(parser.getErrorList() != null && parser.getErrorList().size() > 0)
+ {
+ throw new SPLException(Messages
+ .getString("SPL_POLICY_PARSING_EXCEPTION_MSG"));
+ }
+
+ logger.fine(Thread.currentThread().getName() + " parsing file completed here...");
+
+ AST t = parser.getAST();
+
+ if (t != null)
+ {
+ traverseTree(t);
+ }
+ else
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0007E);
+ }
+
+ // do something with the tree
+ SPLPolicy pol = doTreeAction(f, parser.getAST(), parser.getTokenNames());
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "parseFile");
+
+ return pol;
+ }
+ catch (Exception e)
+ {
+ logger.severe(e.getMessage());
+ throw new SPLException(e.getMessage());
+ }
+ }
+
+ public static void traverseTree(AST t)
+ {
+
+ }
+
+ 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;
+ }
+
+ SPLTreeParser tparse = new SPLTreeParser();
+ tparse.setASTNodeClass("org.apache.imperius.spl.parser.compiler.ASTWithLineNumber");
+ try
+ {
+ DataCollector dc = DataCollectorFactory.getDataCollector();
+ SPLSymbolTable st = new SPLSymbolTable();
+ SPLPolicy cp = tparse.splpolicy(t, dc, st);
+ if(tparse.getErrorList() != null && tparse.getErrorList().size() > 0)
+ {
+ throw new SPLException(Messages.getString("SPL_POLICY_TREE_PARSING_EXCEPTION_MSG"));
+ }
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "doTreeAction");
+ return cp;
+ }
+ catch (RecognitionException e)
+ {
+ throw new SPLException(e.getMessage());
+ }
+ }
+
+ public boolean validatePolicyString(String policyString)
+ throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "validatePolicyString");
+
+ try
+ {
+ StringReader policyStringReader = new StringReader(policyString);
+ parseFile("validate", policyStringReader);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "CreateInternalPolicyObject");
+
+ return true;
+ }
+ catch (Exception e)
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0006E, new Object[] { e
+ .getMessage() });
+ return false;
+ }
- private static PolicyParserImpl singletonObj = null;
-
- private PolicyParserImpl()
- {
- logger = SPLLogger.getSPLLogger().getLogger();
- init();
- }
-
- public void init()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
-
- 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");
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "shutDown");
-
- }
-
- public synchronized SPLPolicy createInternalPolicyObject(String policyRuleName,
- String policyString) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "
- + "CreateInternalPolicyObject");
- try
- {
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "
- + "CreateInternalPolicyObject");
- StringReader policyStringReader = new StringReader(policyString);
- SPLPolicy pol =parseFile(policyRuleName, policyStringReader);
- return pol;
-
- }
- catch (Exception e)
- {
- e.printStackTrace();
- logger.severe(Thread.currentThread().getName()+" " +
- "Error encountered while parsing PolicyString");
- throw new SPLException("Error encountered while parsing PolicyString");
-
- }
-
- // return cimpolicy;
- }
-
- public boolean validate(String PolicyRuleName, String PolicyString)
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
-
- return true;
- }
-
- public static SPLPolicy parseFile(String f, Reader r) throws Exception
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "parseFile");
-
- try
- {
- // Create a scanner that reads from the input stream passed to us
- SPLLexer lexer = new SPLLexer(r);
- lexer.setFilename(f);
-
- // Create a parser that reads from the scanner
- SPLParser parser = new SPLParser(lexer);
- parser.setASTNodeClass("org.apache.imperius.spl.parser.compiler.ASTWithLineNumber");
- parser.setFilename(f);
- if (logger.isLoggable(Level.FINE))
- logger.fine(Thread.currentThread().getName()+" start parse");
-
- // start parsing at the compilationUnit rule
- parser.splpolicy();
- if (logger.isLoggable(Level.FINE))
- logger.fine(Thread.currentThread().getName()+" parsing complete");
- AST t = parser.getAST();
- if (logger.isLoggable(Level.FINE))
- logger.fine(Thread.currentThread().getName()+" got AST");
- if (t != null)
- {
- traverseTree(t);
- }
- else
- {
- logger.severe(Thread.currentThread().getName()+" "+"No tree produced");
-
- }
-
- // do something with the tree
- SPLPolicy pol = doTreeAction(f, parser.getAST(), parser.getTokenNames());
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "parseFile");
- return pol;
- }
- catch (Exception e)
- {
- logger.severe(e.getMessage());
- e.printStackTrace(); // so we can get stack trace
- throw new SPLException(e.getMessage());
- }
- }
-
- public static void traverseTree(AST t)
- {
-
- }
-
- 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;
- }
-
- SPLTreeParser tparse = new SPLTreeParser();
- tparse.setASTNodeClass("org.apache.imperius.spl.parser.compiler.ASTWithLineNumber");
- try
- {
- DataCollector dc = DataCollectorFactory.getDataCollector();
- SPLSymbolTable st=new SPLSymbolTable();
- SPLPolicy cp = tparse.splpolicy(t, dc, st);
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "doTreeAction");
- return cp;
- }
-
- catch (RecognitionException e)
- {
- logger.severe(e.getMessage());
- e.printStackTrace();
- throw new SPLException(e.getMessage());
- //return null;
- }
-
- }
-
- 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");
-
- return true;
-
- }
- catch (Exception e)
- {
- e.printStackTrace();
- logger.severe(Thread.currentThread().getName()+" " +
- "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=686743&r1=686742&r2=686743&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 Aug 18 05:50:36 2008
@@ -17,7 +17,6 @@
* under the License.
*/
-
/**
* @author Prashant Baliga <pr...@in.ibm.com>
*
@@ -38,359 +37,337 @@
import org.apache.imperius.spl.datastore.PolicyRepository;
import org.apache.imperius.spl.parser.exceptions.*;
+import org.apache.imperius.util.Messages;
import org.apache.imperius.util.SPLLogger;
-
-
-public class PolicyRepositoryImpl implements PolicyRepository
+public class PolicyRepositoryImpl implements PolicyRepository
{
+ 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;
+
+ private PolicyRepositoryImpl()
+ {
+ init();
+ }
+
+ public void init()
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "init");
+
+ _fileName = SPLLogger.SPL_HOME + SPLLogger.fileSeparator + REPOSITORY_FILE_NAME;
+ _readSerializedPolicyStorage();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "init");
+ }
+
+ public static synchronized PolicyRepositoryImpl getInstance()
+ {
+ if (singletonObj == null)
+ {
+ singletonObj = new PolicyRepositoryImpl();
+ }
+ return singletonObj;
+ }
+
+ public void shutdown()
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "shutdown");
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "shutdown");
+ }
+
+ public Map getAllPolicies() throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicies");
+
+ Map allPolicies = new Hashtable();
+ _readSerializedPolicyStorage();
+ Iterator instanceKeySet = _policyMap.keySet().iterator();
+ while (instanceKeySet.hasNext())
+ {
+ String key = (String) instanceKeySet.next();
+ String policyString = (String) _policyMap.get(key);
+ allPolicies.put(key, policyString);
+ }
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicies");
+ return allPolicies;
+ }
+
+ public List getAllPolicyNames() throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicyNames");
+
+ List policyNames = new ArrayList();
+ _readSerializedPolicyStorage();
+ Iterator instanceKeySet = _policyMap.keySet().iterator();
+ while (instanceKeySet.hasNext())
+ {
+ // add all Policy names from policyMap to PolicyNames and return it
+ String policyName = (String) instanceKeySet.next();
+ policyNames.add(policyName);
+ }
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "getAllPolicyNames");
+
+ return policyNames;
+ }
+
+ public void updatePolicy(String policyRuleName, String policyString)
+ throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "updatePolicy");
+
+ _readSerializedPolicyStorage();
+ if (policyRuleName != null && policyString != null)
+ {
+ if (_policyMap.containsKey(policyRuleName))
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " updating policy in repository");
+
+ // updating Repository
+ deletePolicy(policyRuleName);
+ insertPolicy(policyRuleName, policyString);
+ _serializePolicyStorage();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "updatePolicy");
+ }
+ else
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public String getPolicyString(String policyRuleName) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "getPolicyString");
+
+ _readSerializedPolicyStorage();
+ if (policyRuleName != null)
+ {
+ if (_policyMap.containsKey(policyRuleName))
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " return Policy from policyMap");
+
+ // return Policy from policyMap
+ String policy = (String) _policyMap.get(policyRuleName);
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "getPolicy");
+
+ return policy;
+ }
+ else
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public synchronized boolean insertPolicy(String policyRuleName,
+ String policyString) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "insertPolicy");
+
+ _readSerializedPolicyStorage();
+ if (policyRuleName != null && policyString != null)
+ {
+ if (_policyMap.containsKey(policyRuleName))
+ {
+ throw new PolicyAlreadyExistsInRepositoryException(Messages
+ .getString("SPL_POLICY_ALREADY_EXISTS_MSG"));
+ }
+ else
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " add policy to policyMap ");
+
+ // add policy to policyMap
+ _policyMap.put((String) policyRuleName, (String) policyString);
+ _serializePolicyStorage();
+ return true;
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ /**
+ * removes a policy from the Hashtable
+ *
+ * @param PolicyRuleName
+ * @throws SPLException
+ */
+ public void deletePolicy(String policyRuleName) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "deletePolicy");
+
+ _readSerializedPolicyStorage();
+ if (policyRuleName != null)
+ {
+ if (!_policyMap.containsKey(policyRuleName))
+ {
+ throw new PolicyDoesNotExistException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG"));
+ }
+ else
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " removing policy from policyMap");
+
+ // removing policy from policyMap
+ _policyMap.remove(policyRuleName);
+ _serializePolicyStorage();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "deletePolicy");
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ public boolean policyExists(String PolicyRuleName) throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "policyExists");
+
+ _readSerializedPolicyStorage();
+ if (PolicyRuleName != null)
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " check to see if Policy exists in policyMap");
+
+ // check to see if Policy exists in policyMap
+ if (_policyMap.containsKey(PolicyRuleName)) {
+
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "policyExists");
+
+ return true;
+ }
+ else
+ {
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "policyExists");
+ return false;
+ }
+ }
+ else
+ {
+ throw new InvalidPolicyParameterException(Messages
+ .getString("SPL_NULL_POLICY_NAME_EXCEPTION_MSG"));
+ }
+ }
+
+ private synchronized static void _readSerializedPolicyStorage()
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "_readSerializedPolicyStorage");
+
+ FileInputStream fis = null;
+ ObjectInputStream in = null;
+ File file = new File(_fileName);
+ try
+ {
+ 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
+ if (!file.exists()) {
+
+ FileOutputStream fos = new FileOutputStream(file);
+ ObjectOutputStream out = new ObjectOutputStream(fos);
+ out.writeObject(_policyMap);
+ out.close();
+ fos.close();
+ }
+ fis = new FileInputStream(file);
+ in = new ObjectInputStream(fis);
+ _policyMap = (HashMap) in.readObject();
+
+ in.close();
+ fis.close();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "_readSerializedPolicyStorage");
+ }
+ catch (IOException ex)
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0003E);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0004E);
+ }
+ }
+
+ private synchronized static void _serializePolicyStorage()
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "_serializePolicyStorage");
+
+ FileOutputStream fos = null;
+ ObjectOutputStream out = null;
+ File file = new File(_fileName);
+ try
+ {
+ logger.fine(Thread.currentThread().getName()
+ + " serialize an policyMap to File System");
+
+ // serialize an policyMap to File System
+ fos = new FileOutputStream(file);
+ out = new ObjectOutputStream(fos);
+ out.writeObject(_policyMap);
+ out.close();
+ fos.close();
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "_serializePolicyStorage");
+ }
+ catch (IOException ex)
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0005E);
+ }
+ }
- 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;
-
- private PolicyRepositoryImpl()
- {
- init();
- }
-
- public void init()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
- _fileName = SPLLogger.SPL_HOME + SPLLogger.fileSeparator
- + "PolicyStorage.DAT";
-
- _readSerializedPolicyStorage();
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
- }
-
- public static synchronized PolicyRepositoryImpl getInstance()
- {
- if(singletonObj == null)
- {
- singletonObj = new PolicyRepositoryImpl();
- }
- return singletonObj;
- }
-
- public void shutdown()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
- // TODO Auto-generated method stub
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "shutdown");
- }
-
- public Map getAllPolicies() throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicies");
- Map allPolicies = new Hashtable();
- _readSerializedPolicyStorage();
- Iterator instanceKeySet = _policyMap.keySet().iterator();
- while (instanceKeySet.hasNext())
- {
- // to allPolicies and return it
- String key = (String) instanceKeySet.next();
- String policyString = (String)_policyMap.get(key);
- allPolicies.put(key, policyString);
-
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicies");
- return allPolicies;
- }
-
- public List getAllPolicyNames() throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicyNames");
- List policyNames = new ArrayList();
- _readSerializedPolicyStorage();
-
- Iterator instanceKeySet = _policyMap.keySet().iterator();
- while (instanceKeySet.hasNext())
- {
- // add all Policy names from policyMap to PolicyNames and return it
- String policyName = (String) instanceKeySet.next();
- policyNames.add(policyName);
-
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getAllPolicyNames");
- return policyNames;
- }
-
- public void updatePolicy(String policyRuleName, String policyString)
- throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "updatePolicy");
- _readSerializedPolicyStorage();
-
- if (policyRuleName != null && policyString != null)
- {
-
- if (_policyMap.containsKey(policyRuleName))
- {
- if (logger.isLoggable(Level.FINE))
- {
- logger.fine(Thread.currentThread().getName()+" updating Repository");
- }
- // updating Repository
- deletePolicy(policyRuleName);
- insertPolicy(policyRuleName, policyString);
- _serializePolicyStorage();
- 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 String getPolicyString(String policyRuleName) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
- _readSerializedPolicyStorage();
-
- if (policyRuleName != null)
- {
- if (_policyMap.containsKey(policyRuleName))
- {
- if (logger.isLoggable(Level.FINE))
- {
- logger.fine(Thread.currentThread().getName()+
- " return Policy from policyMap");
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPolicy");
- // return Policy from policyMap
- String policy = (String) _policyMap.get(policyRuleName);
- return policy;
- }
- 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 synchronized boolean insertPolicy(String policyRuleName, String policyString)
- throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "insertPolicy");
- _readSerializedPolicyStorage();
-
- if (policyRuleName != null && policyString != null)
- {
-
- if (_policyMap.containsKey(policyRuleName))
- {
- logger.severe(Thread.currentThread().getName()+" "+"The Policy already Exists");
- throw new PolicyAlreadyExistsInRepositoryException(
- "The Policy already Exists");
- }
- else
- {
- if (logger.isLoggable(Level.FINE))
- logger.fine(Thread.currentThread().getName()+" add policy to policyMap ");
- // add policy to policyMap
- _policyMap.put((String) policyRuleName, (String) policyString);
- _serializePolicyStorage();
-
-
-
- return true;
- }
- }
- 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");
- }
- }
-
- /**
- * removes a policy from the Hashtable
- *
- * @param PolicyRuleName
- * @throws CIMException
- */
- public void deletePolicy(String policyRuleName) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "deletePolicy");
- _readSerializedPolicyStorage();
-
- if (policyRuleName != null)
- {
-
- if (!_policyMap.containsKey(policyRuleName))
- {
- logger.severe(Thread.currentThread().getName()+" "+"The Policy does not exist");
- throw new PolicyDoesNotExistException(
- "The Policy does not exist");
- }
- else
- {
- if (logger.isLoggable(Level.FINE))
- {
- logger.fine(Thread.currentThread().getName() +
- " removing policy from policyMap");
- }
- // removing policy from policyMap
- _policyMap.remove(policyRuleName);
- _serializePolicyStorage();
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "deletePolicy");
- }
- }
- 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 boolean policyExists(String PolicyRuleName) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "policyExists");
- _readSerializedPolicyStorage();
-
- 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
-
- if (_policyMap.containsKey(PolicyRuleName))
- {
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "policyExists");
- return true;
- }
-
- else
- {
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "policyExists");
- return false;
- }
-
- }
- 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");
- }
- }
-
-
-
-
-
- synchronized private static void _readSerializedPolicyStorage()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" " +
- "_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
- if (!file.exists())
- {
-
- FileOutputStream fos = new FileOutputStream(file);
- ObjectOutputStream out = new ObjectOutputStream(fos);
- out.writeObject(_policyMap);
- out.close();
- fos.close();
- }
-
- fis = new FileInputStream(file);
- in = new ObjectInputStream(fis);
- _policyMap = (HashMap) in.readObject();
-
- in.close();
- fis.close();
- logger.exiting(sourceClass,Thread.currentThread().getName()+" " +
- "_readSerializedPolicyStorage");
- }
- catch (IOException ex)
- {
- logger.severe(Thread.currentThread().getName()+" " +
- "Error reading serialized policyMap");
- ex.printStackTrace();
- }
- catch (ClassNotFoundException ex)
- {
- logger.severe(Thread.currentThread().getName()+" " +
- "Error reading seralized policyMap Object: class not found");
- ex.printStackTrace();
- }
-
- }
-
- synchronized private static void _serializePolicyStorage()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "_serializePolicyStorage");
- FileOutputStream fos = null;
- ObjectOutputStream out = null;
-
- File file = new File(_fileName);
- try
- {
- if (logger.isLoggable(Level.FINE))
- {
- logger.fine(Thread.currentThread().getName() +
- " serialize an policyMap to File System");
- }
- // serialize an policyMap to File System
-
-
- fos = new FileOutputStream(file);
- out = new ObjectOutputStream(fos);
- out.writeObject(_policyMap);
- out.close();
- fos.close();
- logger.exiting(sourceClass,Thread.currentThread().getName()+" " +
- "_serializePolicyStorage");
- }
- catch (IOException ex)
- {
- logger.severe(Thread.currentThread().getName()+" "+"Error serializing policyMap");
- ex.printStackTrace();
- }
- }
-
-
}
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=686743&r1=686742&r2=686743&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 Aug 18 05:50:36 2008
@@ -17,14 +17,11 @@
* under the License.
*/
-
/**
* @author Prashant Baliga <pr...@in.ibm.com>
*
*/
-
-
package org.apache.imperius.spl.evaluator.impl;
import java.util.Map;
@@ -38,163 +35,120 @@
import org.apache.imperius.spl.parser.statements.impl.SPLPolicy;
import org.apache.imperius.spl.parser.util.ActuatorFactory;
import org.apache.imperius.spl.parser.util.DataCollectorFactory;
+import org.apache.imperius.util.Messages;
import org.apache.imperius.util.SPLLogger;
-
-
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;
+ 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");
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "shutdown");
+ }
+
+ public Object evaluatePolicy(SPLPolicy cp, Map instances)
+ throws SPLException
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "evaluatePolicy");
+ try
+ {
+ int result = FAILURE;
+ if (instances != null)
+ {
+ logger.fine(Thread.currentThread().getName() + " instances passed are not null ");
+
+ if (!instances.isEmpty() && instances.size() > 0)
+ {
+ logger.fine(Thread.currentThread().getName() + " Policy Evaluator calling evaluate method of SPLPolicy");
+
+ result = cp.evaluate(_dataCollector, _actuator, instances);
+
+ auditLogger.fine(Thread.currentThread().getName() + "\n" + cp.getAuditLogString());
+ }
+ else
+ {
+ logger.log(Level.INFO, Messages.getString("SPL_NO_INSTANCES_PASSED_FOR_EVALUATION_MSG"));
+ }
+ }
+ else
+ {
+ throw new SPLException(
+ Messages
+ .getString("SPL_NO_INSTANCES_PASSED_FOR_EVALUATION_MSG"));
+ }
+
+ logger.fine(Thread.currentThread().getName()
+ + " policy evaluation completed");
+
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "evaluatePolicy");
+
+ if (result == SUCCESS)
+ {
+ if (!ReturnObjectStore.hasReturnValues())
+ {
+ return new Integer(1);
+ }
+ else
+ {
+ Object returnObjectList = ReturnObjectStore
+ .getReturnValues();
+
+ return returnObjectList;
+ }
+ }
+ else
+ {
+ return new Integer(FAILURE);
+ }
+ }
+ catch (SPLException e1)
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0008E, new Object[] { e1
+ .getMessage() });
+ }
+ catch (Exception e)
+ {
+ logger.log(Level.SEVERE, Messages.SPLOF0008E, new Object[]{e.getMessage()});
+ }
+ return null;
+ }
}
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=686743&r1=686742&r2=686743&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 Mon Aug 18 05:50:36 2008
@@ -38,126 +38,130 @@
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.util.Messages;
import org.apache.imperius.util.SPLLogger;
+
public class InternalClient
{
- private List inputParams =null;
- 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;
+ private PolicyManager pm = null;
+ private DataCollector dc = null;
+ private static final String sourceClass = "InternalClient";
+
+ public InternalClient( PolicyManager policyManager)
+ {
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "InternalClient");
+ dc = DataCollectorFactory.getDataCollector();
+ pm = policyManager;
-// private static InvokePolicy internalClient=null;
-
- 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 PolicyManager pm=null;
- private DataCollector dc=null;
-// private Actuator ac=null;
- private static final String sourceClass="InternalClient";
-
+ logger.exiting(sourceClass, Thread.currentThread().getName() + " "
+ + "InternalClient");
+ }
public int invokePolicy(String policyName, Map instanceMap)
{
- int returnValue = 0;
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+"InvokePolicy");
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "InvokePolicy");
+
+ int returnValue = 0;
try
{
PolicyInfo policyInfo = pm.getPolicyInfo(policyName);
if(policyInfo == null)
{
- throw new SPLException("policy with this name "+policyName+" is not found in repository");
+ throw new SPLException(Messages
+ .getString("SPL_POLICY_DOES_NOT_EXIST_EXCEPTION_MSG")
+ + " " + policyName);
}
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");
+ logger.fine(Thread.currentThread().getName()
+ + " evaluating policy...");
+
+ Integer retVal = (Integer) pm.evaluatePolicy(policyName,instanceMap);
+
+ logger.fine(Thread.currentThread().getName()
+ + " policy evaluation completed successfully");
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);
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "invokePolicy");
}
return 0;
}
catch(SPLException e)
{
- logger.severe(e.getMessage());
+ logger.log(Level.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");
-
+ logger.exiting(sourceClass, Thread.currentThread().getName()
+ + " " + "invokePolicy");
return -1;
}
public int invokePolicy(String policyName, List paramList, boolean boo)
{
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+"InvokePolicy");
- int returnValue=0;
- List objectrefList=paramList;
-
+ logger.entering(sourceClass, Thread.currentThread().getName() + " "
+ + "InvokePolicy");
+
+ int returnValue = 0;
+ List objectrefList = paramList;
try
{
- if(objectrefList==null )
+ 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());
+ Map objectMap = new HashMap();
+ PolicyInfo policyInfo = pm.getPolicyInfo(policyName);
+ Map classQuaifierMap = policyInfo.getClassQualifierMap();
+ Iterator classit = classQuaifierMap.keySet().iterator();
-
- if(classQuaifierMap.size()==0 || classQuaifierMap.size()>1)
+ 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();
+ String className = (String) classit.next();
+ String nameSpace = (String) classQuaifierMap.get(className);
+ List instanceList = dc.enumerateInstanceNames(className, nameSpace);
+ Object instanceObj = null;
+ Iterator it = instanceList.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);
+ instanceObj = (Object) it.next();
+ String objectName = className;
+ InstanceInfo iI = new InstanceInfo(objectName, instanceObj);
+ List instanceInfoList = new ArrayList();
+ instanceInfoList.add(iI);
+ objectMap.put(objectName, instanceInfoList);
+ Integer retVal = (Integer) pm.evaluatePolicy(
+ policyName, objectMap);
- 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.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);
+ logger.severe("POLICY_EVALUATION_FAILED "+policyName+" "+instanceObj.toString()+" "+retVal);
returnValue++;
}
else
{
- logger.severe("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+copI.toString()+" "+retVal);
-
+ logger.severe("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+instanceObj.toString()+" "+retVal);
}
- if(logger.isLoggable(Level.FINE))
- logger.fine(Thread.currentThread().getName()+" Internal client return value="+returnValue);
+
+ logger.fine(Thread.currentThread().getName()+" Internal client return value="+returnValue);
objectMap.remove(instanceInfoList);
-
}
logger.fine("internal client finished iterating over all instances ");
break;
@@ -165,11 +169,11 @@
}
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)
@@ -178,28 +182,21 @@
}
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.fine(Thread.currentThread().getName()+" return value is = "+retVal);
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokeMethod");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"InvokePolicy");
if (retVal.intValue() ==POLICY_EVALUATION_FAILED )
{
@@ -211,60 +208,28 @@
logger.fine("POLICY_EVALUATION_SUCCESSFUL "+policyName+" "+copI.toString()+" "+retVal);
}
- if(logger.isLoggable(Level.FINE))
- logger.fine(Thread.currentThread().getName()+" Internal client return value="+returnValue);
+ 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;
-
}
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");
-
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"InvokePolicy");
+ logger.fine(Thread.currentThread().getName()+" Internal client return value is -1");
+
return -1;
}
- private InternalClient()
- {
-
-
- }
-
-
-
public Object clone() throws CloneNotSupportedException
{
throw new CloneNotSupportedException();
}
-
- public InternalClient( PolicyManager policyManager) {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+"init");
-
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
-
-
- dc=DataCollectorFactory.getDataCollector();
- pm=policyManager;
-
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"init");
-
-
- }
-
}