From 2410d8844182e057fd59ea4139b9a7d61413bbea Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 8 Jul 2008 23:10:31 +0000 Subject: Make the ServiceDiscovery pluggable and add support for OSGi-based service discoverer git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@675040 13f79535-47bb-0310-9956-ffa450edef68 --- .../util/PolicyHandlerDefinitionsLoader.java | 17 +++----- .../sca/policy/util/PolicyHandlerTuple.java | 32 ++++++++++---- .../sca/policy/util/PolicyHandlerUtils.java | 50 +++++++++------------- 3 files changed, 49 insertions(+), 50 deletions(-) (limited to 'java/sca/modules/policy/src/main') diff --git a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java index 14736aa34f..3a37ed3c41 100644 --- a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java +++ b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java @@ -38,7 +38,7 @@ import org.apache.tuscany.sca.extensibility.ServiceDiscovery; */ public class PolicyHandlerDefinitionsLoader { - public static Map> loadPolicyHandlerClassnames() { + public static List loadPolicyHandlerClassnames() { // Get the processor service declarations Set sds; try { @@ -47,15 +47,10 @@ public class PolicyHandlerDefinitionsLoader { throw new IllegalStateException(e); } - Map> handlerTuples = new Hashtable>(); + List handlerTupleList = new ArrayList(); + + Map> handlerTuples = new Hashtable>(); for (ServiceDeclaration sd : sds) { - ClassLoader cl = sd.getClassLoader(); - - List handlerTupleList = handlerTuples.get(cl); - if ( handlerTupleList == null ) { - handlerTupleList = new ArrayList(); - handlerTuples.put(cl, handlerTupleList); - } Map attributes = sd.getAttributes(); String intentName = attributes.get("intent"); QName intentQName = getQName(intentName); @@ -64,10 +59,10 @@ public class PolicyHandlerDefinitionsLoader { if ( appliesTo != null && !appliesTo.startsWith("/") ) { appliesTo = "//" + appliesTo; } - handlerTupleList.add(new PolicyHandlerTuple(sd.getClassName(), intentQName, policyModelClassName, appliesTo)); + handlerTupleList.add(new PolicyHandlerTuple(sd, sd.getClassName(), intentQName, policyModelClassName, appliesTo)); } - return handlerTuples; + return handlerTupleList; } private static QName getQName(String qname) { diff --git a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java index 10a67383bf..84ffe3ef29 100644 --- a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java +++ b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java @@ -21,34 +21,48 @@ package org.apache.tuscany.sca.policy.util; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; + /** * PolicyHanlder tuples stored in policy handler services files * * @version $Rev$ $Date$ */ public class PolicyHandlerTuple { + private ServiceDeclaration declaration; private String policyHandlerClassName; private QName providedIntentName; private String policyModelClassName; private String appliesTo; - - public String getAppliesTo() { - return appliesTo; - } - public void setAppliesTo(String appliesTo) { - this.appliesTo = appliesTo; - } - - public PolicyHandlerTuple(String handlerClassName, + public PolicyHandlerTuple(ServiceDeclaration declaration, + String handlerClassName, QName providedIntentName, String policyModelClassName, String appliesTo) { + this.declaration = declaration; this.policyHandlerClassName = handlerClassName; this.providedIntentName = providedIntentName; this.policyModelClassName = policyModelClassName; this.appliesTo = appliesTo; } + + public ServiceDeclaration getDeclaration() { + return declaration; + } + + public void setDeclaration(ServiceDeclaration declaration) { + this.declaration = declaration; + } + + public String getAppliesTo() { + return appliesTo; + } + + public void setAppliesTo(String appliesTo) { + this.appliesTo = appliesTo; + } + public String getPolicyHandlerClassName() { return policyHandlerClassName; diff --git a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java index d399cce17f..f2977d63bf 100644 --- a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java +++ b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.policy.util; import java.util.List; -import java.util.Map; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicySet; @@ -31,43 +30,34 @@ import org.apache.tuscany.sca.policy.PolicySet; * @version $Rev$ $Date$ */ public class PolicyHandlerUtils { - public static PolicyHandler findPolicyHandler(PolicySet policySet, - Map> policyHandlerClassNames) - throws IllegalAccessException, ClassNotFoundException, InstantiationException { - + public static PolicyHandler findPolicyHandler(PolicySet policySet, List policyHandlerClassNames) + throws IllegalAccessException, ClassNotFoundException, InstantiationException { + PolicyHandler handler = null; - - for (ClassLoader classLoader : policyHandlerClassNames.keySet()) { - for ( PolicyHandlerTuple handlerTuple : policyHandlerClassNames.get(classLoader) ) { - //System.out.println(handlerTuple); - for ( Intent intent : policySet.getProvidedIntents() ) { - if ( intent.getName().equals(handlerTuple.getProvidedIntentName())) { - for ( Object policy : policySet.getPolicies() ) { - if ( policy.getClass().getName().equals(handlerTuple.getPolicyModelClassName())) { - if ( handlerTuple.getAppliesTo() != null ) { - if ( handlerTuple.getAppliesTo().equals(policySet.getAppliesTo() )) { - handler = - (PolicyHandler)Class.forName(handlerTuple.getPolicyHandlerClassName(), - true, - classLoader).newInstance(); - handler.setApplicablePolicySet(policySet); - return handler; - } - } else { - handler = - (PolicyHandler)Class.forName(handlerTuple.getPolicyHandlerClassName(), - true, - classLoader).newInstance(); - handler.setApplicablePolicySet(policySet); - return handler; + + for (PolicyHandlerTuple handlerTuple : policyHandlerClassNames) { + //System.out.println(handlerTuple); + for (Intent intent : policySet.getProvidedIntents()) { + if (intent.getName().equals(handlerTuple.getProvidedIntentName())) { + for (Object policy : policySet.getPolicies()) { + if (policy.getClass().getName().equals(handlerTuple.getPolicyModelClassName())) { + if (handlerTuple.getAppliesTo() != null) { + if (handlerTuple.getAppliesTo().equals(policySet.getAppliesTo())) { + handler = (PolicyHandler)handlerTuple.getDeclaration().loadClass().newInstance(); + handler.setApplicablePolicySet(policySet); + return handler; } + } else { + handler = (PolicyHandler)handlerTuple.getDeclaration().loadClass().newInstance(); + handler.setApplicablePolicySet(policySet); + return handler; } } } } } } - + return handler; } -- cgit v1.2.3