diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-30 13:10:19 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-30 13:10:19 +0000 |
commit | 47fdbd622dc107617a0e5bbd85d21f9249d17ed3 (patch) | |
tree | 3a1733846621cede38b013ae73374498d925769a /branches/sca-java-1.3.3/modules/contribution-xml | |
parent | 7a28ba7f5ff5dbe521e4b62011c4353685516a31 (diff) |
TUSCANY-2631 - Make the contribution processor more fault tolerant. Apply Ram's patches (and a few other changes). Doesn't do everything asked for in the JIRA but a step in the right direction
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@709156 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.3.3/modules/contribution-xml')
3 files changed, 73 insertions, 51 deletions
diff --git a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java index e2e97239e0..f74a87d890 100644 --- a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java +++ b/branches/sca-java-1.3.3/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/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java index 3f5aacb541..dd1a3a677e 100644 --- a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java +++ b/branches/sca-java-1.3.3/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/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties b/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties index 3e1a0187fe..4827fd5e94 100644 --- a/branches/sca-java-1.3.3/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties +++ b/branches/sca-java-1.3.3/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 + |