summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-06-23 13:05:00 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-06-23 13:05:00 +0000
commite9fc3c9cf81db2869a9d2e5a0b3f08a89829508a (patch)
tree01c3374fbadea3ef4c6f79e1d3f41ca2511114cb /sca-java-2.x/trunk/modules
parent4f538657ed8baff04cdf01adff8db3c7e82aa3b9 (diff)
TUSCANY-3873 - A stop gap solution to running the appliesTo algorithm against a matched endpoint reference. Waiting on the discussion from TUSCANY-3877 before producing the full solution.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1138864 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java87
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java24
3 files changed, 103 insertions, 9 deletions
diff --git a/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF
index 30e639f3f9..230b5b3736 100644
--- a/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF
@@ -19,6 +19,7 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.assembly.xsd;version="2.0.0",
org.apache.tuscany.sca.common.xml.dom;version="2.0.0",
org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
+ org.apache.tuscany.sca.context;version="2.0.0",
org.apache.tuscany.sca.contribution.processor;version="2.0.0",
org.apache.tuscany.sca.contribution.resolver;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.core;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
index 158c27e98b..60b82b99f4 100644
--- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
+++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
@@ -39,10 +39,13 @@ import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.builder.BuilderContext;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.definitions.Definitions;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -50,7 +53,7 @@ import org.w3c.dom.NodeList;
/**
* A builder that checks that policy sets apply to the elements to which they are attached.
* Any that don't are removed. It first creates a DOM model for the composite so that the xpath
- * expression can be evaluated. For each element that holds a policy set is calculates the
+ * expression can be evaluated. For each element that holds a policy set it calculates the
* appliesTo nodes and checks that the current element is in the set. If not the policySet is
* removed from the element
*
@@ -66,6 +69,7 @@ public class PolicyAppliesToBuilderImpl extends PolicyAttachmentBuilderImpl {
return "org.apache.tuscany.sca.policy.builder.PolicyAppliesToBuilder";
}
+ // Build the whole composite
public Composite build(Composite composite, BuilderContext context)
throws CompositeBuilderException {
try {
@@ -90,6 +94,74 @@ public class PolicyAppliesToBuilderImpl extends PolicyAttachmentBuilderImpl {
}
}
+ // Build just an endpoint reference that has just been matched against an endpoint. This
+ // can often happen at runtime so the policy attachTo for a reference policy cannot
+ // be assessed at build time
+ // THIS DOESN'T HANDLE THE NESTED COMPOSITE CASE
+ public void build(EndpointReference epr) throws CompositeBuilderException {
+ try {
+
+ // What we really need to be doing here is...
+ //
+ // - correct the composite model to add the service binding to the reference
+ // - turn the composite model into a DOM
+ // - apply the reference policy XPath and assess whether it appliesTo the binding
+ //
+ // I've had a go at making the code do that below. However there is some question
+ // about what the appliesTo field means and it's hard to get here from the
+ // binder so until we sort out the appliesTo question this code isn't used
+
+ CompositeContext compositeContext = ((RuntimeComponent)epr.getComponent()).getComponentContext().getCompositeContext();
+ Composite domainComposite = compositeContext.getDomainComposite();
+ Definitions systemDefinitions = compositeContext.getSystemDefinitions();
+
+ if (systemDefinitions == null ||
+ (systemDefinitions.getPolicySets().isEmpty() &&
+ systemDefinitions.getExternalAttachments().isEmpty()) ) {
+ return;
+ }
+
+ // temporarily add the endpoint binding to the reference model so that the
+ // XPath expression can be evaluated correctly
+ epr.getReference().getBindings().add(epr.getTargetEndpoint().getBinding());
+
+ // create a DOM for the Domain Composite Infoset
+ Document document = saveAsDOM(domainComposite);
+
+ // remove the binding again to retain the untainted model
+ epr.getReference().getBindings().remove(epr.getTargetEndpoint().getBinding());
+
+ // create a cache of evaluated node against each policy set so we don't
+ // have to keep evaluating policy sets that appear in multiple places
+ Map<PolicySet, List<PolicySubject>> appliesToSubjects = new HashMap<PolicySet, List<PolicySubject>>();
+
+ // can we get the composite within which the erp is defined
+
+ for (PolicySet ps : new ArrayList<PolicySet>(epr.getPolicySets()) ) {
+ // Check if this PolicySet applies to the binding, component reference, component, or composite. If not,
+ // remove it from the list of policy sets for this endpoint.
+ if ( epr.getBinding() instanceof PolicySubject ) {
+ if (isApplicableToSubject(document, appliesToSubjects, domainComposite, (PolicySubject)epr.getBinding(), ps))
+ continue;
+ }
+ if (isApplicableToSubject(document, appliesToSubjects, domainComposite, epr.getReference(), ps))
+ continue;
+ else if ( (epr.getReference().getInterfaceContract() != null) &&
+ (isApplicableToSubject(document, appliesToSubjects, domainComposite, epr.getReference().getInterfaceContract().getInterface(), ps)))
+ continue;
+ else if ( isApplicableToSubject(document, appliesToSubjects, domainComposite, epr.getComponent(), ps))
+ continue;
+ else if ( isApplicableToSubject(document, appliesToSubjects, domainComposite, domainComposite, ps))
+ continue;
+ else
+ epr.getPolicySets().remove(ps);
+ }
+
+ } catch (Exception e) {
+ throw new CompositeBuilderException(e);
+ }
+ }
+
private Composite checkAppliesTo(Document document, Map<PolicySet, List<PolicySubject>> appliesToSubjects, Composite topComposite, BuilderContext context) throws Exception {
for ( Component component : topComposite.getComponents() ) {
@@ -127,10 +199,16 @@ public class PolicyAppliesToBuilderImpl extends PolicyAttachmentBuilderImpl {
}
for (ComponentReference componentReference : component.getReferences()) {
- for (EndpointReference epr : componentReference.getEndpointReferences()) {
+ for (EndpointReference epr : componentReference.getEndpointReferences()) {
+ // don't process the EPR yet if it's not resolved
+ if (epr.getStatus() == EndpointReference.Status.WIRED_TARGET_NOT_FOUND ||
+ epr.getBinding() == null){
+ continue;
+ }
+
for (PolicySet ps : new ArrayList<PolicySet>(epr.getPolicySets()) ) {
- // Check if this PolicySet applies to the binding, component reference, component, or composite. If not,
- // remove it from the list of policy sets for this endpoint.
+ // Check if this PolicySet applies to the binding, component reference, component, or composite. If not,
+ // remove it from the list of policy sets for this endpoint.
if ( epr.getBinding() instanceof PolicySubject ) {
if (isApplicableToSubject(document, appliesToSubjects, topComposite, (PolicySubject)epr.getBinding(), ps))
continue;
@@ -161,7 +239,6 @@ public class PolicyAppliesToBuilderImpl extends PolicyAttachmentBuilderImpl {
}
return topComposite;
}
-
/**
* Checks that the provided policy sets applies to the provided policy subject
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
index f00520b836..800d3ef05b 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
@@ -38,6 +38,7 @@ import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
import org.apache.tuscany.sca.assembly.builder.BuilderContext;
import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.PolicyBuilder;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -86,6 +87,7 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder {
protected CompositeActivator compositeActivator;
protected Monitor monitor;
protected UnknownEndpointHandler unknownEndpointHandler;
+ protected CompositeBuilder policyAppliesToBuilder;
public EndpointReferenceBinderImpl(ExtensionPointRegistry extensionPoints) {
@@ -103,6 +105,7 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder {
this.unknownEndpointHandler = utils.getUtility(UnknownEndpointHandler.class);
this.builders = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class);
+
this.compositeActivator = extensionPoints.getExtensionPoint(CompositeActivator.class);
}
@@ -424,11 +427,24 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder {
endpointReference.setTargetEndpoint(matchedEndpoint);
Binding binding = matchedEndpoint.getBinding();
endpointReference.setBinding(binding);
- // TUSCANY-3873 - if no policy on the reference add policy from the service
+ // TUSCANY-3873 - add policy from the service
// we don't care about intents at this stage
- if (endpointReference.getPolicySets().isEmpty()){
- endpointReference.getPolicySets().addAll(matchedEndpoint.getPolicySets());
+ endpointReference.getPolicySets().addAll(matchedEndpoint.getPolicySets());
+ // TODO - we need to re-run the appliesTo processing here but there is some question about what
+ // appliesTo means. It's also difficult to get to the PolicyAppliesToBuilder from here and
+ // need a new EntensionInterface to support access. So for now I'm just cheating and looking to
+ // see if the XPath expression contains the binding type as a string while we discuss appliesTo
+
+ List<PolicySet> psToRemove = new ArrayList<PolicySet>();
+
+ for (PolicySet ps : endpointReference.getPolicySets() ) {
+ if (!ps.getAppliesTo().contains(endpointReference.getBinding().getType().getLocalPart())){
+ psToRemove.add(ps);
+ }
}
+
+ endpointReference.getPolicySets().removeAll(psToRemove);
+
build(endpointReference);
endpointReference.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
endpointReference.setUnresolved(false);
@@ -794,7 +810,7 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder {
}
}
- if(!eprLanguage.equals(epLanguage)){
+ if(!eprLanguage.getNamespaceURI().equals(epLanguage.getNamespaceURI())){
matchAudit.append("No match because the policy sets on either side have policies in differnt languages " +
eprLanguage +
" and " +