summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-22 21:51:38 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-22 21:51:38 +0000
commitb354c03aecb7f30bfd65f0ec02a81ab915ba4966 (patch)
tree569564504b982d2a5bfb3ab3052c0c5130fcae28 /branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache
parentbaa5887866a52cd40be16707d9741cbbad9d7263 (diff)
Add "Extensible" support for the ContributionMetaData/Contribution/Import/Export models (TUSCANY-2983)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@767683 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache')
-rw-r--r--branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java23
-rw-r--r--branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java72
-rw-r--r--branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java25
-rw-r--r--branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java68
4 files changed, 114 insertions, 74 deletions
diff --git a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java
index 8991585d32..99af328964 100644
--- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java
+++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
index a316818b0f..2ed444506c 100644
--- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
+++ b/branches/sca-java-1.x/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,11 +27,14 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.assembly.ExtensionFactory;
import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
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.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
@@ -42,26 +45,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 SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
private static final QName EXPORT = new QName(SCA10_NS, "export");
private static final String NAMESPACE = "namespace";
-
+
private final NamespaceImportExportFactory factory;
private final Monitor monitor;
-
- public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ private final ExtensionFactory extensionFactory;
+ private final StAXArtifactProcessor<Object> extensionProcessor;
+ private final StAXAttributeProcessor<Object> attributeProcessor;
+
+ public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ StAXAttributeProcessor<Object> attributeProcessor,
+ Monitor monitor) {
this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
+ this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class);
+ this.extensionProcessor = extensionProcessor;
+ this.attributeProcessor = attributeProcessor;
this.monitor = monitor;
}
-
+
/**
* Report a warning.
- *
+ *
* @param problems
* @param message
* @param model
@@ -72,10 +84,10 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace
monitor.problem(problem);
}
}
-
+
/**
* Report a exception.
- *
+ *
* @param problems
* @param message
* @param model
@@ -90,43 +102,47 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace
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();
@@ -137,24 +153,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/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java
index 6d2a31f702..35e2d539d4 100644
--- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java
+++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
index a364823256..97fa65b7c2 100644
--- a/branches/sca-java-1.x/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
+++ b/branches/sca-java-1.x/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,11 +27,14 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.assembly.ExtensionFactory;
import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
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.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
@@ -42,28 +45,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 SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
-
+
private static final QName IMPORT = new QName(SCA10_NS, "import");
private static final String NAMESPACE = "namespace";
private static final String LOCATION = "location";
-
+
private final NamespaceImportExportFactory factory;
+ private final ExtensionFactory extensionFactory;
+ private final StAXArtifactProcessor<Object> extensionProcessor;
+ private final StAXAttributeProcessor<Object> attributeProcessor;
private final Monitor monitor;
-
- public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+
+ public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ StAXAttributeProcessor<Object> attributeProcessor,
+ Monitor monitor) {
this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
this.monitor = monitor;
+ this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class);
+ this.extensionProcessor = extensionProcessor;
+ this.attributeProcessor = attributeProcessor;
}
-
+
/**
* Report a warning.
- *
+ *
* @param problems
* @param message
* @param model
@@ -74,10 +86,10 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac
monitor.problem(problem);
}
}
-
+
/**
* Report a exception.
- *
+ *
* @param problems
* @param message
* @param model
@@ -88,11 +100,11 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac
monitor.problem(problem);
}
}
-
+
public QName getArtifactType() {
return IMPORT;
}
-
+
public Class<NamespaceImport> getModelType() {
return NamespaceImport.class;
}
@@ -103,36 +115,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();
@@ -143,22 +159,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();
}