You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2017/08/04 17:45:44 UTC

[2/4] cxf-xjc-utils git commit: [CXFXJC-19, CXFXJC-20, CXFXJC-21] Fix problems in DV plugin found while enabling it for more modules in CXF proper

[CXFXJC-19, CXFXJC-20, CXFXJC-21] Fix problems in DV plugin found while enabling it for more modules in CXF proper


Project: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/commit/1a9ba9e5
Tree: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/tree/1a9ba9e5
Diff: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/diff/1a9ba9e5

Branch: refs/heads/master
Commit: 1a9ba9e54e46ba4aeef598a155c34e7197b229c9
Parents: 83bc8c6
Author: Daniel Kulp <dk...@apache.org>
Authored: Fri Aug 4 13:40:48 2017 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Fri Aug 4 13:40:48 2017 -0400

----------------------------------------------------------------------
 .../apache/cxf/xjc/dv/DefaultValuePlugin.java   | 26 ++++++++++++++++----
 1 file changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/1a9ba9e5/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
----------------------------------------------------------------------
diff --git a/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java b/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
index e4bcb93..63d8ca4 100644
--- a/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
+++ b/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
@@ -68,6 +68,7 @@ public class DefaultValuePlugin {
     private static final Logger LOG = Logger.getLogger(DefaultValuePlugin.class.getName()); //NOPMD
     private boolean complexTypes;
     private boolean active;
+    private boolean attributes;
     
     public DefaultValuePlugin() {
     }
@@ -78,6 +79,7 @@ public class DefaultValuePlugin {
 
     public String getUsage() {
         return   "  -Xdv                 : Initialize fields mapped from elements with their default values\n"
+               + "  -Xdv:attributes      : Also initialize fields mapped from attributes with their default values\n"
                + "  -Xdv:optional        : Initialize fields mapped from elements with their default values\n"
                + "                         for elements with minOccurs=0 but with complexTypes containing \n"
                + "                         fields with default values.";
@@ -89,9 +91,12 @@ public class DefaultValuePlugin {
         
         if (args[index].startsWith("-Xdv")) {
             ret = 1;                    
-            if (args[index].equals("-Xdv:optional")) {
+            if (args[index].indexOf(":optional") != -1) {
                 complexTypes = true;
             }
+            if (args[index].indexOf(":attributes") != -1) {
+                attributes = true;
+            }
             if (!opt.activePlugins.contains(plugin)) {
                 opt.activePlugins.add(plugin);
             }
@@ -204,7 +209,7 @@ public class DefaultValuePlugin {
 
                 JExpression dvExpr = null;
                 if (null != xmlDefaultValue && null != xmlDefaultValue.value) {
-                    dvExpr = getDefaultValueExpression(f, co, outline, xsType, isElement,
+                    dvExpr = getDefaultValueExpression(f, co, outline, xsType, isElement | attributes,
                                                        xmlDefaultValue, false);
                 }
                  
@@ -215,11 +220,15 @@ public class DefaultValuePlugin {
                         .equals(xsType.getOwnerSchema().getTargetNamespace())) {
                     //non-primitive attribute, may still be able to convert it, but need to do
                     //a bunch more checks and changes to setters and isSet and such
+                    
                     dvExpr = 
-                        getDefaultValueExpression(f, co, outline, xsType, isElement, xmlDefaultValue, true);
+                        getDefaultValueExpression(f, co, outline, xsType, isElement | attributes, 
+                                                  xmlDefaultValue, true);
                     
-                    updateSetter(co, f, co.implClass);
-                    updateGetter(co, f, co.implClass, dvExpr, true);                    
+                    if (dvExpr != null) {
+                        updateSetter(co, f, co.implClass);
+                        updateGetter(co, f, co.implClass, dvExpr, true);
+                    }
                 } else if (null == dvExpr) {
                     JType type = f.getRawType();
                     String typeName = type.fullName();
@@ -424,6 +433,9 @@ public class DefaultValuePlugin {
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Updating setter: " + setterName);
         }
+        if (method == null) {
+            return;
+        }
         JDocComment doc = method.javadoc();
         // remove existing method and define new one
         dc.methods().remove(method);
@@ -438,6 +450,10 @@ public class DefaultValuePlugin {
         JFieldRef fr = JExpr.ref(fieldName);
         method.body().assign(fr, var);
         
+        method = dc.getMethod("unset" + fo.getPropertyInfo().getName(true), new JType[0]);
+        if (method != null) {
+            dc.methods().remove(method);
+        }
         method = dc.method(mods, method.type(), "unset" + fo.getPropertyInfo().getName(true));
         method.body().assign(fr, JExpr._null());