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-java | |
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-java')
3 files changed, 98 insertions, 57 deletions
diff --git a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java index 9f6ff52289..d7c3817b68 100644 --- a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java +++ b/branches/sca-java-1.3.3/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/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java index d027d75b32..7812c25c1c 100644 --- a/branches/sca-java-1.3.3/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java +++ b/branches/sca-java-1.3.3/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/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties b/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties index 70b58f75c0..09fc3e9fff 100644 --- a/branches/sca-java-1.3.3/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties +++ b/branches/sca-java-1.3.3/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} |