From: Gustavo Martin Morcuende <gu.martinm@gmail.com>
Date: Mon, 8 Aug 2016 19:51:54 +0000 (+0200)
Subject: cxf-xjc-dv: how to use it and what is it for.
X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=aabb3d78924a1b014b5c91f9de97134b028a1a22;p=SpringWebServicesForFun%2F.git

cxf-xjc-dv: how to use it and what is it for.
---

diff --git a/SOAP/cxf/web-services-spring-cxf-globalxsds/pom.xml b/SOAP/cxf/web-services-spring-cxf-globalxsds/pom.xml
index ef09daf..050df12 100644
--- a/SOAP/cxf/web-services-spring-cxf-globalxsds/pom.xml
+++ b/SOAP/cxf/web-services-spring-cxf-globalxsds/pom.xml
@@ -49,6 +49,26 @@
 				<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>
diff --git a/SOAP/cxf/web-services-spring-cxf-globalxsds/src/main/resources/parent.xsd b/SOAP/cxf/web-services-spring-cxf-globalxsds/src/main/resources/parent.xsd
index fea4a95..1394a41 100644
--- a/SOAP/cxf/web-services-spring-cxf-globalxsds/src/main/resources/parent.xsd
+++ b/SOAP/cxf/web-services-spring-cxf-globalxsds/src/main/resources/parent.xsd
@@ -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>
diff --git a/SOAP/cxf/web-services-spring-cxf-server/pom.xml b/SOAP/cxf/web-services-spring-cxf-server/pom.xml
index 6807bad..32ddcbb 100644
--- a/SOAP/cxf/web-services-spring-cxf-server/pom.xml
+++ b/SOAP/cxf/web-services-spring-cxf-server/pom.xml
@@ -112,9 +112,32 @@
 			<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>