diff options
Diffstat (limited to 'java/sca/modules/contribution-xml/src/main')
3 files changed, 73 insertions, 51 deletions
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 + |