summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/Calculator.composite53
-rw-r--r--java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/sca-contribution.xml31
-rw-r--r--java/sca/itest/validation/src/test/java/binding/jms/MissingActivationSpecNameTestCase.java2
-rw-r--r--java/sca/itest/validation/src/test/java/binding/jms/MissingConnectionFactoryNameTestCase.java2
-rw-r--r--java/sca/itest/validation/src/test/java/binding/jms/MissingResponseActivationSpecTestCase.java2
-rw-r--r--java/sca/itest/validation/src/test/java/binding/jms/MissingResponseConnectionFactoryTestCase.java2
-rw-r--r--java/sca/itest/validation/src/test/java/contribution/xml/MultipleCompositeErrorsTestCase.java64
-rw-r--r--java/sca/itest/validation/src/test/java/domain/CustomCompositeBuilder.java11
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java253
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java745
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java181
-rw-r--r--java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties2
-rw-r--r--java/sca/modules/assembly-xsd/src/main/resources/sca.xsd2
-rw-r--r--java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java74
-rw-r--r--java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java80
-rw-r--r--java/sca/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties1
-rw-r--r--java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java76
-rw-r--r--java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java82
-rw-r--r--java/sca/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties1
-rw-r--r--java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java80
-rw-r--r--java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java82
-rw-r--r--java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties1
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java3
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java114
-rw-r--r--java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties7
25 files changed, 1138 insertions, 813 deletions
diff --git a/java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/Calculator.composite b/java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/Calculator.composite
new file mode 100644
index 0000000000..70f91d1a7d
--- /dev/null
+++ b/java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/Calculator.composite
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://calc"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent">
+ <interface.java interface="calculator.warning.CalculatorService"/>
+ </service>
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.warning.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent"/>
+ <reference name="subtractService" target="SubtractServiceComponent"/>
+ <reference name="multiplyService" target="MultiplyServiceComponent"/>
+ <reference name="divideService" target="DivideServiceComponent"/>
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.warning.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.warning.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.warning.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.warning.DivideServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/sca-contribution.xml b/java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/sca-contribution.xml
new file mode 100644
index 0000000000..c1ff61f07c
--- /dev/null
+++ b/java/sca/itest/validation/src/main/resources/contribution/xml/MultipleCompositeErrors/sca-contribution.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<!-- to test TUSCANY-2631 -->
+
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample">
+ <deployable xmlns:ns1="http://temp"></deployable>
+ <deployable composite="ns1:aaaa" xmlns:ns1="http://temp"></deployable>
+ <deployable xmlns:ns1="http://temp"></deployable>
+ <deployable composite="ns1:dfsdf" xmlns:ns1="x"></deployable>
+ <deployable composite="ns1:dsfs" xmlns:ns1="http://temp"></deployable>
+</contribution> \ No newline at end of file
diff --git a/java/sca/itest/validation/src/test/java/binding/jms/MissingActivationSpecNameTestCase.java b/java/sca/itest/validation/src/test/java/binding/jms/MissingActivationSpecNameTestCase.java
index a974ef0db4..d38a88744f 100644
--- a/java/sca/itest/validation/src/test/java/binding/jms/MissingActivationSpecNameTestCase.java
+++ b/java/sca/itest/validation/src/test/java/binding/jms/MissingActivationSpecNameTestCase.java
@@ -52,7 +52,7 @@ public class MissingActivationSpecNameTestCase extends TestCase {
public void testCalculator() {
Monitor monitor = customDomain.getMonitorInstance();
- Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem();
+ Problem problem = ((DefaultLoggingMonitorImpl)monitor).getProblems().get(1);
assertNotNull(problem);
assertEquals("MissingActivationSpecName", problem.getMessageId());
diff --git a/java/sca/itest/validation/src/test/java/binding/jms/MissingConnectionFactoryNameTestCase.java b/java/sca/itest/validation/src/test/java/binding/jms/MissingConnectionFactoryNameTestCase.java
index adbaa50dc0..6999ae7969 100644
--- a/java/sca/itest/validation/src/test/java/binding/jms/MissingConnectionFactoryNameTestCase.java
+++ b/java/sca/itest/validation/src/test/java/binding/jms/MissingConnectionFactoryNameTestCase.java
@@ -52,7 +52,7 @@ public class MissingConnectionFactoryNameTestCase extends TestCase {
public void testCalculator() {
Monitor monitor = customDomain.getMonitorInstance();
- Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem();
+ Problem problem = ((DefaultLoggingMonitorImpl)monitor).getProblems().get(1);
assertNotNull(problem);
assertEquals("MissingConnectionFactoryName", problem.getMessageId());
diff --git a/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseActivationSpecTestCase.java b/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseActivationSpecTestCase.java
index 4bba6b74de..7333fc0f1e 100644
--- a/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseActivationSpecTestCase.java
+++ b/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseActivationSpecTestCase.java
@@ -52,7 +52,7 @@ public class MissingResponseActivationSpecTestCase extends TestCase {
public void testCalculator() {
Monitor monitor = customDomain.getMonitorInstance();
- Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem();
+ Problem problem = ((DefaultLoggingMonitorImpl)monitor).getProblems().get(1);
assertNotNull(problem);
assertEquals("MissingResponseActivationSpec", problem.getMessageId());
diff --git a/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseConnectionFactoryTestCase.java b/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseConnectionFactoryTestCase.java
index 8f4fc1a739..ca0ef9a294 100644
--- a/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseConnectionFactoryTestCase.java
+++ b/java/sca/itest/validation/src/test/java/binding/jms/MissingResponseConnectionFactoryTestCase.java
@@ -52,7 +52,7 @@ public class MissingResponseConnectionFactoryTestCase extends TestCase {
public void testCalculator() {
Monitor monitor = customDomain.getMonitorInstance();
- Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem();
+ Problem problem = ((DefaultLoggingMonitorImpl)monitor).getProblems().get(1);
assertNotNull(problem);
assertEquals("MissingResponseConnectionFactory", problem.getMessageId());
diff --git a/java/sca/itest/validation/src/test/java/contribution/xml/MultipleCompositeErrorsTestCase.java b/java/sca/itest/validation/src/test/java/contribution/xml/MultipleCompositeErrorsTestCase.java
new file mode 100644
index 0000000000..0a71ea06c7
--- /dev/null
+++ b/java/sca/itest/validation/src/test/java/contribution/xml/MultipleCompositeErrorsTestCase.java
@@ -0,0 +1,64 @@
+/*
+ * 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 contribution.xml;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.logging.impl.DefaultLoggingMonitorImpl;
+
+import domain.CustomCompositeBuilder;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class MultipleCompositeErrorsTestCase extends TestCase {
+
+ private CustomCompositeBuilder customDomain;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ customDomain = CustomCompositeBuilder.getInstance();
+ try {
+ customDomain.loadContribution("src/main/resources/contribution/xml/MultipleCompositeErrors/Calculator.composite",
+ "TestContribution",
+ "src/main/resources/contribution/xml/MultipleCompositeErrors/");
+ } catch (Exception ex){
+ //throw ex;
+ System.out.println("Got Exception");
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ //node.stop();
+ }
+
+ public void testCalculator() {
+ Monitor monitor = customDomain.getMonitorInstance();
+ Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem();
+
+ assertNotNull(problem);
+ assertEquals(5, monitor.getProblems().size());
+ assertEquals("AttributeCompositeMissing", problem.getMessageId());
+
+ }
+}
diff --git a/java/sca/itest/validation/src/test/java/domain/CustomCompositeBuilder.java b/java/sca/itest/validation/src/test/java/domain/CustomCompositeBuilder.java
index 8665bfd535..65814470a4 100644
--- a/java/sca/itest/validation/src/test/java/domain/CustomCompositeBuilder.java
+++ b/java/sca/itest/validation/src/test/java/domain/CustomCompositeBuilder.java
@@ -38,11 +38,14 @@ import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint;
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.URLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
@@ -111,7 +114,13 @@ public class CustomCompositeBuilder {
// Get XML input/output factories
modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
- outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+
+ // create the validating input factory out here just so that the
+ // monitor can be passed in
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, monitor);
+ modelFactories.addFactory(validatingInputFactory);
// Get contribution workspace and assembly model factories
workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class);
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
index 9727b89aab..3da39732e9 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
@@ -84,7 +84,7 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA
modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
}
- public ComponentType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ComponentType read(XMLStreamReader reader) throws ContributionReadException {
ComponentType componentType = null;
Service service = null;
Reference reference = null;
@@ -93,136 +93,143 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA
Callback callback = null;
QName name = null;
- // Read the componentType document
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- name = reader.getName();
-
- if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
-
- // Read a <componentType>
- componentType = assemblyFactory.createComponentType();
- componentType.setConstrainingType(readConstrainingType(reader));
-
- } else if (Constants.SERVICE_QNAME.equals(name)) {
-
- // Read a <service>
- service = assemblyFactory.createService();
- contract = service;
- service.setName(getString(reader, Constants.NAME));
- componentType.getServices().add(service);
- policyProcessor.readPolicies(service, reader);
-
- } else if (Constants.REFERENCE_QNAME.equals(name)) {
-
- // Read a <reference>
- reference = assemblyFactory.createReference();
- contract = reference;
- reference.setName(getString(reader, Constants.NAME));
- reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
- readMultiplicity(reference, reader);
- readTargets(reference, reader);
- componentType.getReferences().add(reference);
- policyProcessor.readPolicies(reference, reader);
-
- } else if (Constants.PROPERTY_QNAME.equals(name)) {
-
- // Read a <property>
- property = assemblyFactory.createProperty();
- readAbstractProperty(property, reader);
- policyProcessor.readPolicies(property, reader);
-
- // Read the property value
- Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
- property.setValue(value);
-
- componentType.getProperties().add(property);
-
- } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
-
- // Read an <implementation> element
- policyProcessor.readPolicies(componentType, reader);
-
- } else if (Constants.CALLBACK_QNAME.equals(name)) {
-
- // Read a <callback>
- callback = assemblyFactory.createCallback();
- contract.setCallback(callback);
- policyProcessor.readPolicies(callback, reader);
-
- } else if (OPERATION_QNAME.equals(name)) {
-
- // Read an <operation>
- Operation operation = new OperationImpl();
- operation.setName(getString(reader, NAME));
- operation.setUnresolved(true);
- if (callback != null) {
- policyProcessor.readPolicies(callback, operation, reader);
- } else {
- policyProcessor.readPolicies(contract, operation, reader);
- }
- } else {
-
- // Read an extension element
- Object extension = extensionProcessor.read(reader);
- if (extension != null) {
- if (extension instanceof InterfaceContract) {
-
- // <service><interface> and <reference><interface>
- contract.setInterfaceContract((InterfaceContract)extension);
-
- } else if (extension instanceof Binding) {
-
- // <service><binding> and <reference><binding>
- if (callback != null) {
- callback.getBindings().add((Binding)extension);
- } else {
- contract.getBindings().add((Binding)extension);
- }
+ try {
+ // Read the componentType document
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
+
+ if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
+
+ // Read a <componentType>
+ componentType = assemblyFactory.createComponentType();
+ componentType.setConstrainingType(readConstrainingType(reader));
+
+ } else if (Constants.SERVICE_QNAME.equals(name)) {
+
+ // Read a <service>
+ service = assemblyFactory.createService();
+ contract = service;
+ service.setName(getString(reader, Constants.NAME));
+ componentType.getServices().add(service);
+ policyProcessor.readPolicies(service, reader);
+
+ } else if (Constants.REFERENCE_QNAME.equals(name)) {
+
+ // Read a <reference>
+ reference = assemblyFactory.createReference();
+ contract = reference;
+ reference.setName(getString(reader, Constants.NAME));
+ reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
+ readMultiplicity(reference, reader);
+ readTargets(reference, reader);
+ componentType.getReferences().add(reference);
+ policyProcessor.readPolicies(reference, reader);
+
+ } else if (Constants.PROPERTY_QNAME.equals(name)) {
+
+ // Read a <property>
+ property = assemblyFactory.createProperty();
+ readAbstractProperty(property, reader);
+ policyProcessor.readPolicies(property, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
+ componentType.getProperties().add(property);
+
+ } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
+
+ // Read an <implementation> element
+ policyProcessor.readPolicies(componentType, reader);
+
+ } else if (Constants.CALLBACK_QNAME.equals(name)) {
+
+ // Read a <callback>
+ callback = assemblyFactory.createCallback();
+ contract.setCallback(callback);
+ policyProcessor.readPolicies(callback, reader);
+
+ } else if (OPERATION_QNAME.equals(name)) {
+
+ // Read an <operation>
+ Operation operation = new OperationImpl();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ if (callback != null) {
+ policyProcessor.readPolicies(callback, operation, reader);
} else {
-
- // Add the extension element to the current element
- if (callback != null) {
- callback.getExtensions().add(extension);
- } else if (contract != null) {
- contract.getExtensions().add(extension);
- } else if (property != null) {
- property.getExtensions().add(extension);
+ policyProcessor.readPolicies(contract, operation, reader);
+ }
+ } else {
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null) {
+ if (extension instanceof InterfaceContract) {
+
+ // <service><interface> and <reference><interface>
+ contract.setInterfaceContract((InterfaceContract)extension);
+
+ } else if (extension instanceof Binding) {
+
+ // <service><binding> and <reference><binding>
+ if (callback != null) {
+ callback.getBindings().add((Binding)extension);
+ } else {
+ contract.getBindings().add((Binding)extension);
+ }
} else {
- if (componentType instanceof Extensible) {
- ((Extensible)componentType).getExtensions().add(extension);
+
+ // Add the extension element to the current element
+ if (callback != null) {
+ callback.getExtensions().add(extension);
+ } else if (contract != null) {
+ contract.getExtensions().add(extension);
+ } else if (property != null) {
+ property.getExtensions().add(extension);
+ } else {
+ if (componentType instanceof Extensible) {
+ ((Extensible)componentType).getExtensions().add(extension);
+ }
}
}
}
}
- }
- break;
-
- case END_ELEMENT:
- name = reader.getName();
-
- // Clear current state when reading reaching end element
- if (SERVICE_QNAME.equals(name)) {
- service = null;
- contract = null;
- } else if (REFERENCE_QNAME.equals(name)) {
- reference = null;
- contract = null;
- } else if (PROPERTY_QNAME.equals(name)) {
- property = null;
- } else if (CALLBACK_QNAME.equals(name)) {
- callback = null;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ service = null;
+ contract = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ reference = null;
+ contract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ property = null;
+ } else if (CALLBACK_QNAME.equals(name)) {
+ callback = null;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
+
return componentType;
}
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
index 09ec7664ce..dfeb647380 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
@@ -149,7 +149,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt
super(contributionFactory, assemblyFactory, policyFactory, extensionProcessor, monitor);
}
- public Composite read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public Composite read(XMLStreamReader reader) throws ContributionReadException {
Composite composite = null;
Composite include = null;
Component component = null;
@@ -164,411 +164,418 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt
Callback callback = null;
QName name = null;
- // Read the composite document
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- name = reader.getName();
-
- if (COMPOSITE_QNAME.equals(name)) {
-
- // Read a <composite>
- composite = assemblyFactory.createComposite();
-
- composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
-
- if(!isSet(reader, TARGET_NAMESPACE)){
- // spec says that a composite must have a namespace
- warning("NoCompositeNamespace", composite, composite.getName().toString());
- }
-
- if(isSet(reader, AUTOWIRE)) {
- composite.setAutowire(getBoolean(reader, AUTOWIRE));
- }
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor);
-
- composite.setLocal(getBoolean(reader, LOCAL));
- composite.setConstrainingType(readConstrainingType(reader));
- policyProcessor.readPolicies(composite, reader);
-
- } else if (INCLUDE_QNAME.equals(name)) {
-
- // Read an <include>
- include = assemblyFactory.createComposite();
- include.setName(getQName(reader, NAME));
- include.setURI(getString(reader, URI));
- include.setUnresolved(true);
- composite.getIncludes().add(include);
-
- } else if (SERVICE_QNAME.equals(name)) {
- if (component != null) {
-
- // Read a <component><service>
- componentService = assemblyFactory.createComponentService();
- contract = componentService;
- componentService.setName(getString(reader, NAME));
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor);
-
- component.getServices().add(componentService);
- policyProcessor.readPolicies(contract, reader);
- } else {
-
- // Read a <composite><service>
- compositeService = assemblyFactory.createCompositeService();
- contract = compositeService;
- compositeService.setName(getString(reader, NAME));
-
- String promoted = getString(reader, PROMOTE);
- if (promoted != null) {
- String promotedComponentName;
- String promotedServiceName;
- int s = promoted.indexOf('/');
- if (s == -1) {
- promotedComponentName = promoted;
- promotedServiceName = null;
- } else {
- promotedComponentName = promoted.substring(0, s);
- promotedServiceName = promoted.substring(s + 1);
- }
+ try {
+ // Read the composite document
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
- Component promotedComponent = assemblyFactory.createComponent();
- promotedComponent.setUnresolved(true);
- promotedComponent.setName(promotedComponentName);
- compositeService.setPromotedComponent(promotedComponent);
+ if (COMPOSITE_QNAME.equals(name)) {
- ComponentService promotedService = assemblyFactory.createComponentService();
- promotedService.setUnresolved(true);
- promotedService.setName(promotedServiceName);
- compositeService.setPromotedService(promotedService);
+ // Read a <composite>
+ composite = assemblyFactory.createComposite();
+
+ composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+
+ if(!isSet(reader, TARGET_NAMESPACE)){
+ // spec says that a composite must have a namespace
+ warning("NoCompositeNamespace", composite, composite.getName().toString());
}
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor);
-
- composite.getServices().add(compositeService);
- policyProcessor.readPolicies(contract, reader);
- }
-
- } else if (REFERENCE_QNAME.equals(name)) {
- if (component != null) {
- // Read a <component><reference>
- componentReference = assemblyFactory.createComponentReference();
- contract = componentReference;
- componentReference.setName(getString(reader, NAME));
- readMultiplicity(componentReference, reader);
- if (isSet(reader, AUTOWIRE)) {
- componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
+
+ if(isSet(reader, AUTOWIRE)) {
+ composite.setAutowire(getBoolean(reader, AUTOWIRE));
}
- readTargets(componentReference, reader);
- componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
//handle extension attributes
- this.readExtendedAttributes(reader, name, componentReference, extensionAttributeProcessor);
-
- component.getReferences().add(componentReference);
- policyProcessor.readPolicies(contract, reader);
- } else {
- // Read a <composite><reference>
- compositeReference = assemblyFactory.createCompositeReference();
- contract = compositeReference;
- compositeReference.setName(getString(reader, NAME));
- readMultiplicity(compositeReference, reader);
- readTargets(compositeReference, reader);
- String promote = reader.getAttributeValue(null, Constants.PROMOTE);
- if (promote != null) {
- for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
- ComponentReference promotedReference =
- assemblyFactory.createComponentReference();
- promotedReference.setUnresolved(true);
- promotedReference.setName(tokens.nextToken());
- compositeReference.getPromotedReferences().add(promotedReference);
+ this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor);
+
+ composite.setLocal(getBoolean(reader, LOCAL));
+ composite.setConstrainingType(readConstrainingType(reader));
+ policyProcessor.readPolicies(composite, reader);
+
+ } else if (INCLUDE_QNAME.equals(name)) {
+
+ // Read an <include>
+ include = assemblyFactory.createComposite();
+ include.setName(getQName(reader, NAME));
+ include.setURI(getString(reader, URI));
+ include.setUnresolved(true);
+ composite.getIncludes().add(include);
+
+ } else if (SERVICE_QNAME.equals(name)) {
+ if (component != null) {
+
+ // Read a <component><service>
+ componentService = assemblyFactory.createComponentService();
+ contract = componentService;
+ componentService.setName(getString(reader, NAME));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor);
+
+ component.getServices().add(componentService);
+ policyProcessor.readPolicies(contract, reader);
+ } else {
+
+ // Read a <composite><service>
+ compositeService = assemblyFactory.createCompositeService();
+ contract = compositeService;
+ compositeService.setName(getString(reader, NAME));
+
+ String promoted = getString(reader, PROMOTE);
+ if (promoted != null) {
+ String promotedComponentName;
+ String promotedServiceName;
+ int s = promoted.indexOf('/');
+ if (s == -1) {
+ promotedComponentName = promoted;
+ promotedServiceName = null;
+ } else {
+ promotedComponentName = promoted.substring(0, s);
+ promotedServiceName = promoted.substring(s + 1);
+ }
+
+ Component promotedComponent = assemblyFactory.createComponent();
+ promotedComponent.setUnresolved(true);
+ promotedComponent.setName(promotedComponentName);
+ compositeService.setPromotedComponent(promotedComponent);
+
+ ComponentService promotedService = assemblyFactory.createComponentService();
+ promotedService.setUnresolved(true);
+ promotedService.setName(promotedServiceName);
+ compositeService.setPromotedService(promotedService);
}
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor);
+
+ composite.getServices().add(compositeService);
+ policyProcessor.readPolicies(contract, reader);
}
- compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
-
- composite.getReferences().add(compositeReference);
- policyProcessor.readPolicies(contract, reader);
- }
-
- } else if (PROPERTY_QNAME.equals(name)) {
- if (component != null) {
-
- // Read a <component><property>
- componentProperty = assemblyFactory.createComponentProperty();
- property = componentProperty;
- String source = getString(reader, SOURCE);
- if(source!=null) {
- source = source.trim();
+
+ } else if (REFERENCE_QNAME.equals(name)) {
+ if (component != null) {
+ // Read a <component><reference>
+ componentReference = assemblyFactory.createComponentReference();
+ contract = componentReference;
+ componentReference.setName(getString(reader, NAME));
+ readMultiplicity(componentReference, reader);
+ if (isSet(reader, AUTOWIRE)) {
+ componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
+ }
+ readTargets(componentReference, reader);
+ componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, componentReference, extensionAttributeProcessor);
+
+ component.getReferences().add(componentReference);
+ policyProcessor.readPolicies(contract, reader);
+ } else {
+ // Read a <composite><reference>
+ compositeReference = assemblyFactory.createCompositeReference();
+ contract = compositeReference;
+ compositeReference.setName(getString(reader, NAME));
+ readMultiplicity(compositeReference, reader);
+ readTargets(compositeReference, reader);
+ String promote = reader.getAttributeValue(null, Constants.PROMOTE);
+ if (promote != null) {
+ for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
+ ComponentReference promotedReference =
+ assemblyFactory.createComponentReference();
+ promotedReference.setUnresolved(true);
+ promotedReference.setName(tokens.nextToken());
+ compositeReference.getPromotedReferences().add(promotedReference);
+ }
+ }
+ compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
+
+ composite.getReferences().add(compositeReference);
+ policyProcessor.readPolicies(contract, reader);
}
- componentProperty.setSource(source);
- if (source != null) {
- // $<name>/...
- if (source.charAt(0) == '$') {
- int index = source.indexOf('/');
- if (index == -1) {
- // Tolerating $prop
- source = source + "/";
- index = source.length() - 1;
+
+ } else if (PROPERTY_QNAME.equals(name)) {
+ if (component != null) {
+
+ // Read a <component><property>
+ componentProperty = assemblyFactory.createComponentProperty();
+ property = componentProperty;
+ String source = getString(reader, SOURCE);
+ if(source!=null) {
+ source = source.trim();
+ }
+ componentProperty.setSource(source);
+ if (source != null) {
+ // $<name>/...
+ if (source.charAt(0) == '$') {
+ int index = source.indexOf('/');
+ if (index == -1) {
+ // Tolerating $prop
+ source = source + "/";
+ index = source.length() - 1;
+ }
+ source = source.substring(index + 1);
+ if ("".equals(source)) {
+ source = ".";
+ }
}
- source = source.substring(index + 1);
- if ("".equals(source)) {
- source = ".";
+ XPath xpath = xPathFactory.newXPath();
+ xpath.setNamespaceContext(reader.getNamespaceContext());
+ try {
+ componentProperty.setSourceXPathExpression(xpath.compile(source));
+ } catch (XPathExpressionException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", xpath, ce);
+ //throw ce;
}
}
- XPath xpath = xPathFactory.newXPath();
- xpath.setNamespaceContext(reader.getNamespaceContext());
- try {
- componentProperty.setSourceXPathExpression(xpath.compile(source));
- } catch (XPathExpressionException e) {
- ContributionReadException ce = new ContributionReadException(e);
- error("ContributionReadException", xpath, ce);
- //throw ce;
- }
+ componentProperty.setFile(getString(reader, FILE));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, componentProperty, extensionAttributeProcessor);
+
+ policyProcessor.readPolicies(property, reader);
+ readAbstractProperty(componentProperty, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
+ component.getProperties().add(componentProperty);
+ } else {
+
+ // Read a <composite><property>
+ property = assemblyFactory.createProperty();
+ policyProcessor.readPolicies(property, reader);
+ readAbstractProperty(property, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
+ composite.getProperties().add(property);
+ }
+
+ // TUSCANY-1949
+ // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
+ if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
+ property = null;
+ componentProperty = null;
+ }
+
+ } else if (COMPONENT_QNAME.equals(name)) {
+
+ // Read a <component>
+ component = assemblyFactory.createComponent();
+ component.setName(getString(reader, NAME));
+ if (isSet(reader, AUTOWIRE)) {
+ component.setAutowire(getBoolean(reader, AUTOWIRE));
+ }
+ if (isSet(reader, URI)) {
+ component.setURI(getString(reader, URI));
}
- componentProperty.setFile(getString(reader, FILE));
//handle extension attributes
- this.readExtendedAttributes(reader, name, componentProperty, extensionAttributeProcessor);
-
- policyProcessor.readPolicies(property, reader);
- readAbstractProperty(componentProperty, reader);
+ this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor);
- // Read the property value
- Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
- property.setValue(value);
+ component.setConstrainingType(readConstrainingType(reader));
+ composite.getComponents().add(component);
+ policyProcessor.readPolicies(component, reader);
+
+ } else if (WIRE_QNAME.equals(name)) {
+
+ // Read a <wire>
+ wire = assemblyFactory.createWire();
+ ComponentReference source = assemblyFactory.createComponentReference();
+ source.setUnresolved(true);
+ source.setName(getString(reader, SOURCE));
+ wire.setSource(source);
+
+ ComponentService target = assemblyFactory.createComponentService();
+ target.setUnresolved(true);
+ target.setName(getString(reader, TARGET));
+ wire.setTarget(target);
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor);
+
+ composite.getWires().add(wire);
+ policyProcessor.readPolicies(wire, reader);
+
+ } else if (CALLBACK_QNAME.equals(name)) {
+
+ // Read a <callback>
+ callback = assemblyFactory.createCallback();
+ contract.setCallback(callback);
- component.getProperties().add(componentProperty);
- } else {
-
- // Read a <composite><property>
- property = assemblyFactory.createProperty();
- policyProcessor.readPolicies(property, reader);
- readAbstractProperty(property, reader);
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor);
- // Read the property value
- Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
- property.setValue(value);
+ policyProcessor.readPolicies(callback, reader);
+
+ } else if (OPERATION_QNAME.equals(name)) {
+
+ // Read an <operation>
+ ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ if (callback != null) {
+ policyProcessor.readPolicies(operation, reader);
+ } else {
+ policyProcessor.readPolicies(operation, reader);
+ }
- composite.getProperties().add(property);
- }
-
- // TUSCANY-1949
- // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
- if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
- property = null;
- componentProperty = null;
- }
-
- } else if (COMPONENT_QNAME.equals(name)) {
-
- // Read a <component>
- component = assemblyFactory.createComponent();
- component.setName(getString(reader, NAME));
- if (isSet(reader, AUTOWIRE)) {
- component.setAutowire(getBoolean(reader, AUTOWIRE));
- }
- if (isSet(reader, URI)) {
- component.setURI(getString(reader, URI));
- }
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor);
-
- component.setConstrainingType(readConstrainingType(reader));
- composite.getComponents().add(component);
- policyProcessor.readPolicies(component, reader);
-
- } else if (WIRE_QNAME.equals(name)) {
-
- // Read a <wire>
- wire = assemblyFactory.createWire();
- ComponentReference source = assemblyFactory.createComponentReference();
- source.setUnresolved(true);
- source.setName(getString(reader, SOURCE));
- wire.setSource(source);
-
- ComponentService target = assemblyFactory.createComponentService();
- target.setUnresolved(true);
- target.setName(getString(reader, TARGET));
- wire.setTarget(target);
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor);
-
- composite.getWires().add(wire);
- policyProcessor.readPolicies(wire, reader);
-
- } else if (CALLBACK_QNAME.equals(name)) {
-
- // Read a <callback>
- callback = assemblyFactory.createCallback();
- contract.setCallback(callback);
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor);
-
- policyProcessor.readPolicies(callback, reader);
-
- } else if (OPERATION_QNAME.equals(name)) {
-
- // Read an <operation>
- ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
- operation.setName(getString(reader, NAME));
- operation.setUnresolved(true);
- if (callback != null) {
- policyProcessor.readPolicies(operation, reader);
+ OperationsConfigurator opConfigurator = null;
+ if ( compositeService != null ) {
+ opConfigurator = compositeService;
+ } else if ( componentService != null ) {
+ opConfigurator = componentService;
+ } else if ( compositeReference != null ) {
+ opConfigurator = compositeReference;
+ } else if ( componentReference != null ) {
+ opConfigurator = componentReference;
+ }
+
+ opConfigurator.getConfiguredOperations().add(operation);
+ } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
+
+ // Read an implementation.composite
+ Composite implementation = assemblyFactory.createComposite();
+ implementation.setName(getQName(reader, NAME));
+ implementation.setUnresolved(true);
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor);
+
+ component.setImplementation(implementation);
+ policyProcessor.readPolicies(implementation, reader);
} else {
- policyProcessor.readPolicies(operation, reader);
- }
-
- OperationsConfigurator opConfigurator = null;
- if ( compositeService != null ) {
- opConfigurator = compositeService;
- } else if ( componentService != null ) {
- opConfigurator = componentService;
- } else if ( compositeReference != null ) {
- opConfigurator = compositeReference;
- } else if ( componentReference != null ) {
- opConfigurator = componentReference;
- }
-
- opConfigurator.getConfiguredOperations().add(operation);
- } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
-
- // Read an implementation.composite
- Composite implementation = assemblyFactory.createComposite();
- implementation.setName(getQName(reader, NAME));
- implementation.setUnresolved(true);
-
- //handle extension attributes
- this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor);
-
- component.setImplementation(implementation);
- policyProcessor.readPolicies(implementation, reader);
- } else {
-
- // Read an extension element
- Object extension = extensionProcessor.read(reader);
- if (extension != null) {
- if (extension instanceof InterfaceContract) {
-
- // <service><interface> and
- // <reference><interface>
- if (contract != null) {
- contract.setInterfaceContract((InterfaceContract)extension);
- } else {
- if (name.getNamespaceURI().equals(SCA10_NS)) {
- error("UnexpectedInterfaceElement", extension);
- //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null) {
+ if (extension instanceof InterfaceContract) {
+
+ // <service><interface> and
+ // <reference><interface>
+ if (contract != null) {
+ contract.setInterfaceContract((InterfaceContract)extension);
} else {
- composite.getExtensions().add(extension);
+ if (name.getNamespaceURI().equals(SCA10_NS)) {
+ error("UnexpectedInterfaceElement", extension);
+ //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
+ } else {
+ composite.getExtensions().add(extension);
+ }
}
- }
- } else if (extension instanceof Binding) {
- if ( extension instanceof PolicySetAttachPoint ) {
- IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
- bindingType.setName(name);
- bindingType.setUnresolved(true);
- ((PolicySetAttachPoint)extension).setType(bindingType);
- }
- // <service><binding> and
- // <reference><binding>
- if (callback != null) {
- callback.getBindings().add((Binding)extension);
- } else {
- if (contract != null) {
- contract.getBindings().add((Binding)extension);
+ } else if (extension instanceof Binding) {
+ if ( extension instanceof PolicySetAttachPoint ) {
+ IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
+ bindingType.setName(name);
+ bindingType.setUnresolved(true);
+ ((PolicySetAttachPoint)extension).setType(bindingType);
+ }
+ // <service><binding> and
+ // <reference><binding>
+ if (callback != null) {
+ callback.getBindings().add((Binding)extension);
+ } else {
+ if (contract != null) {
+ contract.getBindings().add((Binding)extension);
+ } else {
+ if (name.getNamespaceURI().equals(SCA10_NS)) {
+ error("UnexpectedBindingElement", extension);
+ //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
+ } else {
+ composite.getExtensions().add(extension);
+ }
+ }
+ }
+
+ } else if (extension instanceof Implementation) {
+ if ( extension instanceof PolicySetAttachPoint ) {
+ IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
+ implType.setName(name);
+ implType.setUnresolved(true);
+ ((PolicySetAttachPoint)extension).setType(implType);
+ }
+ // <component><implementation>
+ if (component != null) {
+ component.setImplementation((Implementation)extension);
} else {
if (name.getNamespaceURI().equals(SCA10_NS)) {
- error("UnexpectedBindingElement", extension);
- //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
+ error("UnexpectedImplementationElement", extension);
+ //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
} else {
composite.getExtensions().add(extension);
}
}
- }
-
- } else if (extension instanceof Implementation) {
- if ( extension instanceof PolicySetAttachPoint ) {
- IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
- implType.setName(name);
- implType.setUnresolved(true);
- ((PolicySetAttachPoint)extension).setType(implType);
- }
- // <component><implementation>
- if (component != null) {
- component.setImplementation((Implementation)extension);
} else {
- if (name.getNamespaceURI().equals(SCA10_NS)) {
- error("UnexpectedImplementationElement", extension);
- //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
+
+ // Add the extension element to the current
+ // element
+ if (callback != null) {
+ callback.getExtensions().add(extension);
+ } else if (contract != null) {
+ contract.getExtensions().add(extension);
+ } else if (property != null) {
+ property.getExtensions().add(extension);
+ } else if (component != null) {
+ component.getExtensions().add(extension);
} else {
composite.getExtensions().add(extension);
}
}
- } else {
-
- // Add the extension element to the current
- // element
- if (callback != null) {
- callback.getExtensions().add(extension);
- } else if (contract != null) {
- contract.getExtensions().add(extension);
- } else if (property != null) {
- property.getExtensions().add(extension);
- } else if (component != null) {
- component.getExtensions().add(extension);
- } else {
- composite.getExtensions().add(extension);
- }
}
}
- }
- break;
-
- case XMLStreamConstants.CHARACTERS:
- break;
-
- case END_ELEMENT:
- name = reader.getName();
-
- // Clear current state when reading reaching end element
- if (SERVICE_QNAME.equals(name)) {
- componentService = null;
- compositeService = null;
- contract = null;
- } else if (INCLUDE_QNAME.equals(name)) {
- include = null;
- } else if (REFERENCE_QNAME.equals(name)) {
- componentReference = null;
- compositeReference = null;
- contract = null;
- } else if (PROPERTY_QNAME.equals(name)) {
- componentProperty = null;
- property = null;
- } else if (COMPONENT_QNAME.equals(name)) {
- component = null;
- } else if (WIRE_QNAME.equals(name)) {
- wire = null;
- } else if (CALLBACK_QNAME.equals(name)) {
- callback = null;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ break;
+
+ case XMLStreamConstants.CHARACTERS:
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ componentService = null;
+ compositeService = null;
+ contract = null;
+ } else if (INCLUDE_QNAME.equals(name)) {
+ include = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ componentReference = null;
+ compositeReference = null;
+ contract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ componentProperty = null;
+ property = null;
+ } else if (COMPONENT_QNAME.equals(name)) {
+ component = null;
+ } else if (WIRE_QNAME.equals(name)) {
+ wire = null;
+ } else if (CALLBACK_QNAME.equals(name)) {
+ callback = null;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
+
return composite;
}
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
index 334b6c6b97..35a1c553b2 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
@@ -77,7 +77,7 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements
modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
}
- public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException {
ConstrainingType constrainingType = null;
AbstractService abstractService = null;
AbstractReference abstractReference = null;
@@ -85,100 +85,107 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements
AbstractContract abstractContract = null;
QName name = null;
- // Read the constrainingType document
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
-
- case START_ELEMENT:
- name = reader.getName();
-
- // Read a <constrainingType>
- if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
- constrainingType = assemblyFactory.createConstrainingType();
- constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
- policyProcessor.readPolicies(constrainingType, reader);
-
- } else if (Constants.SERVICE_QNAME.equals(name)) {
-
- // Read a <service>
- abstractService = assemblyFactory.createAbstractService();
- abstractContract = abstractService;
- abstractService.setName(getString(reader, Constants.NAME));
- constrainingType.getServices().add(abstractService);
- policyProcessor.readPolicies(abstractService, reader);
-
- } else if (Constants.REFERENCE_QNAME.equals(name)) {
-
- // Read a <reference>
- abstractReference = assemblyFactory.createAbstractReference();
- abstractContract = abstractReference;
- abstractReference.setName(getString(reader, Constants.NAME));
- readMultiplicity(abstractReference, reader);
- constrainingType.getReferences().add(abstractReference);
- policyProcessor.readPolicies(abstractReference, reader);
-
- } else if (Constants.PROPERTY_QNAME.equals(name)) {
-
- // Read a <property>
- abstractProperty = assemblyFactory.createAbstractProperty();
- readAbstractProperty(abstractProperty, reader);
-
- // Read the property value
- Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), reader);
- abstractProperty.setValue(value);
-
- constrainingType.getProperties().add(abstractProperty);
- policyProcessor.readPolicies(abstractProperty, reader);
-
- } else if (OPERATION_QNAME.equals(name)) {
-
- // Read an <operation>
- Operation operation = new OperationImpl();
- operation.setName(getString(reader, NAME));
- operation.setUnresolved(true);
- policyProcessor.readPolicies(abstractContract, operation, reader);
+ try {
+ // Read the constrainingType document
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+
+ case START_ELEMENT:
+ name = reader.getName();
- } else {
-
- // Read an extension element
- Object extension = extensionProcessor.read(reader);
- if (extension instanceof InterfaceContract) {
+ // Read a <constrainingType>
+ if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
+ constrainingType = assemblyFactory.createConstrainingType();
+ constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+ policyProcessor.readPolicies(constrainingType, reader);
+
+ } else if (Constants.SERVICE_QNAME.equals(name)) {
+
+ // Read a <service>
+ abstractService = assemblyFactory.createAbstractService();
+ abstractContract = abstractService;
+ abstractService.setName(getString(reader, Constants.NAME));
+ constrainingType.getServices().add(abstractService);
+ policyProcessor.readPolicies(abstractService, reader);
+
+ } else if (Constants.REFERENCE_QNAME.equals(name)) {
+
+ // Read a <reference>
+ abstractReference = assemblyFactory.createAbstractReference();
+ abstractContract = abstractReference;
+ abstractReference.setName(getString(reader, Constants.NAME));
+ readMultiplicity(abstractReference, reader);
+ constrainingType.getReferences().add(abstractReference);
+ policyProcessor.readPolicies(abstractReference, reader);
+
+ } else if (Constants.PROPERTY_QNAME.equals(name)) {
+
+ // Read a <property>
+ abstractProperty = assemblyFactory.createAbstractProperty();
+ readAbstractProperty(abstractProperty, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), reader);
+ abstractProperty.setValue(value);
+
+ constrainingType.getProperties().add(abstractProperty);
+ policyProcessor.readPolicies(abstractProperty, reader);
+
+ } else if (OPERATION_QNAME.equals(name)) {
+
+ // Read an <operation>
+ Operation operation = new OperationImpl();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ policyProcessor.readPolicies(abstractContract, operation, reader);
- // <service><interface> and <reference><interface>
- abstractContract.setInterfaceContract((InterfaceContract)extension);
} else {
-
- // Add the extension element to the current element
- if (abstractContract != null) {
- abstractContract.getExtensions().add(extension);
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension instanceof InterfaceContract) {
+
+ // <service><interface> and <reference><interface>
+ abstractContract.setInterfaceContract((InterfaceContract)extension);
} else {
- constrainingType.getExtensions().add(extension);
+
+ // Add the extension element to the current element
+ if (abstractContract != null) {
+ abstractContract.getExtensions().add(extension);
+ } else {
+ constrainingType.getExtensions().add(extension);
+ }
+
}
-
}
- }
- break;
-
- case END_ELEMENT:
- name = reader.getName();
-
- // Clear current state when reading reaching end element
- if (SERVICE_QNAME.equals(name)) {
- abstractService = null;
- abstractContract = null;
- } else if (REFERENCE_QNAME.equals(name)) {
- abstractReference = null;
- abstractContract = null;
- } else if (PROPERTY_QNAME.equals(name)) {
- abstractProperty = null;
- }
- break;
- }
- if (reader.hasNext()) {
- reader.next();
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ abstractService = null;
+ abstractContract = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ abstractReference = null;
+ abstractContract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ abstractProperty = null;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
+
return constrainingType;
}
diff --git a/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties b/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties
index 95edf89e30..8cc5e5a5ec 100644
--- a/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties
+++ b/java/sca/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties
@@ -26,4 +26,4 @@ PolicyImplValidationException = PolicyValidation exception when processing imple
PolicyServiceValidationException = PolicyValidation exceptions when processing service/reference {0} in {1}. Error is {2}
ContributionReadException = ContributionReadException occured due to : {0}
ContributionWriteException = ContributionWriteException occured due to : {0}
-
+XMLStreamException = XMLStreamException occured due to : {0}
diff --git a/java/sca/modules/assembly-xsd/src/main/resources/sca.xsd b/java/sca/modules/assembly-xsd/src/main/resources/sca.xsd
index 88edad794c..e4471a4f51 100644
--- a/java/sca/modules/assembly-xsd/src/main/resources/sca.xsd
+++ b/java/sca/modules/assembly-xsd/src/main/resources/sca.xsd
@@ -18,6 +18,8 @@
<include schemaLocation="sca-contributions.xsd"/>
+ <include schemaLocation="sca-contributions.xsd"/>
+
<include schemaLocation="sca-definitions.xsd"/>
<include schemaLocation="sca-policy.xsd"/>
diff --git a/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
index 9f6ff52289..d7c3817b68 100644
--- a/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
+++ b/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
@@ -74,6 +74,20 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
monitor.problem(problem);
}
}
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return EXPORT_JAVA;
@@ -86,38 +100,44 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
/**
* Process <export package=""/>
*/
- public JavaExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public JavaExport read(XMLStreamReader reader) throws ContributionReadException {
JavaExport javaExport = this.factory.createJavaExport();
QName element = null;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- element = reader.getName();
-
- // Read <export.java>
- if (EXPORT_JAVA.equals(element)) {
- String packageName = reader.getAttributeValue(null, PACKAGE);
- if (packageName == null) {
- error("AttributePackageMissing", reader);
- //throw new ContributionReadException("Attribute 'package' is missing");
- } else
- javaExport.setPackage(packageName);
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (EXPORT_JAVA.equals(reader.getName())) {
- return javaExport;
- }
- break;
- }
-
- //Read the next element
- if (reader.hasNext()) {
- reader.next();
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <export.java>
+ if (EXPORT_JAVA.equals(element)) {
+ String packageName = reader.getAttributeValue(null, PACKAGE);
+ if (packageName == null) {
+ error("AttributePackageMissing", reader);
+ //throw new ContributionReadException("Attribute 'package' is missing");
+ } else
+ javaExport.setPackage(packageName);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (EXPORT_JAVA.equals(reader.getName())) {
+ return javaExport;
+ }
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return javaExport;
}
diff --git a/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
index d027d75b32..7812c25c1c 100644
--- a/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
+++ b/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
@@ -75,6 +75,20 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
monitor.problem(problem);
}
}
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return IMPORT_JAVA;
@@ -87,41 +101,47 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
/**
* Process <import.java package="" location=""/>
*/
- public JavaImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public JavaImport read(XMLStreamReader reader) throws ContributionReadException {
JavaImport javaImport = this.factory.createJavaImport();
QName element = null;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- element = reader.getName();
-
- // Read <import.java>
- if (IMPORT_JAVA.equals(element)) {
- String packageName = reader.getAttributeValue(null, PACKAGE);
- if (packageName == null) {
- error("AttributePackageMissing", reader);
- //throw new ContributionReadException("Attribute 'package' is missing");
- } else
- javaImport.setPackage(packageName);
-
- String location = reader.getAttributeValue(null, LOCATION);
- javaImport.setLocation(location);
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (IMPORT_JAVA.equals(reader.getName())) {
- return javaImport;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <import.java>
+ if (IMPORT_JAVA.equals(element)) {
+ String packageName = reader.getAttributeValue(null, PACKAGE);
+ if (packageName == null) {
+ error("AttributePackageMissing", reader);
+ //throw new ContributionReadException("Attribute 'package' is missing");
+ } else
+ javaImport.setPackage(packageName);
+
+ String location = reader.getAttributeValue(null, LOCATION);
+ javaImport.setLocation(location);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (IMPORT_JAVA.equals(reader.getName())) {
+ return javaImport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return javaImport;
}
diff --git a/java/sca/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties b/java/sca/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties
index 70b58f75c0..09fc3e9fff 100644
--- a/java/sca/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties
+++ b/java/sca/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties
@@ -19,4 +19,5 @@
#
#
AttributePackageMissing = Attribute 'package' is missing
+XMLStreamException = XMLStreamException occured due to : {0}
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 64862301c1..a316818b0f 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
@@ -72,6 +72,20 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace
monitor.problem(problem);
}
}
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return EXPORT;
@@ -84,39 +98,45 @@ public class NamespaceExportProcessor implements StAXArtifactProcessor<Namespace
/**
* Process <export namespace=""/>
*/
- public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException {
NamespaceExport namespaceExport = this.factory.createNamespaceExport();
QName element = null;
- 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
- namespaceExport.setNamespace(ns);
- }
-
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (EXPORT.equals(reader.getName())) {
- return namespaceExport;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ 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
+ namespaceExport.setNamespace(ns);
+ }
+
+ 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("XMLStreamException", reader, ex);
+ }
return namespaceExport;
}
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 829e5fa43f..a364823256 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
@@ -75,6 +75,20 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac
}
}
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
public QName getArtifactType() {
return IMPORT;
}
@@ -86,43 +100,49 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor<Namespac
/**
* Process <import namespace="" location=""/>
*/
- public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException {
NamespaceImport namespaceImport = this.factory.createNamespaceImport();
QName element;
- 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
- namespaceImport.setNamespace(ns);
-
- String location = reader.getAttributeValue(null, LOCATION);
- if (location != null) {
- namespaceImport.setLocation(location);
+ 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
+ namespaceImport.setNamespace(ns);
+
+ String location = reader.getAttributeValue(null, LOCATION);
+ if (location != null) {
+ namespaceImport.setLocation(location);
+ }
}
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (IMPORT.equals(reader.getName())) {
- return namespaceImport;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ 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("XMLStreamException", reader, ex);
+ }
return namespaceImport;
}
diff --git a/java/sca/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties b/java/sca/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties
index c7ddba3c3d..c1cbd06e7f 100644
--- a/java/sca/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties
+++ b/java/sca/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties
@@ -19,4 +19,5 @@
#
#
AttributeNameSpaceMissing = Attribute 'namespace' is missing
+XMLStreamException = XMLStreamException occured due to : {0}
diff --git a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java
index 68d5d4761e..cf99aee389 100644
--- a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java
+++ b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java
@@ -68,10 +68,24 @@ public class ResourceExportProcessor implements StAXArtifactProcessor<ResourceEx
*/
private void error(String message, Object model, Object... messageParameters) {
if (monitor != null) {
- Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
- monitor.problem(problem);
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
}
}
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return EXPORT_RESOURCE;
@@ -84,39 +98,45 @@ public class ResourceExportProcessor implements StAXArtifactProcessor<ResourceEx
/**
* Process <export.resource uri=""/>
*/
- public ResourceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ResourceExport read(XMLStreamReader reader) throws ContributionReadException {
ResourceExport resourceExport = this.factory.createResourceExport();
QName element = null;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- element = reader.getName();
-
- // Read <export.resource>
- if (EXPORT_RESOURCE.equals(element)) {
- String uri = reader.getAttributeValue(null, URI);
- if (uri == null) {
- error("AttributeURIMissing", reader);
- //throw new ContributionReadException("Attribute 'uri' is missing");
- } else
- resourceExport.setURI(uri);
- }
-
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (EXPORT_RESOURCE.equals(reader.getName())) {
- return resourceExport;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <export.resource>
+ if (EXPORT_RESOURCE.equals(element)) {
+ String uri = reader.getAttributeValue(null, URI);
+ if (uri == null) {
+ error("AttributeURIMissing", reader);
+ //throw new ContributionReadException("Attribute 'uri' is missing");
+ } else
+ resourceExport.setURI(uri);
+ }
+
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (EXPORT_RESOURCE.equals(reader.getName())) {
+ return resourceExport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return resourceExport;
}
diff --git a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java
index 8b2fc44a1c..bc3fb7fa5f 100644
--- a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java
+++ b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java
@@ -74,6 +74,20 @@ public class ResourceImportProcessor implements StAXArtifactProcessor<ResourceI
monitor.problem(problem);
}
}
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return IMPORT_RESOURCE;
@@ -86,43 +100,49 @@ public class ResourceImportProcessor implements StAXArtifactProcessor<ResourceI
/**
* Process <import.resource uri="" location=""/>
*/
- public ResourceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ResourceImport read(XMLStreamReader reader) throws ContributionReadException {
ResourceImport resourceImport = this.factory.createResourceImport();
QName element;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- element = reader.getName();
-
- // Read <import>
- if (IMPORT_RESOURCE.equals(element)) {
- String uri = reader.getAttributeValue(null, URI);
- if (uri == null) {
- error("AttributeURIMissing", reader);
- //throw new ContributionReadException("Attribute 'uri' is missing");
- } else
- resourceImport.setURI(uri);
-
- String location = reader.getAttributeValue(null, LOCATION);
- if (location != null) {
- resourceImport.setLocation(location);
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <import>
+ if (IMPORT_RESOURCE.equals(element)) {
+ String uri = reader.getAttributeValue(null, URI);
+ if (uri == null) {
+ error("AttributeURIMissing", reader);
+ //throw new ContributionReadException("Attribute 'uri' is missing");
+ } else
+ resourceImport.setURI(uri);
+
+ String location = reader.getAttributeValue(null, LOCATION);
+ if (location != null) {
+ resourceImport.setLocation(location);
+ }
}
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (IMPORT_RESOURCE.equals(reader.getName())) {
- return resourceImport;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (IMPORT_RESOURCE.equals(reader.getName())) {
+ return resourceImport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return resourceImport;
}
diff --git a/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties b/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties
index 58ee8153f8..9df66cce52 100644
--- a/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties
+++ b/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties
@@ -19,4 +19,5 @@
#
#
AttributeURIMissing = Attribute 'uri' is missing
+XMLStreamException = XMLStreamException occured due to : {0}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
index e2e97239e0..f74a87d890 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
@@ -33,6 +33,7 @@ import org.apache.tuscany.sca.contribution.ContributionMetadata;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
@@ -61,7 +62,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
public ContributionMetadataDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
StAXArtifactProcessor staxProcessor,
Monitor monitor) {
- this.inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
this.staxProcessor = staxProcessor;
this.monitor = monitor;
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
index 3f5aacb541..dd1a3a677e 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
@@ -88,6 +88,20 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
}
}
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
public ContributionMetadataProcessor(ModelFactoryExtensionPoint modelFactories,
StAXArtifactProcessor<Object> extensionProcessor,
Monitor monitor) {
@@ -106,63 +120,69 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
return ContributionMetadata.class;
}
- public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException {
ContributionMetadata contribution = null;
QName name = null;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- name = reader.getName();
-
- if (CONTRIBUTION_QNAME.equals(name)) {
-
- // Read <contribution>
- contribution = this.contributionFactory.createContributionMetadata();
- contribution.setUnresolved(true);
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
- } else if (DEPLOYABLE_QNAME.equals(name)) {
-
- // Read <deployable>
- QName compositeName = getQName(reader, "composite");
- if (compositeName == null) {
- error("AttributeCompositeMissing", reader);
- //throw new ContributionReadException("Attribute 'composite' is missing");
+ if (CONTRIBUTION_QNAME.equals(name)) {
+
+ // Read <contribution>
+ contribution = this.contributionFactory.createContributionMetadata();
+ contribution.setUnresolved(true);
+
+ } else if (DEPLOYABLE_QNAME.equals(name)) {
+
+ // Read <deployable>
+ QName compositeName = getQName(reader, "composite");
+ if (compositeName == null) {
+ error("AttributeCompositeMissing", reader);
+ //throw new ContributionReadException("Attribute 'composite' is missing");
+ } else {
+ if (contribution != null) {
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(compositeName);
+ composite.setUnresolved(true);
+ contribution.getDeployables().add(composite);
+ }
+ }
} else {
- if (contribution != null) {
- Composite composite = assemblyFactory.createComposite();
- composite.setName(compositeName);
- composite.setUnresolved(true);
- contribution.getDeployables().add(composite);
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null && contribution != null) {
+ if (extension instanceof Import) {
+ contribution.getImports().add((Import)extension);
+ } else if (extension instanceof Export) {
+ contribution.getExports().add((Export)extension);
+ }
}
}
- } else {
-
- // Read an extension element
- Object extension = extensionProcessor.read(reader);
- if (extension != null && contribution != null) {
- if (extension instanceof Import) {
- contribution.getImports().add((Import)extension);
- } else if (extension instanceof Export) {
- contribution.getExports().add((Export)extension);
- }
+ break;
+
+ case XMLStreamConstants.END_ELEMENT:
+ if (CONTRIBUTION_QNAME.equals(reader.getName())) {
+ return contribution;
}
- }
- break;
-
- case XMLStreamConstants.END_ELEMENT:
- if (CONTRIBUTION_QNAME.equals(reader.getName())) {
- return contribution;
- }
- break;
- }
-
- //Read the next element
- if (reader.hasNext()) {
- reader.next();
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return contribution;
}
diff --git a/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties b/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
index 3e1a0187fe..4827fd5e94 100644
--- a/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
+++ b/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
@@ -18,6 +18,7 @@
# under the License.
#
#
-XMLStreamException = XMLStreamException occured due to:
-IOException = IOException occured due to:
-AttributeCompositeMissing = Attribute 'composite' is missing \ No newline at end of file
+XMLStreamException = XMLStreamException occured due to : {0}
+IOException = IOException occured due to : {0}
+AttributeCompositeMissing = Attribute 'composite' is missing
+