cxf-xjc-dv: how to use it and what is it for.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 8 Aug 2016 19:51:54 +0000 (21:51 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 8 Aug 2016 20:13:15 +0000 (22:13 +0200)
SOAP/cxf/web-services-spring-cxf-globalxsds/pom.xml
SOAP/cxf/web-services-spring-cxf-globalxsds/src/main/resources/parent.xsd
SOAP/cxf/web-services-spring-cxf-server/pom.xml

index ef09daf..050df12 100644 (file)
                                <configuration>
                                        <fork>true</fork>
                                        <extensions>
+                        <!--
+                            By means of the CXF XJC Default Value Plugin (cxf-xjc-dv) Java objects
+                            will return (as default value) their default values declared in the XSD file.
+                            This feature is not found in the xjc Java tool.
+
+                            It is using the XSD attributes "default", "maxocurrs", "minocurrs" when
+                            trying to find the default value to be returned when no other value
+                            is available in the Java object.
+
+                            For using 
+                            a) default plugin's behaviour:
+                              <extensionArgs>
+                                       <extraarg>-Xdv</extraarg>   Initialize fields mapped from elements with their default values
+                              </extensionArgs>
+                            b) optional plugin's behaviour:
+                              <extensionArgs>
+                                       <extraarg>-Xdv:optional</extraarg> Initialize fields mapped from elements with their default values
+                              </extensionArgs>                            for elements with minOccurs=0 but with complexTypes containing
+                                                                          fields with default values.
+                        -->
                                                <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:3.0.3</extension>
                                        </extensions>
                                </configuration>
@@ -67,6 +87,9 @@
                                                                        <xsd>${project.xsd.schemas.source.path}/parent.xsd</xsd>
                                                                        <bindingFile>${project.bindings.path}/custombinding.xjb</bindingFile>
                                                                        <packagename>${project.xsd.schemas.package.name}</packagename>
+                                    <extensionArgs>
+                                        <extraarg>-Xdv:optional</extraarg>
+                                    </extensionArgs>
                                                                </xsdOption>
                                                        </xsdOptions>
                                                </configuration>
index fea4a95..1394a41 100644 (file)
@@ -35,7 +35,7 @@
        <!-- WARNING: I DO NOT KNOW WHY BUT TYPES WORK BETTER WITH JAXB IF THEY END WITH THE Type SUFFIX!!!! :/ -->
        <xsd:complexType name="elementType">
         <xsd:sequence>
-            <xsd:element name="message" type="xsd:string"/>
+            <xsd:element name="message" type="xsd:string" default="This is a default message. Used by cxf-xjc-dv."/>
             <xsd:element name="messageArgs" type="xsd:string" minOccurs="0" maxOccurs="100"/>
         </xsd:sequence>
     </xsd:complexType>
@@ -43,7 +43,7 @@
     <xsd:element id="GeneralFault" name="GeneralFault">
        <xsd:complexType>
                <xsd:sequence>
-                       <xsd:element name="technicalError" type="xsd:string" />
+                       <xsd:element name="technicalError" type="xsd:string" default="This is a default error. Used by cxf-xjc-dv."/>
                        <xsd:element name="elements" type="elementType" minOccurs="0" maxOccurs="unbounded"/>
                </xsd:sequence>
        </xsd:complexType>
index 6807bad..32ddcbb 100644 (file)
                        <plugin>
                                <groupId>org.apache.cxf</groupId>
                                <artifactId>cxf-xjc-plugin</artifactId>
+                <version>3.0.3</version>
                                <configuration>
                                        <fork>true</fork>
                                        <extensions>
+                        <!--
+                            By means of the CXF XJC Default Value Plugin (cxf-xjc-dv) Java objects
+                            will return (as default value) their default values declared in the XSD file.
+                            This feature is not found in the xjc Java tool.
+
+                            It is using the XSD attributes "default", "maxocurrs", "minocurrs" when
+                            trying to find the default value to be returned when no other value
+                            is available in the Java object.
+
+                            For using 
+                            a) default plugin's behaviour:
+                              <extensionArgs>
+                                       <extraarg>-Xdv</extraarg>   Initialize fields mapped from elements with their default values
+                              </extensionArgs>
+                            b) optional plugin's behaviour:
+                              <extensionArgs>
+                                       <extraarg>-Xdv:optional</extraarg> Initialize fields mapped from elements with their default values
+                              </extensionArgs>                            for elements with minOccurs=0 but with complexTypes containing
+                                                                          fields with default values.
+
+                            FOR AN EXAMPLE SEE pom.xml IN web-services-spring-cxf-globalxsds
+                        -->
                                                <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:3.0.3</extension>
                                        </extensions>
                                </configuration>