From 734d1d84e2b097d334bf57331f14af0ee250ca0c Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 14 Jan 2009 18:40:38 +0000 Subject: Reverting changes from revision #734356 and there was some merge conflicts that were not supposed to get to svn. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734475 13f79535-47bb-0310-9956-ffa450edef68 --- branches/sca-java-1.x/modules/assembly-xml/pom.xml | 6 - .../sca/assembly/xml/BaseAssemblyProcessor.java | 10 +- .../assembly/xml/AnyElementReadWriteTestCase.java | 121 ++++++++++++++++++ .../xml/ReadWriteAnyAttributeTestCase.java | 141 --------------------- .../assembly/xml/ReadWriteAnyElementTestCase.java | 121 ------------------ .../assembly/xml/ReadWriteAttributeTestCase.java | 118 +++++++++++++++++ .../sca/assembly/xml/TestAttributeProcessor.java | 3 +- .../sca/assembly/xml/CalculatorExtended.composite | 54 ++++++++ .../processor/xml/AnyAttributeProcessor.java | 20 ++- .../processor/xml/AnyAttributeWrapper.java | 48 ------- .../processor/xml/AnyElementProcessor.java | 13 +- ...a.contribution.processor.StAXAttributeProcessor | 19 --- .../ExtensibleStAXAttributeProcessor.java | 8 +- 13 files changed, 324 insertions(+), 358 deletions(-) create mode 100644 branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java delete mode 100644 branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java delete mode 100644 branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java create mode 100644 branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java create mode 100644 branches/sca-java-1.x/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite delete mode 100644 branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeWrapper.java delete mode 100644 branches/sca-java-1.x/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor (limited to 'branches/sca-java-1.x') 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 d605fe47b3..d6b42550cf 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/pom.xml +++ b/branches/sca-java-1.x/modules/assembly-xml/pom.xml @@ -53,12 +53,6 @@ 1.5-SNAPSHOT - - org.apache.tuscany.sca - tuscany-contribution-xml - 1.5-SNAPSHOT - - org.apache.tuscany.sca tuscany-contribution-namespace 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 1a1d285d10..80c5e807fe 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,7 +60,6 @@ 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; @@ -137,6 +136,8 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); this.monitor = monitor; + + //TODO - this constructor should take a monitor too. } /** @@ -869,8 +870,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()) ) { - Object o = extensionAttributeProcessor.read(attributeName, reader); - estensibleElement.getExtensions().add(o); + String attributeExtension = (String) extensionAttributeProcessor.read(attributeName, reader); + estensibleElement.getExtensions().add(attributeExtension); } } } @@ -888,7 +889,8 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implement */ protected void writeExtendedAttributes(XMLStreamWriter writer, Extensible extensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionWriteException, XMLStreamException { for(Object o : extensibleElement.getExtensions()) { - if(o instanceof AnyAttributeWrapper) { + //FIXME How to identify it's a extended attribute ? + if(o instanceof String) { extensionAttributeProcessor.write(o, writer); } } 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/AnyElementReadWriteTestCase.java new file mode 100644 index 0000000000..779f3cd352 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java @@ -0,0 +1,121 @@ +/* + * 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.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.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class AnyElementReadWriteTestCase { + private static final String XML_RECURSIVE_EXTENDED_ELEMENT = + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + + private static final String XML_UNKNOWN_IMPL = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints + .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, + inputFactory, XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReadWriteExtendedRecursiveElement() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + //System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); + //System.out.println(bos.toString()); + + assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); + bos.close(); + } + + //@Test + @Ignore() + public void testReadWriteUnknwonImpl() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + 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/ReadWriteAnyAttributeTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java deleted file mode 100644 index 0930146a9d..0000000000 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.ByteArrayOutputStream; -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 org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -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 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 = ""+ - ""+ - ""+ - ""+ - ""+ - ""; - - - 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); - - if(attributeProcessor != null) { - StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); - staxAttributeProcessors.addArtifactProcessor(attributeProcessor); - } - - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); - - - } - - /** - * 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); - 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()); - } - - - /** - * 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); - 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()); - } -} diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java deleted file mode 100644 index a205e16676..0000000000 --- a/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.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.Composite; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -public class ReadWriteAnyElementTestCase { - private static final String XML_RECURSIVE_EXTENDED_ELEMENT = - "" + - "" + - "" + - "" + - "" + - "" + - ""; - - - private static final String XML_UNKNOWN_IMPL = - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - ""; - - private XMLInputFactory inputFactory; - private ExtensibleStAXArtifactProcessor staxProcessor; - - @Before - public void setUp() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); - inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints - .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, - inputFactory, XMLOutputFactory.newInstance(), null); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testReadWriteExtendedRecursiveElement() throws Exception { - XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - reader.close(); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); - - // used for debug comparison - //System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); - //System.out.println(bos.toString()); - - assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); - bos.close(); - } - - //@Test - @Ignore() - public void testReadWriteUnknwonImpl() throws Exception { - XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - reader.close(); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); - - // used for debug comparison - //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/ReadWriteAttributeTestCase.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java new file mode 100644 index 0000000000..387405fd8d --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java @@ -0,0 +1,118 @@ +/* + * 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 java.io.ByteArrayOutputStream; +import java.io.InputStream; + +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.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAttributeTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + 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 = ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + @Override + public void setUp() 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()); + + 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); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + is.close(); + } + + public void testWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + is.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + 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/TestAttributeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java index 65bbf75cdf..691145a30e 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,7 +47,8 @@ public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements } public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - writer.writeAttribute(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI(), ATTRIBUTE.getLocalPart(), value); + writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI()); + writer.writeAttribute(ATTRIBUTE.getLocalPart(), value); } public Class 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 new file mode 100644 index 0000000000..3c69d0ed67 --- /dev/null +++ b/branches/sca-java-1.x/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java index 04431f7eab..36e959ea21 100644 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java +++ b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java @@ -38,7 +38,7 @@ import org.apache.tuscany.sca.monitor.Monitor; * * @version $Rev$ $Date$ */ -public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor { +public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor { private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute"); public AnyAttributeProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { @@ -49,23 +49,21 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements return ANY_ATTRIBUTE; } - public Class getModelType() { - return AnyAttributeWrapper.class; + public Class getModelType() { + return String.class; } - public AnyAttributeWrapper read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { - AnyAttributeWrapper attributeWrapper = new AnyAttributeWrapper(); - attributeWrapper.setQName(attributeName); - attributeWrapper.setValue(reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart())); - return attributeWrapper; + public String read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + return reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart()); } - public void write(AnyAttributeWrapper attributeWrapper, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - writer.writeAttribute(attributeWrapper.getQName().getPrefix(), attributeWrapper.getQName().getNamespaceURI(), attributeWrapper.getQName().getLocalPart(), attributeWrapper.getValue().toString()); + public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writer.setPrefix(ANY_ATTRIBUTE.getPrefix(), ANY_ATTRIBUTE.getNamespaceURI()); + writer.writeAttribute(ANY_ATTRIBUTE.getLocalPart(), value); } - public void resolve(AnyAttributeWrapper arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(String arg0, ModelResolver arg1) throws ContributionResolveException { } } diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeWrapper.java b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeWrapper.java deleted file mode 100644 index 16c01755fc..0000000000 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeWrapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.contribution.processor.xml; - -import javax.xml.namespace.QName; - -public class AnyAttributeWrapper { - private QName qName; - private Object value; - - public AnyAttributeWrapper() { - - } - - public AnyAttributeWrapper(QName qName, Object value) { - this.qName = qName; - this.value = value; - } - - public QName getQName() { - return qName; - } - public void setQName(QName name) { - qName = name; - } - public Object getValue() { - return value; - } - public void setValue(Object value) { - this.value = value; - } -} diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java index 5e4462ef08..2b868b9e45 100644 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java +++ b/branches/sca-java-1.x/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java @@ -18,23 +18,28 @@ */ package org.apache.tuscany.sca.contribution.processor.xml; -import static javax.xml.stream.XMLStreamConstants.CDATA; -import static javax.xml.stream.XMLStreamConstants.CHARACTERS; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.CHARACTERS; +import static javax.xml.stream.XMLStreamConstants.COMMENT; +import static javax.xml.stream.XMLStreamConstants.CDATA; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Stack; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; import org.apache.tuscany.sca.contribution.Constants; @@ -44,9 +49,11 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionResolveException; import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.contribution.processor.xml.XMLEventsStreamReader; public class AnyElementProcessor implements StAXArtifactProcessor { - private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement"); + private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, + "anyElement"); private XMLInputFactory xmlInputFactory; @SuppressWarnings("unused") diff --git a/branches/sca-java-1.x/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor b/branches/sca-java-1.x/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor deleted file mode 100644 index e3d5e16ef6..0000000000 --- a/branches/sca-java-1.x/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor +++ /dev/null @@ -1,19 +0,0 @@ -# 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.contribution.processor.xml.AnyAttributeProcessor;qname=http://www.w3.org/2001/XMLSchema#anyAttribute,model=java.lang.Object diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java index 9a5f1b363a..29c2af7513 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java @@ -55,7 +55,7 @@ public class ExtensibleStAXAttributeProcessor private static final Logger logger = Logger.getLogger(ExtensibleStAXAttributeProcessor.class.getName()); - private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute"); + private static final QName UNKNOWN_ATTRIBUTE = new QName(Constants.SCA10_TUSCANY_NS, "unknown"); private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; @@ -149,13 +149,13 @@ public class ExtensibleStAXAttributeProcessor //handle extension attributes without processors - processor = (StAXAttributeProcessor)processors.getProcessor(ANY_ATTRIBUTE); + processor = (StAXAttributeProcessor)processors.getProcessor(UNKNOWN_ATTRIBUTE); if (processor == null) { Location location = source.getLocation(); if (logger.isLoggable(Level.WARNING)) { logger.warning("Could not find Default Attribute processor !"); } - warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location); + warning("DefaultAttributeProcessorNotAvailable", processors, UNKNOWN_ATTRIBUTE, location); } return processor == null ? null : processor.read(attributeName, source); @@ -181,7 +181,7 @@ public class ExtensibleStAXAttributeProcessor } //handle extension attributes without processors - processor = (StAXAttributeProcessor)processors.getProcessor(ANY_ATTRIBUTE); + processor = (StAXAttributeProcessor)processors.getProcessor(UNKNOWN_ATTRIBUTE); if(processor == null) { if (logger.isLoggable(Level.WARNING)) { logger.warning("No Default StAX processor is configured to handle " + model.getClass()); -- cgit v1.2.3