summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-01-12 15:56:32 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-01-12 15:56:32 +0000
commit75d303274d0edc1ffd24cbbd5dd75ec64504bdb2 (patch)
tree9b7a47dfdf46bb89689d6a26493161fab35df8f5 /sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org
parent0239d7c3b47cf13eb7b013a1910d72067f1e0663 (diff)
Start of extension for handling WS-Policy policies. Based on policy-xml-ws but neither working nor in the build yet. It's currently still using the neethi model but this is wrapped in a Tuscany model now to allow us to break out and process assertions separately. Neethi currently has no function for matching so we need to cast around to see if that is available elsewhere.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@898390 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org')
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java69
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java89
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java103
3 files changed, 261 insertions, 0 deletions
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
new file mode 100644
index 0000000000..73692e57fa
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java
@@ -0,0 +1,69 @@
+/*
+ * 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.wspolicy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
+import javax.xml.namespace.QName;
+
+import org.apache.neethi.Policy;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Endpoint;
+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.PolicyExpression;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.policy.wspolicy.xml.WSPolicyProcessor;
+
+/**
+ * The WS-Policy model. Defers to the Neethi policy model under the covers.
+ */
+public class WSPolicy {
+
+ public final static String WS_POLICY_NS = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+ public final static String WS_POLICY = "Policy";
+
+ public final static QName WS_POLICY_QNAME = new QName(WS_POLICY_NS, WS_POLICY);
+
+ private Policy neethiPolicy;
+
+ public QName getSchemaName() {
+ return WS_POLICY_QNAME;
+ }
+
+ public Policy getNeethiPolicy() {
+ return neethiPolicy;
+ }
+
+ public void setNeethiPolicy(Policy neethiPolicy) {
+ this.neethiPolicy = neethiPolicy;
+ }
+
+ @Override
+ public String toString() {
+ return "WSPolicy [" + neethiPolicy + "]";
+ }
+}
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
new file mode 100644
index 0000000000..3bc0d0423d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicyBuilder.java
@@ -0,0 +1,89 @@
+/*
+ * 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.wspolicy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.neethi.Policy;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Endpoint;
+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.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
+ * TBD
+ */
+public class WSPolicyBuilder implements PolicyBuilder<Policy> {
+
+ public boolean build(Endpoint endpoint, BuilderContext context) {
+ List<Policy> polices = getPolicies(endpoint);
+ System.out.println(endpoint + ": " + polices);
+ return true;
+ }
+
+ public boolean build(EndpointReference endpointReference, BuilderContext context) {
+ List<Policy> polices = getPolicies(endpointReference);
+ System.out.println(endpointReference + ": " + polices);
+ return true;
+ }
+
+ public boolean build(Component component, Implementation implementation, BuilderContext context) {
+ List<Policy> polices = getPolicies(implementation);
+ System.out.println(implementation + ": " + polices);
+ return true;
+ }
+
+ public QName getPolicyType() {
+ return WSPolicy.WS_POLICY_QNAME;
+ }
+
+ 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) {
+ return true;
+ }
+
+ public PolicyExpression match(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context) {
+ // Get the ws-policy elements from the endpoint reference and endpoint and work out the intersection
+
+ return null;
+ }
+
+}
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
new file mode 100644
index 0000000000..356d204484
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java
@@ -0,0 +1,103 @@
+/*
+ * 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.wspolicy.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.neethi.PolicyEngine;
+import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
+import org.apache.tuscany.sca.common.xml.stax.reader.XMLDocumentStreamReader;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
+
+/**
+ * Processor for handling xml models of PolicySet definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements
+ StAXArtifactProcessor<WSPolicy> {
+
+ protected StAXArtifactProcessor<Object> extensionProcessor;
+
+ public WSPolicyProcessor(ExtensionPointRegistry registry) {
+ }
+
+ public QName getArtifactType() {
+ return WSPolicy.WS_POLICY_QNAME;
+ }
+
+ public Class<WSPolicy> getModelType() {
+ return WSPolicy.class;
+ }
+
+ public WSPolicy read(XMLStreamReader reader, ProcessorContext context)
+ throws ContributionReadException, XMLStreamException {
+ org.apache.neethi.Policy neethiPolicy = null;
+ XMLDocumentStreamReader doc = new XMLDocumentStreamReader(reader);
+ StAXOMBuilder builder = new StAXOMBuilder(doc);
+ OMElement element = builder.getDocumentElement();
+ neethiPolicy = PolicyEngine.getPolicy(element);
+
+ WSPolicy wsPolicy = new WSPolicy();
+ wsPolicy.setNeethiPolicy(neethiPolicy);
+
+ // read policy assertions
+
+ return wsPolicy;
+ }
+
+ public void write(WSPolicy wsPolicy, XMLStreamWriter writer, ProcessorContext context)
+ throws ContributionWriteException, XMLStreamException {
+
+ // Write an <sca:policySet>
+ writer.writeStartElement(WSPolicy.WS_POLICY_NS, WSPolicy.WS_POLICY);
+
+ if (wsPolicy != null) {
+ wsPolicy.getNeethiPolicy().serialize(writer);
+ }
+
+ writer.writeEndElement();
+ }
+
+ public void resolve(WSPolicy wsPolicy, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
+
+ // resolve policy assertions
+ }
+
+}