cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: [CXFXJC-7] Make sure list types aren't instantiated.
Date Thu, 26 Jun 2014 13:57:55 GMT
Repository: cxf-xjc-utils
Updated Branches:
  refs/heads/master 2d065ea5a -> 2283c8d05


[CXFXJC-7] Make sure list types aren't instantiated.


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/2283c8d0
Tree: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/tree/2283c8d0
Diff: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/diff/2283c8d0

Branch: refs/heads/master
Commit: 2283c8d0588e8765bdfa74010e124eb40e3da2f2
Parents: 2d065ea
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Jun 26 09:57:27 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Thu Jun 26 09:57:27 2014 -0400

----------------------------------------------------------------------
 .../src/test/resources/schemas/configuration/foo.xsd | 15 +++++++++++++++
 .../org/apache/cxf/xjc/dv/DefaultValuePlugin.java    | 10 +++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/2283c8d0/dv-test/src/test/resources/schemas/configuration/foo.xsd
----------------------------------------------------------------------
diff --git a/dv-test/src/test/resources/schemas/configuration/foo.xsd b/dv-test/src/test/resources/schemas/configuration/foo.xsd
index 7256fbc..98d0633 100644
--- a/dv-test/src/test/resources/schemas/configuration/foo.xsd
+++ b/dv-test/src/test/resources/schemas/configuration/foo.xsd
@@ -133,4 +133,19 @@
     
     <xs:element name="fooElement" type="tns:foo"/>
     
+    
+	<xs:element name="itemRedemption">
+      <xs:complexType>
+      	<xs:sequence>
+	      <xs:element name="userId" type="xs:string" />
+       	  <xs:element name="redemptions" maxOccurs="unbounded" type="tns:externalItem"
/>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  
+    <xs:complexType name="externalItem">
+      <xs:sequence>
+        <xs:element minOccurs="0" name="redemptionNumber" type="xs:string" />
+      </xs:sequence>
+    </xs:complexType>    
 </xs:schema>

http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/2283c8d0/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 a46ace0..fdd6e2e 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
@@ -133,6 +133,14 @@ public class DefaultValuePlugin {
             throw new RuntimeException(e);
         }
     }
+    private int getMaxOccurs(XSParticle particle) {
+        try {
+            Number o = (Number)particle.getClass().getMethod("getMaxOccurs").invoke(particle);
+            return o.intValue(); 
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
     
     public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
         if (!active) {
@@ -173,7 +181,7 @@ public class DefaultValuePlugin {
                 if (xsType != null 
                     && xsType.isComplexType()
                     && ((containsDefaultValue(outline, f) && complexTypes)
-                        || (particle != null && getMinOccurs(particle) != 0))) {
+                        || (particle != null && getMinOccurs(particle) != 0 &&
getMaxOccurs(particle) == 1))) {
                     String varName = f.getPropertyInfo().getName(false);
                     JFieldVar var = co.implClass.fields().get(varName);
                     if (var != null) {


Mime
View raw message