From 47fdbd622dc107617a0e5bbd85d21f9249d17ed3 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 30 Oct 2008 13:10:19 +0000 Subject: 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 --- .../namespace/impl/NamespaceImportProcessor.java | 82 ++++++++++++++-------- 1 file changed, 51 insertions(+), 31 deletions(-) (limited to 'branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java') diff --git a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java index 829e5fa43f..a364823256 100644 --- a/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java +++ b/branches/sca-java-1.3.3/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java @@ -75,6 +75,20 @@ public class NamespaceImportProcessor implements StAXArtifactProcessor */ - 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 - 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 + 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; } -- cgit v1.2.3