diff options
Diffstat (limited to 'java/sca/modules/contribution-namespace')
7 files changed, 133 insertions, 82 deletions
diff --git a/java/sca/modules/contribution-namespace/META-INF/MANIFEST.MF b/java/sca/modules/contribution-namespace/META-INF/MANIFEST.MF index e5cda2aa33..dff2787b09 100644 --- a/java/sca/modules/contribution-namespace/META-INF/MANIFEST.MF +++ b/java/sca/modules/contribution-namespace/META-INF/MANIFEST.MF @@ -14,6 +14,8 @@ Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-Description: Apache Tuscany SCA Namespace Import/Export Model
Import-Package: javax.xml.namespace,
javax.xml.stream,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.impl;version="2.0.0",
org.apache.tuscany.sca.contribution;version="2.0.0",
org.apache.tuscany.sca.contribution.namespace;version="2.0.0",
org.apache.tuscany.sca.contribution.processor;version="2.0.0",
diff --git a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java index 8991585d32..99af328964 100644 --- a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java +++ b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java @@ -6,35 +6,36 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.namespace.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an export for the contribution - * + * * @version $Rev$ $Date$ */ -public class NamespaceExportImpl implements NamespaceExport { - private String namespace; +public class NamespaceExportImpl extends ExtensibleImpl implements NamespaceExport { + private String namespace; private ModelResolver modelResolver; - + protected NamespaceExportImpl() { super(); } - + public String getNamespace() { return namespace; } @@ -42,13 +43,13 @@ public class NamespaceExportImpl implements NamespaceExport { public void setNamespace(String namespace) { this.namespace = namespace; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + } diff --git a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java index 55f58b8328..030fc1754b 100644 --- a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java +++ b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.namespace.impl; @@ -27,12 +27,15 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +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.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.monitor.Monitor; @@ -41,26 +44,35 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * Artifact processor for Namespace export - * + * * @version $Rev$ $Date$ */ -public class NamespaceExportProcessor implements StAXArtifactProcessor<NamespaceExport> { +public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NamespaceExport> { private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; private static final QName EXPORT = new QName(SCA11_NS, "export"); private static final String NAMESPACE = "namespace"; - + private final NamespaceImportExportFactory factory; + private final AssemblyFactory extensionFactory; + private final StAXArtifactProcessor<Object> extensionProcessor; + private final StAXAttributeProcessor<Object> attributeProcessor; private final Monitor monitor; - public NamespaceExportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public NamespaceExportProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + StAXAttributeProcessor<Object> attributeProcessor, + Monitor monitor) { this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); + this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; this.monitor = monitor; } - + /** * Report a warning. - * + * * @param problems * @param message * @param model @@ -71,47 +83,51 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace monitor.problem(problem); } } - + public QName getArtifactType() { return EXPORT; } - + public Class<NamespaceExport> getModelType() { return NamespaceExport.class; } - + /** * Process <export namespace=""/> */ public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException { NamespaceExport namespaceExport = this.factory.createNamespaceExport(); QName element = null; - + try { while (reader.hasNext()) { int event = reader.getEventType(); switch (event) { case START_ELEMENT: element = reader.getName(); - + // Read <export> if (EXPORT.equals(element)) { String ns = reader.getAttributeValue(null, NAMESPACE); if (ns == null) { error("AttributeNameSpaceMissing", reader); //throw new ContributionReadException("Attribute 'namespace' is missing"); - } else + } else { namespaceExport.setNamespace(ns); - } - + } + readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory); + } else { + readExtendedElement(reader, namespaceExport, extensionProcessor); + } + break; case XMLStreamConstants.END_ELEMENT: if (EXPORT.equals(reader.getName())) { return namespaceExport; } - break; + break; } - + // Read the next element if (reader.hasNext()) { reader.next(); @@ -122,24 +138,28 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace ContributionReadException ex = new ContributionReadException(e); error("XMLStreamException", reader, ex); } - + return namespaceExport; } public void write(NamespaceExport namespaceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + // Write <export> writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart()); - + if (namespaceExport.getNamespace() != null) { writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace()); } - + + writeExtendedAttributes(writer, namespaceExport, attributeProcessor); + + writeExtendedElements(writer, namespaceExport, extensionProcessor); + writer.writeEndElement(); } public void resolve(NamespaceExport namespaceExport, ModelResolver resolver) throws ContributionResolveException { - + if (namespaceExport.getNamespace() != null) // Initialize the export's resolver namespaceExport.setModelResolver(new NamespaceExportModelResolver(resolver)); diff --git a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java index 6d2a31f702..35e2d539d4 100644 --- a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java +++ b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java @@ -6,19 +6,20 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.namespace.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; @@ -26,26 +27,26 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an import for the contribution - * + * * @version $Rev$ $Date$ */ -public class NamespaceImportImpl implements NamespaceImport { +public class NamespaceImportImpl extends ExtensibleImpl implements NamespaceImport { private ModelResolver modelResolver; /** * The namespace to be imported */ - private String namespace; + private String namespace; /** * Optional location URI pointing to a Contribution that exports the namespace */ private String location; - + protected NamespaceImportImpl() { super(); } - + public String getLocation() { return location; } @@ -61,16 +62,16 @@ public class NamespaceImportImpl implements NamespaceImport { public void setNamespace(String namespace) { this.namespace = namespace; } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + /** * Match a NamespaceImport to a given NamespaceExport based on : * location is not provided @@ -84,7 +85,7 @@ public class NamespaceImportImpl implements NamespaceImport { } return false; } - + @Override public String toString() { return String.valueOf(namespace); diff --git a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java index 4c9129a0e4..b213d5e899 100644 --- a/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java +++ b/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.namespace.impl; @@ -27,12 +27,15 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +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.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.monitor.Monitor; @@ -41,28 +44,37 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * Artifact processor for Namespace import - * + * * @version $Rev$ $Date$ */ -public class NamespaceImportProcessor implements StAXArtifactProcessor<NamespaceImport> { +public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NamespaceImport> { private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - + private static final QName IMPORT = new QName(SCA11_NS, "import"); private static final String NAMESPACE = "namespace"; private static final String LOCATION = "location"; - + private final NamespaceImportExportFactory factory; + private final AssemblyFactory extensionFactory; + private final StAXArtifactProcessor<Object> extensionProcessor; + private final StAXAttributeProcessor<Object> attributeProcessor; private final Monitor monitor; - public NamespaceImportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public NamespaceImportProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + StAXAttributeProcessor<Object> attributeProcessor, + Monitor monitor) { this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); this.monitor = monitor; + this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; } - + /** * Report a warning. - * + * * @param problems * @param message * @param model @@ -73,11 +85,11 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac monitor.problem(problem); } } - + public QName getArtifactType() { return IMPORT; } - + public Class<NamespaceImport> getModelType() { return NamespaceImport.class; } @@ -88,36 +100,40 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException { NamespaceImport namespaceImport = this.factory.createNamespaceImport(); QName element; - + try { while (reader.hasNext()) { int event = reader.getEventType(); switch (event) { case START_ELEMENT: element = reader.getName(); - + // Read <import> if (IMPORT.equals(element)) { String ns = reader.getAttributeValue(null, NAMESPACE); if (ns == null) { error("AttributeNameSpaceMissing", reader); //throw new ContributionReadException("Attribute 'namespace' is missing"); - } else + } else { namespaceImport.setNamespace(ns); - + } + String location = reader.getAttributeValue(null, LOCATION); if (location != null) { namespaceImport.setLocation(location); } + readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory); + } else { + readExtendedElement(reader, namespaceImport, extensionProcessor); } break; case XMLStreamConstants.END_ELEMENT: if (IMPORT.equals(reader.getName())) { return namespaceImport; } - break; + break; } - + // Read the next element if (reader.hasNext()) { reader.next(); @@ -128,22 +144,24 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac ContributionReadException ex = new ContributionReadException(e); error("XMLStreamException", reader, ex); } - + return namespaceImport; } public void write(NamespaceImport namespaceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - + // Write <import> writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart()); - + if (namespaceImport.getNamespace() != null) { writer.writeAttribute(NAMESPACE, namespaceImport.getNamespace()); } if (namespaceImport.getLocation() != null) { writer.writeAttribute(LOCATION, namespaceImport.getLocation()); } - + + writeExtendedAttributes(writer, namespaceImport, attributeProcessor); + writeExtendedElements(writer, namespaceImport, extensionProcessor); writer.writeEndElement(); } diff --git a/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java b/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java index 109fa59855..a1c5189767 100644 --- a/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java +++ b/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.namespace.impl; @@ -43,13 +43,16 @@ import org.junit.Test; /** * Test NamespaceExportProcessorTestCase - * + * * @version $Rev$ $Date$ */ public class NamespaceExportProcessorTestCase { private static final String VALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<export xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns=\"http://ns\" namespace=\"http://foo\"/>"; + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<export xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns=\"http://ns\"" + + " ns:ext=\"extended\" namespace=\"http://foo\">" + + "<ns:foo/></export>"; private static final String INVALID_XML = "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<export xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns=\"http://ns\"/>"; @@ -83,6 +86,8 @@ public class NamespaceExportProcessorTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader); assertEquals("http://foo", namespaceExport.getNamespace()); + assertEquals(1, namespaceExport.getAttributeExtensions().size()); + assertEquals(1, namespaceExport.getExtensions().size()); } /** diff --git a/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java b/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java index 3ac25d4016..676437042d 100644 --- a/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java +++ b/java/sca/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.namespace.impl; @@ -45,17 +45,19 @@ import org.junit.Test; /** * Test NamespaceImportProcessorTestCase - * + * * @version $Rev$ $Date$ */ public class NamespaceImportProcessorTestCase { private static final String VALID_XML = "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<import xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns=\"http://ns\" namespace=\"http://foo\" location=\"sca://contributions/001\"/>"; + + "<import xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns=\"http://ns\"" + + " namespace=\"http://foo\" location=\"sca://contributions/001\" ns:ext=\"extended\">" + + "<ns:foo/></import>"; private static final String INVALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<import xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns=\"http://ns\" location=\"sca://contributions/001\"/>"; private static XMLInputFactory inputFactory; @@ -85,9 +87,11 @@ public class NamespaceImportProcessorTestCase { public void testLoad() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader); - + assertEquals("http://foo", namespaceImport.getNamespace()); assertEquals("sca://contributions/001", namespaceImport.getLocation()); + assertEquals(1, namespaceImport.getAttributeExtensions().size()); + assertEquals(1, namespaceImport.getExtensions().size()); } /** @@ -107,5 +111,5 @@ public class NamespaceImportProcessorTestCase { Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); - } + } } |