diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-14 07:35:29 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-14 07:35:29 +0000 |
commit | 75bc85590e5bc05aff6d7234bf3296d41b324b94 (patch) | |
tree | 09afebe1288e5029615dc0d066375bae801af229 /branches/sca-java-1.x/modules/assembly-xml | |
parent | 0b0c4db98203e2d3dc2f656641c74aa9a4ae82fc (diff) |
Merge branch 'tuscany-2663'
Conflicts:
modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734356 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/assembly-xml')
6 files changed, 84 insertions, 112 deletions
diff --git a/branches/sca-java-1.x/modules/assembly-xml/pom.xml b/branches/sca-java-1.x/modules/assembly-xml/pom.xml index d6b42550cf..d605fe47b3 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/pom.xml +++ b/branches/sca-java-1.x/modules/assembly-xml/pom.xml @@ -55,6 +55,12 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-xml</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-contribution-namespace</artifactId> <version>1.5-SNAPSHOT</version> </dependency> diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java index 80c5e807fe..1a1d285d10 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java @@ -60,6 +60,7 @@ import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.xml.AnyAttributeWrapper; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionResolveException; @@ -136,8 +137,6 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); this.monitor = monitor; - - //TODO - this constructor should take a monitor too. } /** @@ -870,8 +869,8 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement QName attributeName = reader.getAttributeName(a); if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { if( ! elementName.getNamespaceURI().equals(attributeName.getNamespaceURI()) ) { - String attributeExtension = (String) extensionAttributeProcessor.read(attributeName, reader); - estensibleElement.getExtensions().add(attributeExtension); + Object o = extensionAttributeProcessor.read(attributeName, reader); + estensibleElement.getExtensions().add(o); } } } @@ -889,8 +888,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement */ protected void writeExtendedAttributes(XMLStreamWriter writer, Extensible extensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionWriteException, XMLStreamException { for(Object o : extensibleElement.getExtensions()) { - //FIXME How to identify it's a extended attribute ? - if(o instanceof String) { + if(o instanceof AnyAttributeWrapper) { extensionAttributeProcessor.write(o, writer); } } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java index 387405fd8d..0930146a9d 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -19,100 +19,123 @@ package org.apache.tuscany.sca.assembly.xml; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.ByteArrayOutputStream; -import java.io.InputStream; +import java.io.StringReader; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamReader; -import junit.framework.TestCase; - import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; 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.Ignore; +import org.junit.Test; /** * Test reading SCA XML assemblies. * * @version $Rev$ $Date$ */ -public class ReadWriteAttributeTestCase extends TestCase { - - private XMLInputFactory inputFactory; - private ExtensibleStAXArtifactProcessor staxProcessor; - +public class ReadWriteAnyAttributeTestCase { private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); // implementation.java for CalculatorServiceComponent appears in a strange place as the // java implementation extension is not loaded and hence they are loaded as any elements private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+ - "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\">"+ - "<service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\">"+ - "<interface.java interface=\"calculator.CalculatorService\" />"+ - "</service>"+ - "<component name=\"CalculatorServiceComponent\" customAttribute=\"customValue\">"+ - "<implementation.java class=\"calculator.CalculatorServiceImpl\" />"+ - "<reference name=\"addService\" target=\"AddServiceComponent\" />"+ - "<reference name=\"subtractService\" target=\"SubtractServiceComponent\" />"+ - "<reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" />"+ - "<reference name=\"divideService\" target=\"DivideServiceComponent\" />"+ - "</component>"+ - "<component name=\"AddServiceComponent\">"+ + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" " + + "xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" " + + "targetNamespace=\"http://calc\" " + + "name=\"Calculator\">"+ + "<component name=\"AddServiceComponent\" xmlns:test=\"http://test\" test:customAttribute=\"customValue\">"+ "<implementation.java class=\"calculator.AddServiceImpl\" />"+ "</component>"+ - "<component name=\"SubtractServiceComponent\">"+ - "<implementation.java class=\"calculator.SubtractServiceImpl\" />"+ - "</component>"+ - "<component name=\"MultiplyServiceComponent\">"+ - "<implementation.java class=\"calculator.MultiplyServiceImpl\" />"+ - "</component>"+ - "<component name=\"DivideServiceComponent\">"+ - "<implementation.java class=\"calculator.DivideServiceImpl\" />"+ - "</component>"+ "</composite>"; - @Override - public void setUp() throws Exception { + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + /** + * 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(); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); - staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); + if(attributeProcessor != null) { + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(attributeProcessor); + } staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); - } - @Override - public void tearDown() throws Exception { } - public void testReadComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + /** + * Read and Write a composite that has a extended attribute + * and a particular attribute processor + * @throws Exception + */ + @Test + @Ignore + public void testReadWriteCompositeWithAttributeProcessor() throws Exception { + init(new TestAttributeProcessor()); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); Composite composite = (Composite) staxProcessor.read(reader); assertNotNull(composite); - is.close(); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + System.out.println(XML); + System.out.println(bos.toString()); + + + assertEquals(XML, bos.toString()); } - public void testWriteComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + + /** + * 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); assertNotNull(composite); - is.close(); + reader.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); staxProcessor.write(composite, bos); - System.out.println(bos.toString()); - assertEquals(XML, bos.toString()); + // used for debug comparison + System.out.println(XML); + System.out.println(bos.toString()); + + + assertEquals(XML, bos.toString()); } } diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java index 779f3cd352..a205e16676 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java @@ -40,7 +40,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -public class AnyElementReadWriteTestCase { +public class ReadWriteAnyElementTestCase { private static final String XML_RECURSIVE_EXTENDED_ELEMENT = "<?xml version='1.0' encoding='UTF-8'?>" + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://temp\" name=\"RecursiveExtendedElement\">" + @@ -111,8 +111,8 @@ public class AnyElementReadWriteTestCase { staxProcessor.write(composite, bos); // used for debug comparison - System.out.println(XML_UNKNOWN_IMPL); - System.out.println(bos.toString()); + //System.out.println(XML_UNKNOWN_IMPL); + //System.out.println(bos.toString()); assertEquals(XML_UNKNOWN_IMPL, bos.toString()); bos.close(); diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java index 691145a30e..65bbf75cdf 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java @@ -47,8 +47,7 @@ public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements } public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI()); - writer.writeAttribute(ATTRIBUTE.getLocalPart(), value); + writer.writeAttribute(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI(), ATTRIBUTE.getLocalPart(), value); } public Class<String> getModelType() { diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite b/branches/sca-java-1.x/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite deleted file mode 100644 index 3c69d0ed67..0000000000 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * 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. ---> -<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" - xmlns:calc="http://calc" - xmlns:test="http://test" - targetNamespace="http://calc" - name="Calculator"> - - <service name="CalculatorService" promote="CalculatorServiceComponent"> - <interface.java interface="calculator.CalculatorService"/> - </service> - - <component name="CalculatorServiceComponent" test:customAttribute="customValue"> - <implementation.java class="calculator.CalculatorServiceImpl"/> - <reference name="addService" target="AddServiceComponent"/> - <reference name="subtractService" target="SubtractServiceComponent"/> - <reference name="multiplyService" target="MultiplyServiceComponent"/> - <reference name="divideService" target="DivideServiceComponent"/> - </component> - - <component name="AddServiceComponent"> - <implementation.java class="calculator.AddServiceImpl"/> - </component> - - <component name="SubtractServiceComponent"> - <implementation.java class="calculator.SubtractServiceImpl"/> - </component> - - <component name="MultiplyServiceComponent"> - <implementation.java class="calculator.MultiplyServiceImpl"/> - </component> - - <component name="DivideServiceComponent"> - <implementation.java class="calculator.DivideServiceImpl"/> - </component> - -</composite> |