summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-07-11 10:41:30 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-07-11 10:41:30 +0000
commitf7e7402c450c81c4ca5a58adb7b3603db94a44f5 (patch)
treed0a0b85c0d3efde5c144c0211f8fed27cae92eb0
parent3db096b9f3b635cd63aceccf75faf93bd4659f5b (diff)
TUSCANY-3883 - Add wireFormat support to default binding.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1145115 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java32
-rw-r--r--sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java157
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefault.java49
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefaultProcessor.java71
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java10
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/Calculator.composite4
-rw-r--r--sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor18
7 files changed, 331 insertions, 10 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java
index 28f4f9fb25..bbc812582e 100644
--- a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java
+++ b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.assembly.xml;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -28,6 +29,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.WireFormat;
import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
@@ -58,13 +60,15 @@ public class SCABindingProcessor extends BaseStAXArtifactProcessor implements St
private SCABindingFactory scaBindingFactory;
private PolicySubjectProcessor policyProcessor;
private PolicyFactory intentAttachPointTypeFactory;
+ private StAXArtifactProcessor<Object> extensionProcessor;
- public SCABindingProcessor(FactoryExtensionPoint modelFactories) {
+ public SCABindingProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor) {
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
policyProcessor = new PolicySubjectProcessor(policyFactory);
this.intentAttachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.extensionProcessor = extensionProcessor;
}
public QName getArtifactType() {
@@ -97,10 +101,25 @@ public class SCABindingProcessor extends BaseStAXArtifactProcessor implements St
scaBinding.setURI(uri);
}
- // Skip to end element
- while (reader.hasNext()) {
- if (reader.next() == END_ELEMENT && BINDING_SCA_QNAME.equals(reader.getName())) {
- break;
+ // Read any sub-elements
+ boolean endFound = false;
+ while (reader.hasNext() && endFound == false) {
+ int nextElementType = reader.next();
+ switch (nextElementType) {
+ case START_ELEMENT:
+ Object extension = extensionProcessor.read(reader, context);
+ if (extension != null) {
+ if (extension instanceof WireFormat) {
+ scaBinding.setRequestWireFormat((WireFormat)extension);
+ }
+ }
+ break;
+ case END_ELEMENT:
+ QName endElementName = reader.getName();
+ if(endElementName.equals(endElementName)){
+ endFound = true;
+ }
+ break;
}
}
return scaBinding;
@@ -125,6 +144,9 @@ public class SCABindingProcessor extends BaseStAXArtifactProcessor implements St
if (scaBinding.getURI() != null) {
writer.writeAttribute(URI, scaBinding.getURI());
}
+
+ // write wireFormat
+ extensionProcessor.write(scaBinding.getRequestWireFormat(), writer, context);
writer.writeEndElement();
}
diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java
new file mode 100644
index 0000000000..2a6fd9ca65
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java
@@ -0,0 +1,157 @@
+/*
+ * 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.assembly.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.junit.Test;
+
+/**
+ * Test reading SCA XML assemblies.
+ *
+ * @version $Rev: 1041915 $ $Date: 2010-12-03 17:10:49 +0000 (Fri, 03 Dec 2010) $
+ */
+public class ReadWriteBindingSCATestCase {
+
+ private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" " +
+ "targetNamespace=\"http://calc\" " +
+ "name=\"Calculator\">"+
+ "<component name=\"AddServiceComponent\" xmlns:test=\"http://test\" test:customAttribute=\"customValue\">"+
+ "<implementation.java class=\"calculator.AddServiceImpl\" />"+
+ "</component>"+
+ "</composite>";
+
+ private XMLInputFactory inputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+ private ProcessorContext context;
+
+ /**
+ * Initialize the test environment
+ * This takes care to register attribute processors when provided
+ *
+ * @param attributeProcessor
+ * @throws Exception
+ */
+ private void init(StAXAttributeProcessor<?> attributeProcessor) throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ if(attributeProcessor != null) {
+ StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class);
+ staxAttributeProcessors.addArtifactProcessor(attributeProcessor);
+ }
+
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+ }
+
+ /**
+ * Read and Write a composite that has a extended attribute
+ * and a particular attribute processor
+ * @throws Exception
+ */
+ @Test
+ public void testReadWriteCompositeWithAttributeProcessor() throws Exception {
+ init(new TestAttributeProcessor());
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML));
+ Composite composite = (Composite) staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML);
+ // System.out.println(bos.toString());
+
+ //assertEquals(XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyComposite(composite);
+ }
+
+ /**
+ * Read and Write a composite that has a extended attribute
+ * but no particular processor for it
+ * @throws Exception
+ */
+ @Test
+ public void testDefaultReadWriteComposite() throws Exception {
+ init(null);
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML));
+ Composite composite = (Composite) staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML);
+ // System.out.println(bos.toString());
+
+ // assertEquals(XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyComposite(composite);
+ }
+
+ private void verifyComposite(Composite c) {
+ assertEquals("Calculator", c.getName().getLocalPart());
+ assertEquals(1, c.getComponents().size());
+ Component component = c.getComponents().get(0);
+ assertEquals("AddServiceComponent", component.getName());
+ assertEquals(1, component.getAttributeExtensions().size());
+ Extension extension = component.getAttributeExtensions().get(0);
+ assertEquals("customAttribute", extension.getQName().getLocalPart());
+ assertEquals("http://test", extension.getQName().getNamespaceURI());
+ assertEquals("customValue", extension.getValue());
+ }
+} \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefault.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefault.java
new file mode 100644
index 0000000000..1cb4df39e0
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefault.java
@@ -0,0 +1,49 @@
+/*
+ * 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.apace.tuscany.sca.binding.sca.wireformat;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.WireFormat;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ *
+ * @version $Rev: 986685 $ $Date: 2010-08-18 15:00:03 +0100 (Wed, 18 Aug 2010) $
+ */
+public class WireFormatDefault implements WireFormat {
+ public static final QName WIRE_FORMAT_DEFAULT_QNAME = new QName(Constants.SCA11_NS, "wireFormat.default");
+
+
+ public QName getSchemaName() {
+ return WIRE_FORMAT_DEFAULT_QNAME;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return this.getClass() == obj.getClass();
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefaultProcessor.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefaultProcessor.java
new file mode 100644
index 0000000000..6c8bd13197
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/wireformat/WireFormatDefaultProcessor.java
@@ -0,0 +1,71 @@
+/*
+ * 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.apace.tuscany.sca.binding.sca.wireformat;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+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.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+
+/**
+ *
+ * @version $Rev: 825773 $ $Date: 2009-10-16 06:42:26 +0100 (Fri, 16 Oct 2009) $
+ */
+public class WireFormatDefaultProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<WireFormatDefault> {
+
+ public QName getArtifactType() {
+ return WireFormatDefault.WIRE_FORMAT_DEFAULT_QNAME;
+ }
+
+ public WireFormatDefaultProcessor(FactoryExtensionPoint modelFactories) {
+ }
+
+ public WireFormatDefault read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ WireFormatDefault wireFormat = new WireFormatDefault();
+
+ return wireFormat;
+ }
+
+ public void write(WireFormatDefault wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+ String prefix = "tuscany";
+ writer.writeStartElement(prefix, getArtifactType().getLocalPart(), getArtifactType().getNamespaceURI());
+ writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS);
+
+ writer.writeEndElement();
+ }
+
+ public Class<WireFormatDefault> getModelType() {
+ return WireFormatDefault.class;
+ }
+
+ public void resolve(WireFormatDefault arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
+
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java
index 895a551f79..c60885f5a4 100644
--- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java
@@ -61,7 +61,7 @@ public class ReadTestCase {
}
@Test
- public void testReadComponentType() throws Exception {
+ public void testReadComponentType() throws Exception {
InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType");
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
ComponentType componentType = (ComponentType)staxProcessor.read(reader, context);
@@ -71,8 +71,8 @@ public class ReadTestCase {
assertNotNull(referenceSCABinding);
SCABinding serviceSCABinding = (SCABinding) componentType.getServices().get(0).getBindings().get(0);
- assertNotNull(serviceSCABinding);
-
+ assertNotNull(serviceSCABinding);
+
//new PrintUtil(System.out).print(componentType);
}
@@ -87,7 +87,9 @@ public class ReadTestCase {
SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0);
Assert.assertNotNull(referenceSCABinding);
- Assert.assertNotNull(serviceSCABinding);
+ Assert.assertNotNull(serviceSCABinding);
+
+ assertNotNull(serviceSCABinding.getRequestWireFormat());
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/Calculator.composite b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/Calculator.composite
index 1847b2b452..46a6fe6c9b 100644
--- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/Calculator.composite
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/Calculator.composite
@@ -40,7 +40,9 @@
<implementation.java class="calculator.AddServiceImpl"/>
<service name="AddService">
<interface.java interface="calculator.AddService"/>
- <binding.sca/>
+ <binding.sca>
+ <wireFormat.default/>
+ </binding.sca>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..185b1e83c6
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/test/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,18 @@
+# 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.
+
+org.apace.tuscany.sca.binding.sca.wireformat.WireFormatDefaultProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#wireFormat.default,model=org.apace.tuscany.sca.binding.sca.wireformat.WireFormatDefault \ No newline at end of file