Author: dkulp
Date: Wed Nov 14 14:13:34 2007
New Revision: 595088

URL: http://svn.apache.org/viewvc?rev=595088&view=rev
Log:
Merged revisions 594483 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r594483 | mmao | 2007-11-13 06:08:37 -0500 (Tue, 13 Nov 2007) | 4 lines
  
  CXF-1206
    * xjc dv plugin provides default values for complexTypes that contain 
elements which have default values
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java
    
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd
    
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java?rev=595088&r1=595087&r2=595088&view=diff
==============================================================================
--- 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java
 (original)
+++ 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/java/org/apache/cxf/xjc/dv/DefaultValueTest.java
 Wed Nov 14 14:13:34 2007
@@ -149,6 +149,11 @@
     }
     
     private void assertDefaultElementValues(Foo foo) {
+        assertEquals("Unexpected value for element pageColor.background", 
"red", 
+                     foo.getPageColor().getBackground());
+        assertEquals("Unexpected value for element pageColor.foreground", 
"blue", 
+                     foo.getPageColor().getForeground());
+
         assertEquals("Unexpected value for element driving",
                      "LeftTurn", foo.getDriving().value());
         assertEquals("Unexpected value for element stringElem",

Modified: 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd
URL: 
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd?rev=595088&r1=595087&r2=595088&view=diff
==============================================================================
--- 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd
 (original)
+++ 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv-test/src/test/resources/schemas/configuration/foo.xsd
 Wed Nov 14 14:13:34 2007
@@ -41,8 +41,16 @@
        </xs:restriction>
     </xs:simpleType>
 
+    <xs:complexType name="pageColor">
+       <xs:sequence>
+           <xs:element name="background" type="xs:string" default="red"/>
+           <xs:element name="foreground" type="xs:string" default="blue"/>
+       </xs:sequence>
+    </xs:complexType>
+
     <xs:complexType name="foo">        
         <xs:sequence>
+           <xs:element name="pageColor" type="tns:pageColor" 
minOccurs="0"></xs:element>
             <xs:element name="driving" type="tns:drivingDecision" 
default="LeftTurn" minOccurs="0"></xs:element>
             <xs:element name="stringElem" type="xs:string" default="hello" 
minOccurs="0"></xs:element>
             <xs:element name="booleanElem" type="xs:boolean" default="true" 
minOccurs="0"></xs:element>

Modified: 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java?rev=595088&r1=595087&r2=595088&view=diff
==============================================================================
--- 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
 (original)
+++ 
incubator/cxf/branches/2.0.x-fixes/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
 Wed Nov 14 14:13:34 2007
@@ -36,6 +36,7 @@
 import com.sun.codemodel.JExpr;
 import com.sun.codemodel.JExpression;
 import com.sun.codemodel.JFieldRef;
+import com.sun.codemodel.JFieldVar;
 import com.sun.codemodel.JMethod;
 import com.sun.codemodel.JOp;
 import com.sun.codemodel.JType;
@@ -74,6 +75,29 @@
         return "  -Xdv                 : Initialize fields mapped from 
elements with their default values";
     }
 
+    private boolean containsDefaultValue(Outline outline, FieldOutline field) {
+        ClassOutline fClass = null;
+        for (ClassOutline classOutline : outline.getClasses()) {
+            if (classOutline.implClass == field.getRawType()) {
+                fClass = classOutline;
+                break;
+            }
+        }
+
+        for (FieldOutline f : fClass.getDeclaredFields()) {
+            if (f.getPropertyInfo().getSchemaComponent() instanceof 
XSParticle) {
+                XSParticle particle = 
(XSParticle)f.getPropertyInfo().getSchemaComponent();
+                XSTerm term = particle.getTerm();
+                if (term.isElementDecl()) {
+                    if (term.asElementDecl().getDefaultValue() != null) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
     public boolean run(Outline outline, Options opt, ErrorHandler 
errorHandler) {
         LOG.fine("Running default value plugin.");
         for (ClassOutline co : outline.getClasses()) {
@@ -103,6 +127,21 @@
                     XSAttributeDecl decl = attributeUse.getDecl();
                     xmlDefaultValue = decl.getDefaultValue();                  
      
                     xsType = decl.getType();
+                }
+
+                
+                if (xsType != null && xsType.isComplexType() && 
containsDefaultValue(outline, f)) {
+                    String varName = f.getPropertyInfo().getName(false);
+                    JFieldVar var = co.implClass.fields().get(varName);
+                    if (var != null) {
+                        co.implClass.removeField(var);
+
+                        JFieldVar newVar = 
co.implClass.field(var.mods().getValue(), 
+                                                              var.type(), 
+                                                              var.name(), 
+                                                              
JExpr._new(f.getRawType()));
+                        newVar.javadoc().append(var.javadoc());
+                    }
                 }
 
                 if (null == xmlDefaultValue || null == xmlDefaultValue.value) {


Reply via email to