summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyContainer.java36
-rw-r--r--sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java14
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java14
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java31
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java29
5 files changed, 101 insertions, 23 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyContainer.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyContainer.java
new file mode 100644
index 0000000000..c0c4021dde
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyContainer.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+/**
+ * Base interface for policy models. Mainly allows policies to hold
+ * other policies
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyContainer {
+ /**
+ * For complex policy models, such as ws-policy,
+ * a policy provider may only match against one of a
+ * number of child policy models
+ *
+ * @return the matching child policy object or null
+ */
+ <T> Object getChildPolicy(Class<T> policyType);
+}
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java
index 30802feb82..e143cb2aa5 100644
--- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java
+++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.provider;
+import java.security.Policy;
import java.util.ArrayList;
import java.util.List;
@@ -29,6 +30,7 @@ import org.apache.tuscany.sca.assembly.EndpointReference;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.InvocationChain;
import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicyContainer;
import org.apache.tuscany.sca.policy.PolicyExpression;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySubject;
@@ -57,13 +59,23 @@ public abstract class BasePolicyProvider<T> implements PolicyProvider {
if (policyType.isInstance(p)) {
policies.add(policyType.cast(p));
}
+
if (p instanceof PolicyExpression) {
PolicyExpression exp = (PolicyExpression)p;
if (policyType.isInstance(exp.getPolicy())) {
policies.add(policyType.cast(exp.getPolicy()));
}
+
+ // TODO - some code to handle the case where the
+ // policy expression is a WS-Policy
+ // Experimental at the moment.
+ if (PolicyContainer.class.isInstance(exp.getPolicy())){
+ Object policy = ((PolicyContainer)exp.getPolicy()).getChildPolicy(policyType);
+ if(policy != null){
+ policies.add(policyType.cast(policy));
+ }
+ }
}
-
}
}
return policies;
diff --git a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java
index 2893072165..843f370df6 100644
--- a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java
@@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.EndpointReference;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.builder.BuilderContext;
import org.apache.tuscany.sca.assembly.builder.PolicyBuilder;
+import org.apache.tuscany.sca.policy.PolicyContainer;
import org.apache.tuscany.sca.policy.PolicyExpression;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySubject;
@@ -41,7 +42,7 @@ import org.apache.tuscany.sca.policy.wspolicy.xml.WSPolicyProcessor;
/**
* The WS-Policy model. Currently defers to the Neethi policy model under the covers.
*/
-public class WSPolicy {
+public class WSPolicy implements PolicyContainer {
public final static String WS_POLICY_NS = "http://schemas.xmlsoap.org/ws/2004/09/policy";
public final static String WS_POLICY = "Policy";
@@ -71,4 +72,15 @@ public class WSPolicy {
public String toString() {
return "WSPolicy [" + neethiPolicy + "]";
}
+
+ public <T> Object getChildPolicy(Class<T> policyType) {
+ for (Object alternative : policyAssertions){
+ for (Object policy : (List<Object>)alternative){
+ if (policyType.isInstance(policy)){
+ return policy;
+ }
+ }
+ }
+ return null;
+ }
}
diff --git a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java
index e42086abe1..d6bd710ed9 100644
--- a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java
@@ -34,7 +34,6 @@ import org.apache.tuscany.sca.assembly.builder.PolicyBuilder;
import org.apache.tuscany.sca.policy.PolicyExpression;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySubject;
-import org.apache.tuscany.sca.policy.wspolicy.xml.WSPolicyProcessor;
/**
* Processing for WS-Policy objects
@@ -43,19 +42,19 @@ import org.apache.tuscany.sca.policy.wspolicy.xml.WSPolicyProcessor;
public class WSPolicyBuilder implements PolicyBuilder<Policy> {
public boolean build(Endpoint endpoint, BuilderContext context) {
- List<Policy> polices = getPolicies(endpoint);
+ List<WSPolicy> polices = getPolicies(endpoint);
System.out.println(endpoint + ": " + polices);
return true;
}
public boolean build(EndpointReference endpointReference, BuilderContext context) {
- List<Policy> polices = getPolicies(endpointReference);
+ List<WSPolicy> polices = getPolicies(endpointReference);
System.out.println(endpointReference + ": " + polices);
return true;
}
public boolean build(Component component, Implementation implementation, BuilderContext context) {
- List<Policy> polices = getPolicies(implementation);
+ List<WSPolicy> polices = getPolicies(implementation);
System.out.println(implementation + ": " + polices);
return true;
}
@@ -68,18 +67,6 @@ public class WSPolicyBuilder implements PolicyBuilder<Policy> {
return null;
}
- private List<Policy> getPolicies(PolicySubject subject) {
- List<Policy> polices = new ArrayList<Policy>();
- for (PolicySet ps : subject.getPolicySets()) {
- for (PolicyExpression exp : ps.getPolicies()) {
- if (getPolicyType().equals(exp.getName())) {
- polices.add((Policy)exp.getPolicy());
- }
- }
- }
- return polices;
- }
-
public boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context) {
// TODO - neethi doesn't include code for matching ws policy
@@ -147,6 +134,18 @@ public class WSPolicyBuilder implements PolicyBuilder<Policy> {
return true;
}
+ private List<WSPolicy> getPolicies(PolicySubject subject) {
+ List<WSPolicy> polices = new ArrayList<WSPolicy>();
+ for (PolicySet ps : subject.getPolicySets()) {
+ for (PolicyExpression exp : ps.getPolicies()) {
+ if (getPolicyType().equals(exp.getName())) {
+ polices.add((WSPolicy)exp.getPolicy());
+ }
+ }
+ }
+ return polices;
+ }
+
private boolean build(WSPolicy wsPolicy1, WSPolicy wsPolicy2){
// TODO - cheating here as we assume a flat policy structure
// we've read all the policy assertions into Tuscany models
diff --git a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java
index 33b1b8ee04..ee2d539be3 100644
--- a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java
@@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
@@ -102,13 +104,24 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements
WSPolicy wsPolicy = new WSPolicy();
wsPolicy.setNeethiPolicy(neethiPolicy);
- // read policy assertions
- readPolicyAssertions(wsPolicy,neethiPolicy, context);
+ // normalize the neethi tree so we can easily identify
+ // the policy alternatives
+ neethiPolicy.normalize(true);
+
+ // top-level children of ExactlyOne are policy alternatives so
+ // for each child create a policy model list and pull the
+ // policies out
+ for(Object alternative : neethiPolicy.getPolicyComponents()) {
+ List<Object> assertions = new ArrayList<Object>();
+ readPolicyAssertions(assertions, (PolicyComponent)alternative, context);
+ wsPolicy.getPolicyAssertions().add(assertions);
+ }
+
return wsPolicy;
}
- private void readPolicyAssertions(WSPolicy wsPolicy, PolicyComponent policyComponent, ProcessorContext context){
+ private void readPolicyAssertions(List<Object> policyAssertions, PolicyComponent policyComponent, ProcessorContext context){
// recurse into the policy alternatives
// TODO - lots of todos here as this just walks down the neethi hierarchy
@@ -116,12 +129,14 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements
// regard to the policy alternatives. Undecided about whether to
// commit to prepresenting this hierarchy in Tuscany or whether
// to rely on neethi
+ // Should this be in the builder? Not really as this drives the
+ // Tuscany specific readers
if (policyComponent.getType() != Constants.TYPE_ASSERTION){
PolicyOperator policyOperator = (PolicyOperator)policyComponent;
for(Object childComponent : policyOperator.getPolicyComponents()){
// TODO - create assertion hierarchy in wsPolicy model
// how we do this depends on if we continue to use neethi
- readPolicyAssertions(wsPolicy, (PolicyComponent)childComponent, context);
+ readPolicyAssertions(policyAssertions, (PolicyComponent)childComponent, context);
}
} else {
try {
@@ -136,10 +151,14 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream);
+ Object neethiAssertion = policyComponent;
Object tuscanyAssertion = extensionProcessor.read(reader, context);
if (tuscanyAssertion != null) {
- wsPolicy.getPolicyAssertions().add(tuscanyAssertion);
+ policyAssertions.add(tuscanyAssertion);
+ } else {
+ // add neethi assertion
+ policyAssertions.add(neethiAssertion);
}
} catch (Exception ex) {
// TODO - report the error properly