cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1162224 - in /cxf/trunk: api/src/main/java/org/apache/cxf/tools/common/ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/ tools/wsdlto/frontend/jaxws/src/ma...
Date Fri, 26 Aug 2011 19:56:35 GMT
Author: dkulp
Date: Fri Aug 26 19:56:35 2011
New Revision: 1162224

URL: http://svn.apache.org/viewvc?rev=1162224&view=rev
Log:
[CXF-3762] Support a flag to set the exception superclass
Modified patch from Aaron Pieper applied

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
    cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/wsdlto.xml
    cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java
    cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
    cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java Fri Aug 26
19:56:35 2011
@@ -96,6 +96,7 @@ public final class ToolConstants {
     public static final String CFG_ALLOW_ELEMENT_REFS = "allowElementReferences";
     public static final String CFG_RESERVE_NAME = "reserveClass";
     public static final String CFG_FAULT_SERIAL_VERSION_UID = "faultSerialVersionUID";
+    public static final String CFG_EXCEPTION_SUPER = "exceptionSuper";
     public static final String CFG_MARK_GENERATED = "mark-generated";
 
 

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
Fri Aug 26 19:56:35 2011
@@ -151,6 +151,11 @@ public class Option {
     String faultSerialVersionUID;
 
     /**
+     * The superclass to use for generated exceptions, default is java.lang.Exception
+     */
+    String exceptionSuper;
+
+    /**
      * Uses @Generated annotation in all generated java classes if the flag is set to true.
      */
     Boolean markGenerated;
@@ -359,6 +364,14 @@ public class Option {
     public void setFaultSerialVersionUID(String faultSerialVersionUID) {
         this.faultSerialVersionUID = faultSerialVersionUID;
     }
+    
+    public String getExceptionSuper() {
+        return exceptionSuper;
+    }
+    
+    public void setExceptionSuper(String exceptionSuper) {
+        this.exceptionSuper = exceptionSuper;
+    }
 
     public Boolean isMarkGenerated() {
         return markGenerated;
@@ -446,6 +459,7 @@ public class Option {
         destination.setMimeMethods(getMimeMethods());
         destination.setAsyncMethods(getAsyncMethods());
         destination.setBareMethods(getBareMethods());
+        destination.setExceptionSuper(getExceptionSuper());
     }
     
     private <T> T setIfNull(T dest, T source) {
@@ -457,6 +471,7 @@ public class Option {
     
     public void merge(Option defaultOptions) {
         wsdlList = setIfNull(wsdlList, defaultOptions.wsdlList);
+        exceptionSuper = setIfNull(exceptionSuper, defaultOptions.exceptionSuper);
         extendedSoapHeaders = setIfNull(extendedSoapHeaders, defaultOptions.extendedSoapHeaders);
         noTypes = setIfNull(noTypes, defaultOptions.noTypes);
         validateWsdl = setIfNull(validateWsdl, defaultOptions.validateWsdl);

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
Fri Aug 26 19:56:35 2011
@@ -156,6 +156,7 @@ public class WsdlOption extends Option {
         addIfNotNull(list, getDefaultNamespacePackageMapping(), "-dns");
         addIfNotNull(list, getServiceName(), "-sn");
         addIfNotNull(list, getFaultSerialVersionUID(), "-faultSerialVersionUID");
+        addIfNotNull(list, getExceptionSuper(), "-exceptionSuper");
         addIfTrue(list, isAutoNameResolution(), "-autoNameResolution");
         addIfTrue(list, isNoAddressBinding(), "-noAddressBinding");
         addList(list, "-xjc", false, getXJCargs());

Modified: cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/wsdlto.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/wsdlto.xml?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/wsdlto.xml (original)
+++ cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/wsdlto.xml Fri Aug
26 19:56:35 2011
@@ -208,6 +208,16 @@ under the License.
                 </associatedArgument>
             </option>
 
+            <option id="exceptionSuper" maxOccurs="1">
+                <annotation>
+                    Specifies the superclass to use for generated exceptions, the default
is java.lang.Exception.
+                </annotation>
+                <switch>exceptionSuper</switch>
+                <associatedArgument placement="afterSpace">
+                    <annotation>exceptionSuper</annotation>
+                </associatedArgument>
+            </option>
+
         </optionGroup>
         <optionGroup id="common_options">
             <option id="help" maxOccurs="1">

Modified: cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java
(original)
+++ cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java
Fri Aug 26 19:56:35 2011
@@ -105,24 +105,33 @@ public class FaultGenerator extends Abst
                     setAttributes("suid", "");
                 }
                 setAttributes("expClass", expClz);
-                String exceptionSuperclass = "Exception";
+                String exceptionSuperclass;
+                if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
+                    exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
+                } else {
+                    exceptionSuperclass = "java.lang.Exception";
+                }
+                String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass

+                    : exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.')
+ 1);
+                String exceptionSuperclassString = simpleName;
                 for (JavaField jf : expClz.getFields()) {
                     String jfClassName = jf.getClassName();
-                    if (jfClassName.substring(jfClassName.lastIndexOf(".") + 1).equals("Exception"))
{
-                        exceptionSuperclass = "java.lang.Exception";
+                    if (jfClassName.substring(jfClassName.lastIndexOf(".") + 1)
+                        .equals(simpleName)) {
+                        exceptionSuperclassString = exceptionSuperclass;
                     }
                     setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
                 }
                 ClassCollector collector = penv.get(ClassCollector.class);
                 for (String pkg : collector.getTypesPackages()) {
-                    if (collector.containTypesClass(pkg, "Exception")) {
-                        exceptionSuperclass = "java.lang.Exception";
+                    if (collector.containTypesClass(pkg, simpleName)) {
+                        exceptionSuperclassString = exceptionSuperclass;
                     }
                 }
-                if (expClz.getName().equals(exceptionSuperclass)) {
-                    exceptionSuperclass = "java.lang.Exception";
+                if (expClz.getName().equals(exceptionSuperclassString)) {
+                    exceptionSuperclassString = exceptionSuperclass;
                 }
-                setAttributes("exceptionSuperclass", exceptionSuperclass);
+                setAttributes("exceptionSuperclass", exceptionSuperclassString);
 
                 setCommonAttributes();
                 doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(),

Modified: cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
(original)
+++ cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
Fri Aug 26 19:56:35 2011
@@ -354,6 +354,16 @@ Examples:
                 </associatedArgument>
             </option>
 
+            <option id="exceptionSuper" maxOccurs="1">
+                <annotation>
+                    Specifies the superclass to use for generated exceptions, the default
is java.lang.Exception.
+                </annotation>
+                <switch>exceptionSuper</switch>
+                <associatedArgument placement="afterSpace">
+                    <annotation>exceptionSuper</annotation>
+                </associatedArgument>
+            </option>
+
             <option id="mark-generated" maxOccurs="1">
                 <annotation>
                     Adds @Generated annotation in all java files that are generated.

Modified: cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java?rev=1162224&r1=1162223&r2=1162224&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
(original)
+++ cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
Fri Aug 26 19:56:35 2011
@@ -1542,6 +1542,36 @@ public class CodeGenTest extends Abstrac
         assertEquals(123456789L, l.longValue());
     }
     @Test
+    public void testNoExceptionSuper() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+        processor.setContext(env);
+        processor.execute();
+        
+        File faultFile = new File(output, "org/apache/cxf/w2j/hello_world_soap_http/NoSuchCodeLitFault.java");
+        assertTrue(faultFile.exists());
+        faultFile = new File(output, "org/apache/cxf/w2j/hello_world_soap_http/BadRecordLitFault.java");
+        assertTrue(faultFile.exists());
+        
+        Class<?> fault = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_http.NoSuchCodeLitFault");
+        assertEquals(Exception.class, fault.getSuperclass());
+    }
+    @Test
+    public void testExceptionSuper() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+        env.put(ToolConstants.CFG_EXCEPTION_SUPER, "java.lang.RuntimeException");
+        processor.setContext(env);
+        processor.execute();
+        
+        File faultFile = new File(output, "org/apache/cxf/w2j/hello_world_soap_http/NoSuchCodeLitFault.java");
+        assertTrue(faultFile.exists());
+        faultFile = new File(output, "org/apache/cxf/w2j/hello_world_soap_http/BadRecordLitFault.java");
+        assertTrue(faultFile.exists());
+        
+        Class<?> fault = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_http.NoSuchCodeLitFault");
+        assertEquals(RuntimeException.class, fault.getSuperclass());
+    }
+
+    @Test
     public void testExtensionWrapper() throws Exception {
         env.put(ToolConstants.CFG_WSDLURL,
                 getLocation("/wsdl2java_wsdl/cxf2193/hello_world_extension_wrapped.wsdl"));



Mime
View raw message