You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2008/10/09 12:52:18 UTC

svn commit: r703128 - /forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java

Author: thorsten
Date: Thu Oct  9 03:52:18 2008
New Revision: 703128

URL: http://svn.apache.org/viewvc?rev=703128&view=rev
Log:
Switching to use contract exception and enhancing the code around the exception handling in general

Modified:
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java?rev=703128&r1=703127&r2=703128&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java (original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java Thu Oct  9 03:52:18 2008
@@ -27,12 +27,11 @@
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
 import javax.xml.transform.URIResolver;
 import javax.xml.transform.stream.StreamResult;
 
 import org.apache.forrest.dispatcher.api.Contract;
-import org.apache.forrest.dispatcher.exception.DispatcherException;
+import org.apache.forrest.dispatcher.exception.ContractException;
 
 import org.apache.forrest.dispatcher.impl.helper.Loggable;
 import org.apache.forrest.dispatcher.impl.helper.XSLContractHelper;
@@ -45,7 +44,7 @@
 
   private boolean allowXmlProperties = false;
 
-  public XSLContract(boolean allowXmlProperties, URIResolver uriResolver) throws DispatcherException {
+  public XSLContract(boolean allowXmlProperties, URIResolver uriResolver) throws ContractException {
     this.allowXmlProperties = allowXmlProperties;
     /*
      * get a new instance of the corresponding helper class since the helper is
@@ -55,12 +54,11 @@
   }
 
   public BufferedInputStream execute(InputStream dataStream,
-      Map<String, Object> properties) throws DispatcherException {
+      Map<String, Object> properties) throws ContractException {
     if (xslSource == null || helper == null) {
-      throw new DispatcherException("Contract \"" + name
-          + "\" has produced an exception. "
-          + "The xsl source have not been initialize from stream "
-          + "the contract. We cannot proceed without this.");
+      String message = "The xsl source have not been initialize from stream "
+          + "for the contract.";
+      throw new ContractException(message);
     }
     try {
       /*
@@ -68,14 +66,11 @@
        */
       helper.prepareTransformation(xslSource, allowXmlProperties, properties);
     } catch (TransformerConfigurationException e) {
-      throw new DispatcherException("Contract \"" + name
-          + "\" has produced an exception. "
-          + "Could not setup the transformer for "
-          + "the contract. We cannot proceed without this.", e);
+      String message =  "Could not setup the transformer for "
+                + "the contract."+"\n"+ e;
+      throw new ContractException(message );
     } catch (Exception e) {
-      throw new DispatcherException("Contract \"" + name
-          + "\" has produced an exception. "
-          + "We cannot proceed without this.", e);
+      throw new ContractException(e);
     }
     /*
      * If no dataStream is present we need to create an empty xml doc to be able
@@ -85,10 +80,9 @@
       try {
         dataStream = helper.createEmptyXml();
       } catch (XMLStreamException e) {
-        throw new DispatcherException("Contract \"" + name
-            + "\" has produced an exception. "
-            + "Could not create an empty xml document for "
-            + "the contract. We cannot proceed without this.", e);
+        String message = "Could not create an empty xml document for "
+            + "the contract. " +"\n"+ e;
+        throw new ContractException(message);
       }
     }
     ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -96,23 +90,22 @@
     Result streamResult = new StreamResult(new BufferedOutputStream(out));
     try {
       helper.transform(dataStream,streamResult);
-    } catch (TransformerException e) {
-      throw new DispatcherException("Contract \"" + name
-          + "\" has produced an exception. "
-          + "Could not invoke the transformation for "
-          + "the contract. We cannot proceed without this.", e);
+    } catch (Exception e) {
+      String message = "Could not invoke the transformation for "
+          + "the contract. "+"\n"+ e;
+      throw new ContractException(message);
     }
     log.debug(out.toString());
     return new BufferedInputStream(new ByteArrayInputStream(out.toByteArray()));
   }
 
   public void initializeFromStream(InputStream stream)
-      throws DispatcherException {
+      throws ContractException {
     // invoke the extraction
     try {
       helper.setTemplate(stream, this);
     } catch (XMLStreamException e) {
-      throw new DispatcherException(e);
+      throw new ContractException(e);
     }
 
   }