cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1189938 - in /cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb: JAXBBindErrorListener.java JAXBDataBinding.java
Date Thu, 27 Oct 2011 19:04:11 GMT
Author: dkulp
Date: Thu Oct 27 19:04:11 2011
New Revision: 1189938

URL: http://svn.apache.org/viewvc?rev=1189938&view=rev
Log:
[CXF-3887] Allow xjc to display multiple error messages

Modified:
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java?rev=1189938&r1=1189937&r2=1189938&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
Thu Oct 27 19:04:11 2011
@@ -18,6 +18,7 @@
  */
 
 package org.apache.cxf.tools.wsdlto.databinding.jaxb;
+
 import com.sun.tools.xjc.api.ErrorListener;
 
 import org.apache.cxf.tools.common.ToolException;
@@ -25,21 +26,40 @@ import org.apache.cxf.tools.common.ToolE
 public class JAXBBindErrorListener implements ErrorListener {
     private boolean isVerbose;
     private String prefix = "Thrown by JAXB: ";
-
+    private StringBuilder errors = new StringBuilder();
+    private Exception firstException;
+    
     public JAXBBindErrorListener(boolean verbose) {
         isVerbose = verbose;
     }
 
+    public boolean hasErrors() {
+        return errors.length() != 0;
+    }
+    public void throwError() {
+        throw new ToolException(prefix + "\n" + errors.toString(), firstException);
+    }
+    
     public void error(org.xml.sax.SAXParseException exception) {
+        if (errors.length() == 0) {
+            errors.append(prefix);
+        }
+        errors.append("\n");
         if (exception.getLineNumber() > 0) {
-            throw new ToolException(prefix + exception.getLocalizedMessage() 
-                                    + " at line " + exception.getLineNumber()
-                                    + " column " + exception.getColumnNumber()
-                                    + " of schema " + exception.getSystemId(), exception);
+            errors.append(exception.getLocalizedMessage() + "\n"
+                       + " at line " + exception.getLineNumber()
+                       + " column " + exception.getColumnNumber()
+                       + " of schema " + exception.getSystemId()
+                       + "\n");
            
+        } else {
+            errors.append(prefix + mapMessage(exception.getLocalizedMessage())
+                          + "\n");
+        }
+        if (firstException == null) {
+            firstException = exception;
+            firstException.fillInStackTrace();
         }
-        throw new ToolException(prefix + mapMessage(exception.getLocalizedMessage()), exception);
-
     }
 
     public void fatalError(org.xml.sax.SAXParseException exception) {
@@ -56,7 +76,7 @@ public class JAXBBindErrorListener imple
 
     public void warning(org.xml.sax.SAXParseException exception) {
         if (this.isVerbose) {
-            System.err.println("JAXB parsing schema warning " + exception.toString()
+            System.out.println("JAXB parsing schema warning " + exception.toString()
                                + " in schema " + exception.getSystemId());
         }
     }

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1189938&r1=1189937&r2=1189938&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Thu Oct 27 19:04:11 2011
@@ -247,7 +247,8 @@ public class JAXBDataBinding implements 
     private ToolContext context;
     private DefaultValueProvider defaultValues;
     private boolean initialized;
-
+    private JAXBBindErrorListener listener;
+    
     static {
         DEFAULT_TYPE_MAP.add("boolean");
         DEFAULT_TYPE_MAP.add("int");
@@ -292,7 +293,7 @@ public class JAXBDataBinding implements 
 
         schemaCompiler.setClassNameAllocator(allocator);
 
-        JAXBBindErrorListener listener = new JAXBBindErrorListener(context.isVerbose());
+        listener = new JAXBBindErrorListener(context.isVerbose());
         schemaCompiler.setErrorListener(listener);
         // Collection<SchemaInfo> schemas = serviceInfo.getSchemas();
         List<InputSource> jaxbBindings = context.getJaxbBindingFile();
@@ -407,6 +408,10 @@ public class JAXBDataBinding implements 
                 }
             }
         }
+        
+        if (listener.hasErrors()) {
+            listener.throwError();
+        }
         initialized = true;
     }
 
@@ -728,6 +733,7 @@ public class JAXBDataBinding implements 
                 for (String str : fileCodeWriter.getExcludeFileList()) {
                     context.getExcludeFileList().add(str);
                 }
+                
             }
             return;
         } catch (IOException e) {



Mime
View raw message