From 66e05fbc5dbe0d5806881166c30aaf543576fdd1 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 31 Oct 2008 09:44:57 +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@709372 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/impl/JavaExportProcessor.java | 74 ++++++++++++-------- .../java/impl/JavaImportProcessor.java | 80 ++++++++++++++-------- ...ontribution-java-validation-messages.properties | 1 + 3 files changed, 98 insertions(+), 57 deletions(-) (limited to 'java/sca/modules/contribution-java/src/main') 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 { 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 { /** * Process */ - 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 - 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 + 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 { 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 { /** * Process */ - 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 - 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 + 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} -- cgit v1.2.3