summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/policy-wspolicy/src/main
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-01-15 19:18:31 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-01-15 19:18:31 +0000
commitb5795f0876b7ceea20bdb523327af217af5a318b (patch)
tree65f61fdd3dc6b2a7b66f13f6d9e6bce3eaeefe98 /sca-java-2.x/trunk/modules/policy-wspolicy/src/main
parentbddbbfc4ecf8bd9f76c17360e7050877e8e242d2 (diff)
A bit more progress on the ws policy model. Not working yet.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@899766 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/policy-wspolicy/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/WSPolicy.java7
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/java/org/apache/tuscany/sca/policy/wspolicy/xml/WSPolicyProcessor.java66
-rw-r--r--sca-java-2.x/trunk/modules/policy-wspolicy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor38
3 files changed, 89 insertions, 22 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
index 73692e57fa..2893072165 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
@@ -39,7 +39,7 @@ 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.
+ * The WS-Policy model. Currently defers to the Neethi policy model under the covers.
*/
public class WSPolicy {
@@ -49,6 +49,7 @@ public class WSPolicy {
public final static QName WS_POLICY_QNAME = new QName(WS_POLICY_NS, WS_POLICY);
private Policy neethiPolicy;
+ private List<Object> policyAssertions = new ArrayList<Object>();
public QName getSchemaName() {
return WS_POLICY_QNAME;
@@ -61,6 +62,10 @@ public class WSPolicy {
public void setNeethiPolicy(Policy neethiPolicy) {
this.neethiPolicy = neethiPolicy;
}
+
+ public List<Object> getPolicyAssertions(){
+ return policyAssertions;
+ }
@Override
public String toString() {
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 356d204484..559cb3525d 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
@@ -19,7 +19,14 @@
package org.apache.tuscany.sca.policy.wspolicy.xml;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -30,7 +37,12 @@ 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.All;
+import org.apache.neethi.Constants;
+import org.apache.neethi.ExactlyOne;
+import org.apache.neethi.PolicyComponent;
import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.PolicyOperator;
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;
@@ -42,6 +54,7 @@ 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.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
/**
@@ -52,9 +65,22 @@ import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements
StAXArtifactProcessor<WSPolicy> {
+ protected ExtensionPointRegistry registry;
protected StAXArtifactProcessor<Object> extensionProcessor;
+ protected StAXAttributeProcessor<Object> extensionAttributeProcessor;
+ protected XMLInputFactory inputFactory;
+ protected XMLOutputFactory outputFactory;
- public WSPolicyProcessor(ExtensionPointRegistry registry) {
+ public WSPolicyProcessor(ExtensionPointRegistry registry,
+ StAXArtifactProcessor extensionProcessor,
+ StAXAttributeProcessor extensionAttributeProcessor) {
+ this.registry = registry;
+ this.extensionProcessor = extensionProcessor;
+ this.extensionAttributeProcessor = extensionAttributeProcessor;
+
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
}
public QName getArtifactType() {
@@ -76,10 +102,46 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements
WSPolicy wsPolicy = new WSPolicy();
wsPolicy.setNeethiPolicy(neethiPolicy);
- // read policy assertions
+ // read policy assertions
+ readPolicyAssertions(wsPolicy,neethiPolicy, context);
return wsPolicy;
}
+
+ private void readPolicyAssertions(WSPolicy wsPolicy, PolicyComponent policyComponent, ProcessorContext context){
+
+ // recurse into the policy alternatives
+ 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);
+ }
+ } else {
+ try {
+ // TODO - not sure we should keep the neethi model but hack for the
+ // time being to get Tuscany processors to process the OMElements
+ // help within the neethi model
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream);
+
+ policyComponent.serialize(writer);
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream);
+
+ Object tuscanyAssertion = extensionProcessor.read(reader, context);
+
+ if (tuscanyAssertion != null) {
+ wsPolicy.getPolicyAssertions().add(tuscanyAssertion);
+ }
+ } catch (Exception ex) {
+ // TODO - report the error properly
+ ex.printStackTrace();
+ }
+ }
+ }
public void write(WSPolicy wsPolicy, XMLStreamWriter writer, ProcessorContext context)
throws ContributionWriteException, XMLStreamException {
diff --git a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
index 0ef04d5e41..745ad35871 100644
--- a/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
+++ b/sca-java-2.x/trunk/modules/policy-wspolicy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -1,20 +1,20 @@
-# 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.
-
-# Implementation class for the artifact processor extension
-org.apache.tuscany.sca.policy.xml.ws.WSPolicyProcessor;qname=http://schemas.xmlsoap.org/ws/2004/09/policy#Policy,model=org.apache.neethi.Policy
+# 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.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.policy.wspolicy.xml.WSPolicyProcessor;qname=http://schemas.xmlsoap.org/ws/2004/09/policy#Policy,model=org.apache.neethi.Policy