summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/contribution-java
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-10-31 09:44:57 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-10-31 09:44:57 +0000
commit66e05fbc5dbe0d5806881166c30aaf543576fdd1 (patch)
treed5cc2cd21214e5615e4fb6d36b66dcd04d7fb153 /java/sca/modules/contribution-java
parent95c83c38d814e6dbcceb9efdcd4b62d60a16c051 (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@709372 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/contribution-java')
-rw-r--r--java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java74
-rw-r--r--java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java80
-rw-r--r--java/sca/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties1
3 files changed, 98 insertions, 57 deletions
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<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/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<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/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}