Author: gnodet
Date: Fri Jan  5 00:26:46 2007
New Revision: 492940

URL: http://svn.apache.org/viewvc?view=rev&rev=492940
Log:
SM-582: update ValidateComponent to utilise a dependency injected factory 
implementation to mitigate threading issues

Added:
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
   (with props)
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
   (with props)
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
   (with props)
Modified:
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java

Added: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java?view=auto&rev=492940
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
 (added)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
 Fri Jan  5 00:26:46 2007
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.components.validation;
+
+/**
+ * @author gmcdonald
+ *
+ */
+public class CountingErrorHandlerFactory implements
+        MessageAwareErrorHandlerFactory {
+
+    /* (non-Javadoc)
+     * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandlerFactory#createMessageAwareErrorHandler()
+     */
+    public MessageAwareErrorHandler createMessageAwareErrorHandler() {
+        return new CountingErrorHandler();
+    }
+
+}

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java?view=diff&rev=492940&r1=492939&r2=492940
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java
 Fri Jan  5 00:26:46 2007
@@ -39,26 +39,26 @@
  */
 public class MessageAggregatingErrorHandler implements 
MessageAwareErrorHandler {
     
-       private static final String openCDATA = "<![CDATA[";
-       private static final String closeCDATA = "]]>";
-       private static final String openError = "<error>";
-       private static final String closeError = "</error>";
-       private static final String openFatalError = "<fatalError>";
-       private static final String closeFatalError = "</fataError>";
-       private static final String openWarning = "<warning>";
-       private static final String closeWarning = "</warning>";
-       
-       private String openRootElement;
-       private String closeRootElement;
+    private static final String openCDATA = "<![CDATA[";
+    private static final String closeCDATA = "]]>";
+    private static final String openError = "<error>";
+    private static final String closeError = "</error>";
+    private static final String openFatalError = "<fatalError>";
+    private static final String closeFatalError = "</fataError>";
+    private static final String openWarning = "<warning>";
+    private static final String closeWarning = "</warning>";
+    
+    private String openRootElement;
+    private String closeRootElement;
 
-       /**
+    /**
      * Number of warnings.
      */
-       private int warningCount;
-       
-       /**
-        * Number of errors.
-        */
+    private int warningCount;
+    
+    /**
+     * Number of errors.
+     */
     private int errorCount;
     
     /**
@@ -88,92 +88,66 @@
     
     private SourceTransformer sourceTransformer = new SourceTransformer();
     
-       /**
-     * Constructor.
-     * 
-     * @param rootElement
-     *                 The root element name of the fault xml message 
-     * @param namespace
-     *                 The namespace for the fault xml message
-     */
-    public MessageAggregatingErrorHandler(String rootPath, String namespace) 
throws IllegalArgumentException {
-       if (rootPath == null || rootPath.trim().length() == 0) {
-               throw new IllegalArgumentException("rootPath must not be null 
or an empty string");
-       }
-       this.rootPath = rootPath;
-       this.namespace = namespace;
-       createRootElementTags();
-    }
-
     /**
      * Constructor.
      * 
      * @param rootElement
-     *                 The root element name of the fault xml message 
+     *      The root element name of the fault xml message 
      * @param namespace
-     *                 The namespace for the fault xml message
+     *      The namespace for the fault xml message
      * @param includeStackTraces
-     *                 Include stracktraces in the final output
+     *      Include stracktraces in the final output
      */
     public MessageAggregatingErrorHandler(String rootPath, String namespace, 
boolean includeStackTraces) throws IllegalArgumentException {
-       this(rootPath, namespace);
-       this.includeStackTraces = includeStackTraces;
+        if (rootPath == null || rootPath.trim().length() == 0) {
+            throw new IllegalArgumentException("rootPath must not be null or 
an empty string");
+        }
+        this.rootPath = rootPath;
+        this.namespace = namespace;
+        this.includeStackTraces = includeStackTraces;
+        createRootElementTags();
     }
 
     /**
-        * @return Returns the sourceTransformer.
-        */
-       public SourceTransformer getSourceTransformer() {
-               return sourceTransformer;
-       }
-
-       /**
-        * @param sourceTransformer The sourceTransformer to set.
-        */
-       public void setSourceTransformer(SourceTransformer sourceTransformer) {
-               this.sourceTransformer = sourceTransformer;
-       }
-
-       /**
      * Creates the root element tags for later use down to n depth.
      * Note: the rootPath here is of the form:
      * 
-     *                 
<code>rootElementName/elementName-1/../elementName-n</code>
+     *      <code>rootElementName/elementName-1/../elementName-n</code>
      * 
      * The namespace will be appended to the root element if it is not
      * null or empty.
      */
-       private void createRootElementTags() {
-               /* 
-                * since the rootPath is constrained to be not null or empty
-                * then we have at least one path element.
-                */
-               String[] pathElements = rootPath.split("/");
-
-               StringBuffer openRootElementSB = new 
StringBuffer().append("<").append(pathElements[0]);
-               StringBuffer closeRootElementSB = new StringBuffer();
-               
-               if (namespace != null && namespace.trim().length() > 0) {
-                       openRootElementSB.append(" 
xmlns=\"").append(namespace).append("\">"); 
-               } else {
-                       openRootElementSB.append(">");
-               }
-               
-               if (pathElements.length > 0) {
-                       for (int i = 1, j = pathElements.length - 1; i < 
pathElements.length; i++, j--) {
-                               
openRootElementSB.append("<").append(pathElements[i]).append(">");
-                               
closeRootElementSB.append("</").append(pathElements[j]).append(">");
-                       }
-               }
-       
-       // create the closing root element tag
-       closeRootElementSB.append("</").append(pathElements[0]).append(">");
-       
-       openRootElement = openRootElementSB.toString();
-       closeRootElement = closeRootElementSB.toString();
+    private void createRootElementTags() {
+        /* 
+         * since the rootPath is constrained to be not null or empty
+         * then we have at least one path element.
+         */
+        String[] pathElements = rootPath.split("/");
+
+        StringBuffer openRootElementSB = new 
StringBuffer().append("<").append(pathElements[0]);
+        StringBuffer closeRootElementSB = new StringBuffer();
+        
+        if (namespace != null && namespace.trim().length() > 0) {
+            openRootElementSB.append(" 
xmlns=\"").append(namespace).append("\">"); 
+        } else {
+            openRootElementSB.append(">");
+        }
+        
+        if (pathElements.length > 0) {
+            for (int i = 1, j = pathElements.length - 1; i < 
pathElements.length; i++, j--) {
+                
openRootElementSB.append("<").append(pathElements[i]).append(">");
+                
closeRootElementSB.append("</").append(pathElements[j]).append(">");
+            }
+        }
+        
+        // create the closing root element tag
+        closeRootElementSB.append("</").append(pathElements[0]).append(">");
+        
+        openRootElement = openRootElementSB.toString();
+        closeRootElement = closeRootElementSB.toString();
     }
     
-       /*  (non-Javadoc)
+    /*  (non-Javadoc)
      * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandler#hasErrors()
      */
     public boolean hasErrors() {
@@ -209,7 +183,7 @@
 
         // open warning and CDATA tags
         messages.append(openWarning).append(openCDATA);
-       
+        
         // append the fatal error message
         appendErrorMessage(e);
         
@@ -225,7 +199,7 @@
 
         // open fatal error and CDATA tags
         messages.append(openError).append(openCDATA);
-       
+        
         // append the error message
         appendErrorMessage(e);
         
@@ -238,10 +212,10 @@
      */
     public void fatalError(SAXParseException e) throws SAXException {
         ++fatalErrorCount;
-       
+        
         // open fatal error and CDATA tags
         messages.append(openFatalError).append(openCDATA);
-       
+        
         // append the fatal error message
         appendErrorMessage(e);
         
@@ -260,7 +234,7 @@
             e.printStackTrace(new PrintWriter(sw));
             messages.append(sw.toString());
         } else {
-               messages.append(e.getLocalizedMessage());
+            messages.append(e.getLocalizedMessage());
         }
     }
     
@@ -268,73 +242,73 @@
      * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandler#capturesMessages()
      */
     public boolean capturesMessages() {
-       return true;
+        return true;
     }
 
-       /* (non-Javadoc)
-        * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandler#getMessagesAs(java.lang.Class)
-        */
-       public Object getMessagesAs(Class format) throws MessagingException {
-               if (format == DOMSource.class) {
-                       return getDOMSource();
-               } else if (format == StringSource.class) {
-                       return getStringSource();
-               } else if (format == String.class) {
-                       return getMessagesWithRootElement();
-               }
-               throw new MessagingException("Unsupported message format: " + 
format.getName());
-       }
-
-       /* (non-Javadoc)
-        * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandler#supportsMessageFormat(java.lang.Class)
-        */
-       public boolean supportsMessageFormat(Class format) {
-               if (format == DOMSource.class) {
-                       return true;
-               } else if (format == StringSource.class) {
-                       return true;
-               } else if (format == String.class) {
-                       return true;
-               }
-               return false;
-       }
-    
-       /**
-        * Return the messages encapsulated with the root element.
-        * 
-        * @return
-        */
-       private String getMessagesWithRootElement() {
-               return new 
StringBuffer().append(openRootElement).append(messages).append(closeRootElement).toString();
-       }
-       
-       /**
-        * Get the error messages as a String Source.
-        * 
-        * @return
-        */
-       private StringSource getStringSource() {
-               return new StringSource(getMessagesWithRootElement());
-       }
-       
-       /**
-        * Get the error messages as a DOMSource.
-        * 
-        * @return
-        * @throws MessagingException
-        */
-       private DOMSource getDOMSource() throws MessagingException {
-               try {
-                       return sourceTransformer.toDOMSource(getStringSource());
-               } catch (ParserConfigurationException e) {
-                       throw new MessagingException("Failed to create 
DOMSource for Schema validation messages: " + e, e);
-               } catch (IOException e) {
-                       throw new MessagingException("Failed to create 
DOMSource for Schema validation messages: " + e, e);
-               } catch (SAXException e) {
-                       throw new MessagingException("Failed to create 
DOMSource for Schema validation messages: " + e, e);
-               } catch (TransformerException e) {
-                       throw new MessagingException("Failed to create 
DOMSource for Schema validation messages: " + e, e);
-               }
-       }
+    /* (non-Javadoc)
+     * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandler#getMessagesAs(java.lang.Class)
+     */
+    public Object getMessagesAs(Class format) throws MessagingException {
+        if (format == DOMSource.class) {
+            return getDOMSource();
+        } else if (format == StringSource.class) {
+            return getStringSource();
+        } else if (format == String.class) {
+            return getMessagesWithRootElement();
+        }
+        throw new MessagingException("Unsupported message format: " + 
format.getName());
+    }
+
+    /* (non-Javadoc)
+     * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandler#supportsMessageFormat(java.lang.Class)
+     */
+    public boolean supportsMessageFormat(Class format) {
+        if (format == DOMSource.class) {
+            return true;
+        } else if (format == StringSource.class) {
+            return true;
+        } else if (format == String.class) {
+            return true;
+        }
+        return false;
+    }
+    
+    /**
+     * Return the messages encapsulated with the root element.
+     * 
+     * @return
+     */
+    private String getMessagesWithRootElement() {
+        return new 
StringBuffer().append(openRootElement).append(messages).append(closeRootElement).toString();
+    }
+    
+    /**
+     * Get the error messages as a String Source.
+     * 
+     * @return
+     */
+    private StringSource getStringSource() {
+        return new StringSource(getMessagesWithRootElement());
+    }
+    
+    /**
+     * Get the error messages as a DOMSource.
+     * 
+     * @return
+     * @throws MessagingException
+     */
+    private DOMSource getDOMSource() throws MessagingException {
+        try {
+            return sourceTransformer.toDOMSource(getStringSource());
+        } catch (ParserConfigurationException e) {
+            throw new MessagingException("Failed to create DOMSource for 
Schema validation messages: " + e, e);
+        } catch (IOException e) {
+            throw new MessagingException("Failed to create DOMSource for 
Schema validation messages: " + e, e);
+        } catch (SAXException e) {
+            throw new MessagingException("Failed to create DOMSource for 
Schema validation messages: " + e, e);
+        } catch (TransformerException e) {
+            throw new MessagingException("Failed to create DOMSource for 
Schema validation messages: " + e, e);
+        }
+    }
     
 }

Added: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java?view=auto&rev=492940
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
 (added)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
 Fri Jan  5 00:26:46 2007
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.components.validation;
+
+/**
+ * @author gmcdonald
+ *
+ */
+public class MessageAggregatingErrorHandlerFactory implements
+        MessageAwareErrorHandlerFactory {
+
+    /**
+     * The root element name for the fault xml message
+     */
+    private String rootPath;
+    
+    /**
+     * The namespace for the fault xml message
+     */
+    private String namespace;
+    
+    /**
+     * Determines whether or not to include stacktraces in the fault xml 
message
+     */
+    private boolean includeStackTraces;
+    
+    /**
+     * @return Returns the includeStackTraces.
+     */
+    public boolean isIncludeStackTraces() {
+        return includeStackTraces;
+    }
+
+    /**
+     * @param includeStackTraces The includeStackTraces to set.
+     */
+    public void setIncludeStackTraces(boolean includeStackTraces) {
+        this.includeStackTraces = includeStackTraces;
+    }
+
+    /**
+     * @return Returns the namespace.
+     */
+    public String getNamespace() {
+        return namespace;
+    }
+
+    /**
+     * @param namespace The namespace to set.
+     */
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    /**
+     * @return Returns the rootPath.
+     */
+    public String getRootPath() {
+        return rootPath;
+    }
+
+    /**
+     * @param rootPath The rootPath to set.
+     */
+    public void setRootPath(String rootPath) {
+        this.rootPath = rootPath;
+    }
+
+    /* (non-Javadoc)
+     * @see 
org.apache.servicemix.components.validation.MessageAwareErrorHandlerFactory#createMessageAwareErrorHandler()
+     */
+    public MessageAwareErrorHandler createMessageAwareErrorHandler() {
+        return new MessageAggregatingErrorHandler(rootPath, namespace, 
includeStackTraces);
+    }
+
+}

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java?view=auto&rev=492940
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
 (added)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
 Fri Jan  5 00:26:46 2007
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.components.validation;
+
+/**
+ * Simple factory interface to a MessageAwareErrorHandler implementation
+ * 
+ * @author gmcdonald
+ *
+ */
+public interface MessageAwareErrorHandlerFactory {
+    
+    /**
+     * Create and return a concrete MessageAwareErrorHandler implementation
+     * 
+     * @return
+     */
+    public MessageAwareErrorHandler createMessageAwareErrorHandler();
+}

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java?view=diff&rev=492940&r1=492939&r2=492940
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java
 Fri Jan  5 00:26:46 2007
@@ -51,7 +51,7 @@
     private String schemaLanguage = "http://www.w3.org/2001/XMLSchema";;
     private Source schemaSource;
     private Resource schemaResource;
-    private MessageAwareErrorHandler errorHandler = new CountingErrorHandler();
+    private MessageAwareErrorHandlerFactory errorHandlerFactory = new 
CountingErrorHandlerFactory();
 
     public Schema getSchema() {
         return schema;
@@ -85,13 +85,13 @@
         this.schemaResource = schemaResource;
     }
    
-    public MessageAwareErrorHandler getErrorHandler() {
-               return errorHandler;
-       }
-
-       public void setErrorHandler(MessageAwareErrorHandler errorHandler) {
-               this.errorHandler = errorHandler;
-       }
+    public MessageAwareErrorHandlerFactory getErrorHandlerFactory() {
+        return errorHandlerFactory;
+    }
+
+    public void setErrorHandlerFactory(MessageAwareErrorHandlerFactory 
errorHandlerFactory) {
+        this.errorHandlerFactory = errorHandlerFactory;
+    }
 
     protected void init() throws JBIException {
         super.init();
@@ -105,9 +105,9 @@
                         throw new JBIException("You must specify a schema, 
schemaSource or schemaResource property");
                     }
                     if (schemaResource.getURL() == null) {
-                       schemaSource = new 
StreamSource(schemaResource.getInputStream());
+                        schemaSource = new 
StreamSource(schemaResource.getInputStream());
                     } else {
-                       schemaSource = new 
StreamSource(schemaResource.getInputStream(), 
schemaResource.getURL().toExternalForm());     
+                        schemaSource = new 
StreamSource(schemaResource.getInputStream(), 
schemaResource.getURL().toExternalForm()); 
                     }
                 }
                 schema = factory.newSchema(schemaSource);
@@ -124,19 +124,22 @@
     protected boolean transform(MessageExchange exchange, NormalizedMessage 
in, NormalizedMessage out) throws MessagingException {
         Validator validator = schema.newValidator();
 
+        // create a new errorHandler and set it on the validator
+        MessageAwareErrorHandler errorHandler = 
errorHandlerFactory.createMessageAwareErrorHandler();
         validator.setErrorHandler(errorHandler);
         DOMResult result = new DOMResult();
+        
         // Transform first so that the input source will be parsed only once
         // if it is a StreamSource
         getMessageTransformer().transform(exchange, in, out);
         try {
-               SourceTransformer sourceTransformer = new SourceTransformer();
-               // Only DOMSource and SAXSource are allowed for validating
-               // See 
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
-               // As we expect a DOMResult as output, we must ensure that the 
input is a 
-               // DOMSource
-               DOMSource src = sourceTransformer.toDOMSource(out.getContent());
-               doValidation(validator,src,result);
+            SourceTransformer sourceTransformer = new SourceTransformer();
+            // Only DOMSource and SAXSource are allowed for validating
+            // See 
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
+            // As we expect a DOMResult as output, we must ensure that the 
input is a 
+            // DOMSource
+            DOMSource src = sourceTransformer.toDOMSource(out.getContent());
+            doValidation(validator,src,result);
             if (errorHandler.hasErrors()) {
                 Fault fault = exchange.createFault();
                 
@@ -150,40 +153,40 @@
                  */
                 if (errorHandler.capturesMessages()) {
 
-                       /* 
-                        * In descending order of preference select a format to 
use. If
-                        * neither DOMSource, StringSource or String are 
supported throw
-                        * a messaging exception.
-                        */
-                       if 
(errorHandler.supportsMessageFormat(DOMSource.class)) {
-                               fault.setContent(
-                                               
(DOMSource)errorHandler.getMessagesAs(DOMSource.class));
-                       } else if 
(errorHandler.supportsMessageFormat(StringSource.class)) {
-                               fault.setContent(sourceTransformer.toDOMSource(
-                                               
(StringSource)errorHandler.getMessagesAs(StringSource.class)));
-                       } else if 
(errorHandler.supportsMessageFormat(String.class)) {
-                               fault.setContent(
-                                               sourceTransformer.toDOMSource(
-                                                               new 
StringSource(
-                                                                               
(String)errorHandler.getMessagesAs(String.class))));
-                       } else {
-                               throw new 
MessagingException("MessageAwareErrorHandler implementation " + 
-                                               
errorHandler.getClass().getName() +
-                                               " does not support a compatible 
error message format.");
-                       }
+                    /* 
+                     * In descending order of preference select a format to 
use. If
+                     * neither DOMSource, StringSource or String are supported 
throw
+                     * a messaging exception.
+                     */
+                    if (errorHandler.supportsMessageFormat(DOMSource.class)) {
+                        fault.setContent(
+                                
(DOMSource)errorHandler.getMessagesAs(DOMSource.class));
+                    } else if 
(errorHandler.supportsMessageFormat(StringSource.class)) {
+                        fault.setContent(sourceTransformer.toDOMSource(
+                                
(StringSource)errorHandler.getMessagesAs(StringSource.class)));
+                    } else if 
(errorHandler.supportsMessageFormat(String.class)) {
+                        fault.setContent(
+                                sourceTransformer.toDOMSource(
+                                        new StringSource(
+                                                
(String)errorHandler.getMessagesAs(String.class))));
+                    } else {
+                        throw new MessagingException("MessageAwareErrorHandler 
implementation " + 
+                                errorHandler.getClass().getName() +
+                                " does not support a compatible error message 
format.");
+                    }
                 } else {
-                       /* 
-                        * we can't do much here if the ErrorHandler 
implementation does
-                        * not support capturing messages
-                        */
+                    /* 
+                     * we can't do much here if the ErrorHandler 
implementation does
+                     * not support capturing messages
+                     */
                     fault.setContent(new DOMSource(result.getNode(), 
result.getSystemId()));
                 }
                 throw new FaultException("Failed to validate against schema: " 
+ schema, exchange, fault);
             }
             else {
-               // Retrieve the ouput of the validation
-               // as it may have been changed by the validator
-               out.setContent(new DOMSource(result.getNode(), 
result.getSystemId()));
+                // Retrieve the ouput of the validation
+                // as it may have been changed by the validator
+                out.setContent(new DOMSource(result.getNode(), 
result.getSystemId()));
                 return true;
              }
         }
@@ -195,13 +198,13 @@
         } 
         catch (ParserConfigurationException e) {
             throw new MessagingException(e);
-               } 
+        } 
         catch (TransformerException e) {
             throw new MessagingException(e);
-               }
+        }
     }
     
     protected void doValidation(Validator validator, DOMSource src, DOMResult 
result) throws SAXException, IOException {
-       validator.validate(src,result);
+        validator.validate(src,result);
     }
 }


Reply via email to