cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r906033 - in /cxf/trunk/common/xjc: boolean-test/ dv-test/ dv/src/main/java/org/apache/cxf/xjc/dv/ ts-test/ ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ ts/src/main/java/org/apache/cxf/xjc/ts/ wsdlextension-test/ wsdlextension/ w...
Date Wed, 03 Feb 2010 12:48:11 GMT
Author: dkulp
Date: Wed Feb  3 12:47:47 2010
New Revision: 906033

URL: http://svn.apache.org/viewvc?rev=906033&view=rev
Log:
Work toward making the xjc things a little more self standing

Modified:
    cxf/trunk/common/xjc/boolean-test/pom.xml
    cxf/trunk/common/xjc/dv-test/pom.xml
    cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
    cxf/trunk/common/xjc/ts-test/pom.xml
    cxf/trunk/common/xjc/ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ToStringPlugin.java
    cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java
    cxf/trunk/common/xjc/wsdlextension-test/pom.xml
    cxf/trunk/common/xjc/wsdlextension/pom.xml
    cxf/trunk/common/xjc/wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/WSDLExtension.java

Modified: cxf/trunk/common/xjc/boolean-test/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/boolean-test/pom.xml?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/boolean-test/pom.xml (original)
+++ cxf/trunk/common/xjc/boolean-test/pom.xml Wed Feb  3 12:47:47 2010
@@ -63,11 +63,6 @@
 			<artifactId>junit</artifactId>
 			<scope>test</scope>
 		</dependency>
-		<dependency>
-			<groupId>org.apache.cxf</groupId>
-			<artifactId>cxf-common-utilities</artifactId>
-			<version>${project.version}</version>
-		</dependency>
 	</dependencies>
 
 	<build>

Modified: cxf/trunk/common/xjc/dv-test/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/dv-test/pom.xml?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/dv-test/pom.xml (original)
+++ cxf/trunk/common/xjc/dv-test/pom.xml Wed Feb  3 12:47:47 2010
@@ -58,11 +58,6 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-common-utilities</artifactId>
-            <version>${project.version}</version>
-        </dependency>
     </dependencies>
 
     <build>

Modified: cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java (original)
+++ cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java Wed
Feb  3 12:47:47 2010
@@ -24,6 +24,8 @@
 
 import javax.xml.bind.DatatypeConverter;
 import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 
@@ -39,6 +41,7 @@
 import com.sun.codemodel.JFieldVar;
 import com.sun.codemodel.JMethod;
 import com.sun.codemodel.JOp;
+import com.sun.codemodel.JTryBlock;
 import com.sun.codemodel.JType;
 import com.sun.tools.xjc.Options;
 import com.sun.tools.xjc.outline.ClassOutline;
@@ -159,8 +162,12 @@
                     
                     updateSetter(co, f, co.implClass);
                     updateGetter(co, f, co.implClass, dvExpr, true);                    
-                    
                 } else if (null == dvExpr) {
+                    JType type = f.getRawType();
+                    String typeName = type.fullName();
+                    if ("javax.xml.datatype.Duration".equals(typeName)) {
+                        updateDurationGetter(co, f, co.implClass, xmlDefaultValue, outline);
+                    }
                     continue;
                 } else {
                     updateGetter(co, f, co.implClass, dvExpr, false);                   

@@ -172,6 +179,42 @@
     }
     
     
+    private void updateDurationGetter(ClassOutline co, FieldOutline fo, JDefinedClass dc,
+                                      XmlString xmlDefaultValue, Outline outline) {
+        String fieldName = fo.getPropertyInfo().getName(false);
+
+        String getterName = "get" + fo.getPropertyInfo().getName(true);
+
+        JMethod method = dc.getMethod(getterName, new JType[0]);
+        JDocComment doc = method.javadoc();
+        int mods = method.mods().getValue();
+        JType mtype = method.type();
+
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("Updating getter: " + getterName);
+        }
+        // remove existing method and define new one
+
+        dc.methods().remove(method);
+
+        method = dc.method(mods, mtype, getterName);
+        method.javadoc().append(doc);
+
+        JFieldRef fr = JExpr.ref(fieldName);
+        if (xmlDefaultValue != null) {
+            JExpression test = JOp.eq(JExpr._null(), fr);
+            JConditional jc =  method.body()._if(test);
+            JTryBlock b = jc._then()._try();
+            b.body()._return(outline.getCodeModel().ref(DatatypeFactory.class)
+                .staticInvoke("newInstance").invoke("newDuration").arg(JExpr.lit(xmlDefaultValue.value)));
+            b._catch(outline.getCodeModel().ref(DatatypeConfigurationException.class));
+            method.body()._return(fr);
+        } else {
+            method.body()._return(fr);
+        }
+
+    }
+
     JExpression getDefaultValueExpression(FieldOutline f,
                                           ClassOutline co,
                                           Outline outline,
@@ -235,8 +278,7 @@
                 .arg(qn.getLocalPart())
                 .arg(qn.getPrefix());
         } else if ("javax.xml.datatype.Duration".equals(typeName)) {
-            dv = outline.getCodeModel().ref("org.apache.cxf.jaxb.DatatypeFactory")
-                .staticInvoke("createDuration").arg(defaultValue);
+            dv = null;
         } else if (type instanceof JDefinedClass) {
             JDefinedClass cls = (JDefinedClass)type;
             if (cls.getClassType() == ClassType.ENUM) {
@@ -306,10 +348,8 @@
             JExpression test = JOp.eq(JExpr._null(), fr);
             JConditional jc =  method.body()._if(test);
             jc._then()._return(dvExpr);
-            jc._else()._return(fr);
-        } else {
-            method.body()._return(fr);
         }
+        method.body()._return(fr);
     }
     private void updateSetter(ClassOutline co, FieldOutline fo, 
                               JDefinedClass dc) {

Modified: cxf/trunk/common/xjc/ts-test/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/ts-test/pom.xml?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/ts-test/pom.xml (original)
+++ cxf/trunk/common/xjc/ts-test/pom.xml Wed Feb  3 12:47:47 2010
@@ -52,11 +52,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-common-utilities</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
             <groupId>commons-lang</groupId>
             <artifactId>commons-lang</artifactId>
         </dependency>
@@ -78,7 +73,7 @@
                 <configuration>
                     <outputDirectory>${basedir}/target/generated/src/test/java</outputDirectory>
                     <schemaDirectory>${basedir}/src/test/resources/schemas/configuration</schemaDirectory>
-                    <arguments>-Xts</arguments>
+                    <arguments>-Xts:style:org.apache.commons.lang.builder.ToStringStyle.DEFAULT_STYLE</arguments>
                     <extension>true</extension>
                     <quiet>true</quiet>
                 </configuration>

Modified: cxf/trunk/common/xjc/ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ToStringPlugin.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ToStringPlugin.java?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ToStringPlugin.java
(original)
+++ cxf/trunk/common/xjc/ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ToStringPlugin.java
Wed Feb  3 12:47:47 2010
@@ -62,6 +62,11 @@
         return impl.run(outline, opt, errorHandler);
     }
 
+    public void onActivated(Options opts) throws BadCommandLineException {
+        impl.onActivated(opts);
+    }
+
+    
     /* (non-Javadoc)
      * @see com.sun.tools.xjc.Plugin#parseArgument(com.sun.tools.xjc.Options, java.lang.String[],
int)
      */

Modified: cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java (original)
+++ cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java Wed Feb
 3 12:47:47 2010
@@ -46,38 +46,59 @@
     private static final Logger LOG = Logger.getLogger(ToStringPlugin.class.getName()); //NOPMD
 
     private String styleFieldName = "DEFAULT_STYLE";
+    private String styleClassName = "org.apache.cxf.jaxb.JAXBToStringStyle";
+    private boolean active;
+    
     public String getOptionName() {
         return "Xts";
     }
 
     public String getUsage() {
         return "  -Xts                 : Activate plugin to add a toString() method to generated
classes\n"
+            +  "         equivalent to: -Xts:style:org.apache.cxf.jaxb.JAXBToStringStyle.DEFAULT_STYLE\n"
             +  "  -Xts:style:multiline : Have toString produce multi line output\n"
-            +  "  -Xts:style:simple    : Have toString produce single line terse output";
+            +  "         equivalent to: -Xts:style:org.apache.cxf.jaxb.JAXBToStringStyle.MULTI_LINE_STYLE\n"
+            +  "  -Xts:style:simple    : Have toString produce single line terse output\n"
+            +  "         equivalent to: -Xts:style:org.apache.cxf.jaxb.JAXBToStringStyle.SIMPLE_STYLE\n"
+            +  "  -Xts:style:org.apache.commons.lang.builder.ToStringStyle.FIELD : The full
class+field\n"
+            +  "         name of the ToStringStyle to use.";
     }
 
     public int parseArgument(Options opt, String[] args, int index, com.sun.tools.xjc.Plugin
plugin) 
         throws BadCommandLineException, IOException {
         int ret = 0;
-        if (args[index].equals("-Xts:style:multiline")) {
-            styleFieldName = "MULTI_LINE_STYLE";
-            ret = 1;
-        } else if (args[index].equals("-Xts:style:simple")) {
-            styleFieldName = "SIMPLE_STYLE";
-            ret = 1;
-        }
-        if (!opt.activePlugins.contains(plugin)) {
-            opt.activePlugins.add(plugin);
+        
+        if (args[index].startsWith("-Xts")) {
+            ret = 1;                    
+            if (args[index].startsWith("-Xts:style:")) {
+                String v = args[index].substring("-Xts:style:".length());
+                if ("multiline".equals(v)) {
+                    styleFieldName = "MULTI_LINE_STYLE";
+                } else if ("simple".equals(v)) {
+                    styleFieldName = "SIMPLE_STYLE";                    
+                } else {
+                    int idx = v.lastIndexOf('.');
+                    styleFieldName = v.substring(idx + 1);
+                    styleClassName = v.substring(0, idx);
+                }
+            }
+            if (!opt.activePlugins.contains(plugin)) {
+                opt.activePlugins.add(plugin);
+            }
+            active = true;
         }
         return ret;
     }
     
     public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
         LOG.fine("Running toString() plugin.");
-        
+        if (!active) {
+            return true;
+        }
+
         final JClass toStringDelegateImpl = outline.getCodeModel()
-            .ref("org.apache.cxf.jaxb.JAXBToStringBuilder");
-        final JClass styleClass = outline.getCodeModel().ref("org.apache.cxf.jaxb.JAXBToStringStyle");
+            .ref("org.apache.commons.lang.builder.ToStringBuilder");
+        final JClass styleClass = outline.getCodeModel().ref(styleClassName);
         final JFieldRef toStringDelegateStyleParam = styleClass.staticRef(styleFieldName);
         
         for (ClassOutline co : outline.getClasses()) {
@@ -91,8 +112,9 @@
                                    JClass delegateImpl, 
                                    JFieldRef toStringDelegateStyleParam) {
         final JDefinedClass implementation = co.implClass;
+        
         final JMethod toStringMethod = implementation.method(JMod.PUBLIC, String.class, "toString");
-        final JInvocation invoke = delegateImpl.staticInvoke("valueOf");
+        final JInvocation invoke = delegateImpl.staticInvoke("reflectionToString");
         invoke.arg(JExpr._this());
         invoke.arg(toStringDelegateStyleParam);
         toStringMethod.body()._return(invoke);
@@ -102,4 +124,8 @@
         doc.add("\nThis is an extension method, produced by the 'ts' xjc plugin");
         toStringMethod.annotate(Override.class);
     }
+
+    public void onActivated(Options opts) {
+        active = true;
+    }
 }

Modified: cxf/trunk/common/xjc/wsdlextension-test/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/wsdlextension-test/pom.xml?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/wsdlextension-test/pom.xml (original)
+++ cxf/trunk/common/xjc/wsdlextension-test/pom.xml Wed Feb  3 12:47:47 2010
@@ -52,14 +52,13 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-common-utilities</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
         </dependency>
+        <dependency>
+           <groupId>wsdl4j</groupId>
+           <artifactId>wsdl4j</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

Modified: cxf/trunk/common/xjc/wsdlextension/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/wsdlextension/pom.xml?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/wsdlextension/pom.xml (original)
+++ cxf/trunk/common/xjc/wsdlextension/pom.xml Wed Feb  3 12:47:47 2010
@@ -38,11 +38,6 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-common-utilities</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
             <groupId>com.sun.xml.bind</groupId>
             <artifactId>jaxb-xjc</artifactId>
         </dependency>
@@ -54,6 +49,10 @@
             <groupId>commons-lang</groupId>
             <artifactId>commons-lang</artifactId>
         </dependency>
+        <dependency>
+            <groupId>wsdl4j</groupId>
+            <artifactId>wsdl4j</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

Modified: cxf/trunk/common/xjc/wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/WSDLExtension.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xjc/wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/WSDLExtension.java?rev=906033&r1=906032&r2=906033&view=diff
==============================================================================
--- cxf/trunk/common/xjc/wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/WSDLExtension.java
(original)
+++ cxf/trunk/common/xjc/wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/WSDLExtension.java
Wed Feb  3 12:47:47 2010
@@ -41,11 +41,9 @@
 import com.sun.tools.xjc.outline.ClassOutline;
 import com.sun.tools.xjc.outline.Outline;
 
-import org.apache.cxf.common.logging.LogUtils;
-
 public class WSDLExtension {
 
-    private static final Logger LOG = LogUtils.getL7dLogger(WSDLExtension.class);
+    private static final Logger LOG = Logger.getLogger(WSDLExtension.class.getName()); //NOPMD
 
     public String getOptionName() {
         return "Xwsdlextension";



Mime
View raw message