summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/contribution-resource/src/main
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-resource/src/main
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-resource/src/main')
-rw-r--r--java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java80
-rw-r--r--java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java82
-rw-r--r--java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties1
3 files changed, 102 insertions, 61 deletions
diff --git a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java
index 68d5d4761e..cf99aee389 100644
--- a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java
+++ b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java
@@ -68,10 +68,24 @@ public class ResourceExportProcessor implements StAXArtifactProcessor<ResourceEx
*/
private void error(String message, Object model, Object... messageParameters) {
if (monitor != null) {
- Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
- monitor.problem(problem);
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ 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-resource-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return EXPORT_RESOURCE;
@@ -84,39 +98,45 @@ public class ResourceExportProcessor implements StAXArtifactProcessor<ResourceEx
/**
* Process <export.resource uri=""/>
*/
- public ResourceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ResourceExport read(XMLStreamReader reader) throws ContributionReadException {
ResourceExport resourceExport = this.factory.createResourceExport();
QName element = null;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- element = reader.getName();
-
- // Read <export.resource>
- if (EXPORT_RESOURCE.equals(element)) {
- String uri = reader.getAttributeValue(null, URI);
- if (uri == null) {
- error("AttributeURIMissing", reader);
- //throw new ContributionReadException("Attribute 'uri' is missing");
- } else
- resourceExport.setURI(uri);
- }
-
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (EXPORT_RESOURCE.equals(reader.getName())) {
- return resourceExport;
- }
- 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.resource>
+ if (EXPORT_RESOURCE.equals(element)) {
+ String uri = reader.getAttributeValue(null, URI);
+ if (uri == null) {
+ error("AttributeURIMissing", reader);
+ //throw new ContributionReadException("Attribute 'uri' is missing");
+ } else
+ resourceExport.setURI(uri);
+ }
+
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (EXPORT_RESOURCE.equals(reader.getName())) {
+ return resourceExport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return resourceExport;
}
diff --git a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java
index 8b2fc44a1c..bc3fb7fa5f 100644
--- a/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java
+++ b/java/sca/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java
@@ -74,6 +74,20 @@ public class ResourceImportProcessor implements StAXArtifactProcessor<ResourceI
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-resource-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
public QName getArtifactType() {
return IMPORT_RESOURCE;
@@ -86,43 +100,49 @@ public class ResourceImportProcessor implements StAXArtifactProcessor<ResourceI
/**
* Process <import.resource uri="" location=""/>
*/
- public ResourceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ResourceImport read(XMLStreamReader reader) throws ContributionReadException {
ResourceImport resourceImport = this.factory.createResourceImport();
QName element;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- element = reader.getName();
-
- // Read <import>
- if (IMPORT_RESOURCE.equals(element)) {
- String uri = reader.getAttributeValue(null, URI);
- if (uri == null) {
- error("AttributeURIMissing", reader);
- //throw new ContributionReadException("Attribute 'uri' is missing");
- } else
- resourceImport.setURI(uri);
-
- String location = reader.getAttributeValue(null, LOCATION);
- if (location != null) {
- resourceImport.setLocation(location);
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <import>
+ if (IMPORT_RESOURCE.equals(element)) {
+ String uri = reader.getAttributeValue(null, URI);
+ if (uri == null) {
+ error("AttributeURIMissing", reader);
+ //throw new ContributionReadException("Attribute 'uri' is missing");
+ } else
+ resourceImport.setURI(uri);
+
+ String location = reader.getAttributeValue(null, LOCATION);
+ if (location != null) {
+ resourceImport.setLocation(location);
+ }
}
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (IMPORT_RESOURCE.equals(reader.getName())) {
- return resourceImport;
- }
- break;
- }
-
- // Read the next element
- if (reader.hasNext()) {
- reader.next();
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (IMPORT_RESOURCE.equals(reader.getName())) {
+ return resourceImport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return resourceImport;
}
diff --git a/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties b/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties
index 58ee8153f8..9df66cce52 100644
--- a/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties
+++ b/java/sca/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties
@@ -19,4 +19,5 @@
#
#
AttributeURIMissing = Attribute 'uri' is missing
+XMLStreamException = XMLStreamException occured due to : {0}