With cxf-xjc-plugin and cxf-codegen-plugin we can use many other plugins.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Mon, 18 May 2015 20:43:22 +0000 (22:43 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Mon, 18 May 2015 20:51:07 +0000 (22:51 +0200)
I was using jaxb2-basics for inheritance but now I also use jaxb2-basics-annotate
which allow me to annotate classes, methods properties, etc, etc. These plugins
generate code from xsd files. We can also use custom bindings if we do not want
(or we may not) modify the xsd files but we want to generate code with those
extensions (inheritance and annotation)

pom.xml
src/main/resources/xsd/custombinding.xjb
src/main/resources/xsd/examples.xsd

diff --git a/pom.xml b/pom.xml
index 450e486..79484f5 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <dependency>
             <groupId>org.jvnet.jaxb2_commons</groupId>
             <artifactId>jaxb2-basics-runtime</artifactId>
-            <version>0.6.3</version>
+            <version>0.9.4</version>
         </dependency>
        </dependencies>
        <build>
                 <plugin>
                     <groupId>org.apache.cxf</groupId>
                     <artifactId>cxf-xjc-plugin</artifactId>
-                    <version>2.3.0</version>
+                    <version>3.0.3</version>
                 </plugin>
                 <!-- Generate code from wsdl files (the client's code) -->
                 <plugin>
                     <groupId>org.apache.cxf</groupId>
                     <artifactId>cxf-codegen-plugin</artifactId>
-                    <version>2.3.0</version>
+                    <version>3.1.0</version>
                 </plugin>
                 <plugin>
                     <groupId>org.codehaus.mojo</groupId>
                                     <packagename>${project.xsd.schemas.package.name}</packagename>
                                     <extensionArgs>
                                         <extraarg>-Xinheritance</extraarg>
+                                        <extraarg>-Xannotate</extraarg>
                                      </extensionArgs> 
                                 </xsdOption>
                             </xsdOptions>
                         </configuration>
                     </execution>
                 </executions>
-                <!-- We make this plugin work with this jaxb2 version.
-                     This particular version let us generate inherited classes using
-                     the -Xinheritance argument. -->
-                <dependencies>
+               <dependencies>
+                    <!-- We make this plugin work with this jaxb2 version.
+                         This particular version let us generate inherited classes using
+                         the -Xinheritance argument.
+        
+                         DO NOT FORGET: We can use <inheritance:implements> in xsd files or by means 
+                         of custom bindings (see custombinding.xjb) This useful when you may not modify
+                         xsd files because they are generated by other person or machine.
+                    -->
                     <dependency>
                         <groupId>org.jvnet.jaxb2_commons</groupId>
                         <artifactId>jaxb2-basics</artifactId>
-                        <version>0.6.3</version>
+                        <version>0.9.4</version>
+                    </dependency>
+
+                    <!-- We make this plugin work with this jaxb2 version.
+                         This particular version let us generate annotated classes using
+                         the -Xannotate argument.
+
+                         DO NOT FORGET: We can use <annox:annotate> in xsd files or by means 
+                         of custom bindings like I did with <inheritance:implements> (see custombinding.xjb)
+                         This useful when you may not modify xsd files because they are generated
+                         by other person or machine.
+                    -->
+                    <dependency>
+                        <groupId>org.jvnet.jaxb2_commons</groupId>
+                        <artifactId>jaxb2-basics-annotate</artifactId>
+                        <version>1.0.1</version>
                     </dependency>
                 </dependencies>
             </plugin>
                         </configuration>
                      </execution>
                 </executions>
-                <!-- We make this plugin work with this jaxb2 version.
-                     This particular version let us generate inherited classes using
-                     the -xjc-Xinheritance argument. -->
                 <dependencies>
+                    <!-- We make this plugin work with this jaxb2 version.
+                         This particular version let us generate inherited classes using
+                         the -Xinheritance argument.
+        
+                         DO NOT FORGET: We can use <inheritance:implements> in xsd files or by means 
+                         of custom bindings (see custombinding.xjb) This useful when you may not modify
+                         xsd files because they are generated by other person or machine.
+                    -->
                     <dependency>
                         <groupId>org.jvnet.jaxb2_commons</groupId>
                         <artifactId>jaxb2-basics</artifactId>
-                        <version>0.6.3</version>
+                        <version>0.9.4</version>
                     </dependency>
                 </dependencies>
             </plugin> 
index 9ceb3a9..08d81e9 100644 (file)
@@ -3,8 +3,9 @@
 <jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
     xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
+    xmlns:annox="http://annox.dev.java.net"
     jaxb:version="2.1"
-    jaxb:extensionBindingPrefixes="inheritance">
+    jaxb:extensionBindingPrefixes="inheritance annox">
     
     <!--
     Se procesa con Xpath si quieres meter expresiones regulares y cosas así en teoría dependes de Xpath
@@ -23,6 +24,7 @@
     <jaxb:bindings schemaLocation="examples.xsd"> 
         <jaxb:bindings node="//xsd:element[@name='CustomBindingExampleRequest']/xsd:complexType">
                 <inheritance:implements>de.spring.webservices.operations.Request</inheritance:implements>
+                <annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate>
         </jaxb:bindings>
     </jaxb:bindings>
 
     <jaxb:bindings schemaLocation="examples.xsd"> 
         <jaxb:bindings node="//xsd:element[@name='CustomBindingExampleResponse']/xsd:complexType">
                 <inheritance:implements>de.spring.webservices.operations.Response</inheritance:implements>
+                <annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate>
         </jaxb:bindings>
     </jaxb:bindings>
 
+    <!-- The same applies to annotate. If you do not want or you may not modify your xsd files you cand
+         modify instead this file with your custom binding :) -->
+
 </jaxb:bindings>
index d951278..f8f068b 100644 (file)
@@ -4,8 +4,9 @@
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
     xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
+    xmlns:annox="http://annox.dev.java.net"
     jaxb:version="2.1"
-    jaxb:extensionBindingPrefixes="inheritance"
+    jaxb:extensionBindingPrefixes="inheritance annox"
     elementFormDefault="qualified"
     targetNamespace="http://localhost:8888/spring-ws/example">
        
@@ -14,6 +15,7 @@
           <xs:complexType>
               <xs:annotation>
                 <xs:appinfo>
+                    <annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate> 
                     <inheritance:implements>de.spring.webservices.operations.Request</inheritance:implements>
                 </xs:appinfo>
             </xs:annotation>