Index: C:/Naidu/Projects/eclipse/june_policy_workspace/apache/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java =================================================================== --- C:/Naidu/Projects/eclipse/june_policy_workspace/apache/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java (revision 669817) +++ C:/Naidu/Projects/eclipse/june_policy_workspace/apache/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/Java_SPLPolicyRuleProvider.java (working copy) @@ -17,16 +17,13 @@ * under the License. */ - /** * @author Prashant Baliga * */ - package org.apache.imperius.javaspl; - import java.util.List; import java.util.Map; @@ -38,120 +35,129 @@ import org.apache.imperius.spl.parser.exceptions.SPLException; import org.apache.imperius.spl.parser.util.InternalClientFactory; +public class Java_SPLPolicyRuleProvider { + private PolicyManager _policyManager = null; + + private static Java_SPLPolicyRuleProvider javaSPLPolicyRuleProvider = null; + + private Java_SPLPolicyRuleProvider() throws SPLException { + initialize(); + } + + public static synchronized Java_SPLPolicyRuleProvider getInstance() throws SPLException { + + if(javaSPLPolicyRuleProvider == null) { + + javaSPLPolicyRuleProvider = new Java_SPLPolicyRuleProvider(); + } + + return javaSPLPolicyRuleProvider; + } +// public Java_SPLPolicyRuleProvider() throws SPLException { +// initialize(); +// } + public void cleanup() throws SPLException { -public class Java_SPLPolicyRuleProvider -{ + } - - private PolicyManager _policyManager= null; - - - public Java_SPLPolicyRuleProvider() throws SPLException - { - initialize(); - - } - - public void cleanup() throws SPLException { - - - - } + public void initialize() throws SPLException { - public void initialize() throws SPLException - { - - - DataCollector dc = new JavaDataCollectorImpl(); - Actuator ac = new JavaActuatorImpl(); - - - _policyManager= new PolicyManagerImpl(dc,ac); - - // registering internal client - InternalClient oInternalClientObj = new InternalClient(_policyManager); - InternalClientFactory.registerInternalClient(oInternalClientObj); - - - } + DataCollector dc = new JavaDataCollectorImpl(); + Actuator ac = new JavaActuatorImpl(); + _policyManager = new PolicyManagerImpl(dc, ac); + // registering internal client + InternalClient oInternalClientObj = new InternalClient(_policyManager); + InternalClientFactory.registerInternalClient(oInternalClientObj); - public boolean createPolicy(String name, String policyString) throws SPLException - { - - boolean result = _policyManager.createPolicy(name,policyString); - - return result; - } - - public boolean validatePolicyString(String policyString) throws SPLException - { - - boolean result = _policyManager.validatePolicyString(policyString); - - return result; - } + } - public void deletePolicy(String name) throws SPLException - { - - _policyManager.deletePolicy(name); - - return; - } + public boolean createPolicy(String name, String policyString) + throws SPLException { - public List enumeratePolicyNames() throws SPLException - { + boolean result = _policyManager.createPolicy(name, policyString); - List policyNames = _policyManager.getAllPolicyNames(); - - return policyNames; - } + return result; + } - public Map enumeratePolicies() throws SPLException - { + public boolean validatePolicyString(String policyString) + throws SPLException { - Map policyInstances = _policyManager.getAllPolicies(); - - return policyInstances; + boolean result = _policyManager.validatePolicyString(policyString); - } + return result; + } - - public String getPolicy(String policyName) throws SPLException - { + public void deletePolicy(String name) throws SPLException { - String policy = _policyManager.getPolicy(policyName); - - return policy; + _policyManager.deletePolicy(name); - } + return; + } - public void modifyPolicy(String name, String policyString) throws SPLException { + public List enumeratePolicyNames() throws SPLException { - - _policyManager.updatePolicy(name,policyString); - + List policyNames = _policyManager.getAllPolicyNames(); - } + return policyNames; + } - public Object executePolicy(String policyName, Map instanceObjectMap) throws SPLException - { - - - Object retVal = _policyManager.evaluatePolicy(policyName,instanceObjectMap); - - - return retVal; - } - - public static void main(String [] args) - { - + public Map enumeratePolicies() throws SPLException { - } + Map policyInstances = _policyManager.getAllPolicies(); + return policyInstances; + + } + + public String getPolicy(String policyName) throws SPLException { + + String policy = _policyManager.getPolicy(policyName); + + return policy; + + } + + public void modifyPolicy(String name, String policyString) + throws SPLException { + + _policyManager.updatePolicy(name, policyString); + + } + + public Object executePolicy(String policyName, Map instanceObjectMap) + throws SPLException { + + Object retVal = _policyManager.evaluatePolicy(policyName, + instanceObjectMap); + + return retVal; + } + + + 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) { + + } + }