summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace')
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java30
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java46
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java60
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java42
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java55
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java55
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java172
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java41
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java93
-rw-r--r--sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java178
10 files changed, 772 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java
new file mode 100644
index 0000000000..a71fa61a54
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java
@@ -0,0 +1,30 @@
+/*
+ * 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.namespace;
+
+import org.apache.tuscany.sca.contribution.namespace.impl.NamespaceImportExportFactoryImpl;
+
+/**
+ * Default Namespace Import/Export model factory implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultNamespaceImportExportFactory extends NamespaceImportExportFactoryImpl implements NamespaceImportExportFactory {
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java
new file mode 100644
index 0000000000..c68aee8521
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java
@@ -0,0 +1,46 @@
+/*
+ * 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.namespace;
+
+import org.apache.tuscany.sca.contribution.Export;
+
+
+/**
+ * The representation of an XML namespace export.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface NamespaceExport extends Export {
+
+ /**
+ * Get Namespace that identifies the export
+ *
+ * @return The exported namespace
+ */
+ String getNamespace();
+
+ /**
+ * Set Namespace that identifies the export
+ *
+ * @param namespace The exported namespace
+ */
+ void setNamespace(String namespace);
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java
new file mode 100644
index 0000000000..c452b15ee9
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java
@@ -0,0 +1,60 @@
+/*
+ * 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.namespace;
+
+import org.apache.tuscany.sca.contribution.Import;
+
+/**
+ * The representation of an XML namespace import.
+ *
+ * @version $Rev$ $Date$
+ * @tuscany.spi.extension.asclient
+ */
+public interface NamespaceImport extends Import {
+
+ /**
+ * Get the location used to resolve the definitions for this import
+ *
+ * @return The import location
+ */
+ String getLocation();
+
+ /**
+ * Set the location used to resolve the definitions for this import
+ *
+ * @param location The import location
+ */
+ void setLocation(String location);
+
+ /**
+ * Get Namespace that identifies the import
+ *
+ * @return The namespace
+ */
+ String getNamespace();
+
+ /**
+ * Set Namespace that identifies the import
+ *
+ * @param namespace The namespace
+ */
+ void setNamespace(String namespace);
+
+} \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java
new file mode 100644
index 0000000000..cfbac8bb1f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java
@@ -0,0 +1,42 @@
+/*
+ * 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.namespace;
+
+/**
+ * Base Namespace import/export model factory
+ *
+ * @version $Rev$ $Date$
+ */
+public interface NamespaceImportExportFactory {
+
+ /**
+ * Create a namespace import model object
+ *
+ * @return The new NamespaceImport model object
+ */
+ NamespaceImport createNamespaceImport();
+
+ /**
+ * Create a namespace export model object
+ *
+ * @return The new NamespaceExport model object
+ */
+ NamespaceExport createNamespaceExport();
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java
new file mode 100644
index 0000000000..99af328964
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java
@@ -0,0 +1,55 @@
+/*
+ * 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.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 extends ExtensibleImpl implements NamespaceExport {
+ private String namespace;
+ private ModelResolver modelResolver;
+
+ protected NamespaceExportImpl() {
+ super();
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java
new file mode 100644
index 0000000000..7bf3c32c93
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java
@@ -0,0 +1,55 @@
+/*
+ * 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.namespace.impl;
+
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A model resolver for namespace exports.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamespaceExportModelResolver implements ModelResolver {
+
+ private ModelResolver resolver;
+
+ public NamespaceExportModelResolver(ModelResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ public void addModel(Object resolved, ProcessorContext context) {
+ throw new IllegalStateException();
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ throw new IllegalStateException();
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+
+ // Just delegate to the contribution's model resolver, namespace
+ // based filtering is implemented in the model specific model
+ // resolver, which know how to get the namespace of the particular
+ // type of model that they handle
+ return resolver.resolveModel(modelClass, unresolved, context);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
new file mode 100644
index 0000000000..0d410fb377
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
@@ -0,0 +1,172 @@
+/*
+ * 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.namespace.impl;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+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.ProcessorContext;
+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;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Artifact processor for Namespace export
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NamespaceExport> {
+
+ private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+ 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;
+
+ public NamespaceExportProcessor(FactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ StAXAttributeProcessor<Object> attributeProcessor) {
+ this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
+ this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.extensionProcessor = extensionProcessor;
+ this.attributeProcessor = attributeProcessor;
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getArtifactType() {
+ return EXPORT;
+ }
+
+ public Class<NamespaceExport> getModelType() {
+ return NamespaceExport.class;
+ }
+
+ /**
+ * Process <export namespace=""/>
+ */
+ public NamespaceExport read(XMLStreamReader reader, ProcessorContext context) 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(context.getMonitor(), "AttributeNameSpaceMissing", reader);
+ //throw new ContributionReadException("Attribute 'namespace' is missing");
+ } else {
+ namespaceExport.setNamespace(ns);
+ }
+ readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory, context);
+ } else {
+ //read extended elements
+ Object ext = extensionProcessor.read(reader, context);
+ if (namespaceExport != null) {
+ namespaceExport.getExtensions().add(ext);
+ }
+ }
+
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (EXPORT.equals(reader.getName())) {
+ return namespaceExport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ }
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
+ }
+
+ return namespaceExport;
+ }
+
+ public void write(NamespaceExport namespaceExport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+
+ // Write <export>
+ writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart());
+
+ if (namespaceExport.getNamespace() != null) {
+ writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace());
+ }
+
+ writeExtendedAttributes(writer, namespaceExport, attributeProcessor, context);
+
+ // handle extended elements
+ for (Object ext : namespaceExport.getExtensions()) {
+ extensionProcessor.write(ext, writer, context);
+ }
+
+ writer.writeEndElement();
+ }
+
+ public void resolve(NamespaceExport namespaceExport, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+
+ if (namespaceExport.getNamespace() != null)
+ // Initialize the export's resolver
+ namespaceExport.setModelResolver(new NamespaceExportModelResolver(resolver));
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java
new file mode 100644
index 0000000000..1146e593a9
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java
@@ -0,0 +1,41 @@
+/*
+ * 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.namespace.impl;
+
+import org.apache.tuscany.sca.contribution.namespace.NamespaceExport;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory;
+
+/**
+ * Namespace Import/Export model factory implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamespaceImportExportFactoryImpl implements NamespaceImportExportFactory {
+
+ public NamespaceImport createNamespaceImport() {
+ return new NamespaceImportImpl();
+ }
+
+ public NamespaceExport createNamespaceExport() {
+ return new NamespaceExportImpl();
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java
new file mode 100644
index 0000000000..35e2d539d4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The representation of an import for the contribution
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamespaceImportImpl extends ExtensibleImpl implements NamespaceImport {
+ private ModelResolver modelResolver;
+
+ /**
+ * The namespace to be imported
+ */
+ 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;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ 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
+ * import and export namespaces match
+ */
+ public boolean match(Export export) {
+ if (export instanceof NamespaceExport) {
+ if (this.getNamespace().equals(((NamespaceExport)export).getNamespace())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(namespace);
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
new file mode 100644
index 0000000000..17b0dc3953
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
@@ -0,0 +1,178 @@
+/*
+ * 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.namespace.impl;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+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.ProcessorContext;
+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;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Artifact processor for Namespace import
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NamespaceImport> {
+ private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+
+ 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;
+
+ public NamespaceImportProcessor(FactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ StAXAttributeProcessor<Object> attributeProcessor) {
+ this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
+ this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.extensionProcessor = extensionProcessor;
+ this.attributeProcessor = attributeProcessor;
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getArtifactType() {
+ return IMPORT;
+ }
+
+ public Class<NamespaceImport> getModelType() {
+ return NamespaceImport.class;
+ }
+
+ /**
+ * Process <import namespace="" location=""/>
+ */
+ public NamespaceImport read(XMLStreamReader reader, ProcessorContext context) 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(context.getMonitor(), "AttributeNameSpaceMissing", reader);
+ //throw new ContributionReadException("Attribute 'namespace' is missing");
+ } else {
+ namespaceImport.setNamespace(ns);
+ }
+
+ String location = getURIString(reader, LOCATION);
+ if (location != null) {
+ namespaceImport.setLocation(location);
+ }
+ readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory, context);
+ } else {
+ // handle extended elements
+ Object ext = extensionProcessor.read(reader, context);
+ if (namespaceImport != null) {
+ namespaceImport.getExtensions().add(ext);
+ }
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (IMPORT.equals(reader.getName())) {
+ return namespaceImport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ }
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
+ }
+
+ return namespaceImport;
+ }
+
+ public void write(NamespaceImport namespaceImport, XMLStreamWriter writer, ProcessorContext context) 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, context);
+
+ //handle extended elements
+ for (Object ext : namespaceImport.getExtensions()) {
+ extensionProcessor.write(ext, writer, context);
+ }
+
+ writer.writeEndElement();
+ }
+
+
+ public void resolve(NamespaceImport model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ }
+}