From b5795f0876b7ceea20bdb523327af217af5a318b Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 15 Jan 2010 19:18:31 +0000 Subject: 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 --- .../tuscany/sca/policy/wspolicy/WSPolicy.java | 7 ++- .../sca/policy/wspolicy/xml/WSPolicyProcessor.java | 66 +++++++++++++++++++++- ...ca.contribution.processor.StAXArtifactProcessor | 38 ++++++------- 3 files changed, 89 insertions(+), 22 deletions(-) (limited to 'sca-java-2.x/trunk/modules/policy-wspolicy/src/main') 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 policyAssertions = new ArrayList(); public QName getSchemaName() { return WS_POLICY_QNAME; @@ -61,6 +62,10 @@ public class WSPolicy { public void setNeethiPolicy(Policy neethiPolicy) { this.neethiPolicy = neethiPolicy; } + + public List 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 { + protected ExtensionPointRegistry registry; protected StAXArtifactProcessor extensionProcessor; + protected StAXAttributeProcessor 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 -- cgit v1.2.3