1. CC-XJC

CC-XJC

Introduction

CC-XJC is a JAXB 2.0 XJC plugin for adding a copy constructor to schema derived classes. The plugin provides a '-copy-constructor' option which is enabled by adding its jar file to the XJC classpath. When enabled, the following options can be used to control the behavior of the plugin. See the examples for further information.

-cc-visibility

The '-cc-visibility' option can be used to specify the visibility of generated copy methods. It takes one argument from the list [private, package, protected, public]. This option impacts the number of generated methods. Default: private.

-cc-target

The '-cc-target' option can be used to specify a target JDK version for the generated code. It takes one argument from the list [1.5, 1.6, 1.7]. Default: 1.5.

-cc-nullable (since 1.1)

The '-cc-nullable' option got introduced in version 1.1. It can be used to instruct the plugin to allow passing 'null' references to copy constructors as it was the default in versions prior to 1.1. Starting with version 1.1, that default has been changed to throw a 'NullPointerException' for any 'null' references passed to copy constructors.

-cc-hierarchical (since 1.2)

The '-cc-hierarchical' option got introduced in version 1.2. It can be used to instruct the plugin to generate hierarchical copy constructors - copy constructors supporting copying from super types.

Example:

        <xsd:complexType name="Root"/>

        <xsd:complexType name="Parent">
          <xsd:complexContext>
            <xsd:extension base="Root"/>
          </xsd:complexContext>
        </xsd:complexType>

        <xsd:complexType name="Child">
          <xsd:complexContext>
            <xsd:extension base="Parent"/>
          </xsd:complexContext>
        </xsd:complexType>

Without the '-cc-hierarchical' option, the plugin will generate the following copy constructors (compatible with versions 1.0.x):

        public Root(final Root o)
        public Parent(final Parent o)
        public Child(final Child o)

Specifying the '-cc-hierarchical' option, the plugin will generate the following copy constructors allowing to create copies of super types.

        public Root(final Root o)
        public Parent(final Root o)
        public Child(final Root o)

Note: Using the '-cc-hierarchical' option has the drawback of losing type safety. There will be no compile errors and no runtime errors when accidentally passing the wrong instance to such a constructor. If you plan to use the '-cc-hierarchical' option, you may want to verify your code by regenerating your classes without that option and by inspecting any compile errors this produces to verify the instance passed to the copy constructor is the instance you intended to copy.

-cc-cloneable-types (since 1.3)

The '-cc-cloneable-types' option got introduced in version 1.3. It can be used to specify a list of class names of cloneable classes to support separated by ':'. The plugin adds the following types to that list by default.

  • java.util.Date
  • java.util.Calendar
  • java.util.TimeZone
  • java.util.Locale
  • javax.xml.datatype.XMLGregorianCalendar

As of version 1.5, entries starting with an '@' character are interpreted as a name of a file holding one type name per line.

-cc-immutable-types (since 1.3)

The '-cc-immutable-types' option got introduced in version 1.3. It can be used to specify a list of class names of immutable classes to support separated by ':'. The plugin adds the following types to that list by default.

  • java.lang.Boolean
  • java.lang.Byte
  • java.lang.Character
  • java.lang.Double
  • java.lang.Enum
  • java.lang.Float
  • java.lang.Integer
  • java.lang.Long
  • java.lang.Short
  • java.lang.String
  • java.math.BigDecimal
  • java.math.BigInteger
  • java.util.Currency
  • java.util.UUID
  • javax.xml.namespace.QName
  • javax.xml.datatype.Duration

As of version 1.5, entries starting with an '@' character are interpreted as a name of a file holding one type name per line.

-cc-string-types (since 1.5)

The '-cc-string-types' option got introduced in version 1.5. It can be used to specify a list of class names of string based datatype classes to support separated by ':'. Entries starting with an '@' character are interpreted as a name of a file holding one type name per line. A string based datatype class is a class which provides a public constructor taking a single string parameter which can be used to create a new instance of that type using the value returned by that type's toString method. The plugin adds the following types to that list by default.

  • java.io.File
  • java.net.URI
  • java.net.URL
  • javax.activation.MimeType

Support

Development of CC-XJC is community driven. Please file any issues with the MantisBT bugtracker or subscribe to the ccxjc-users mailing list for discussing issues or asking questions. You may also want to use the wiki for providing content related to CC-XJC yourself. Please note that applications provided by Sourceforge may require you to login to Sourceforge. If you do not have a Sourceforge account, simply create one at Sourceforge.

Examples

JAXB-RI CLI

To use the JAXB-RI XJC command line interface simply add the corresponding java archives to the classpath and execute the XJC main class 'com.sun.tools.xjc.Driver'. The following example demonstrates a working command line for use with JDK 1.5 (assuming the needed dependencies are found in the current working directory).

  java -cp activation-1.1.jar:\
           jaxb-api-2.0.jar:\
           stax-api-1.0.jar:\
           jaxb-impl-2.0.5.jar:\
           jaxb-xjc-2.0.5.jar:\
           cc-xjc-plugin-2.0.jar\
           com.sun.tools.xjc.Driver -d /tmp/src -copy-constructor <schema files>

Maven

Maven users simply add the CC-XJC plugin as a dependency to a JAXB plugin of choice. The following example demonstrates the use of the CC-XJC plugin with the Mojo jaxb2-maven-plugin.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>1.3</version>
  <dependencies>
    <dependency>
      <groupId>net.sourceforge.ccxjc</groupId>
      <artifactId>cc-xjc-plugin</artifactId>
      <version>2.0</version>
    </dependency>
  </dependencies>
  <executions>
    <execution>
      <id>xjc</id>
      <goals>
        <goal>xjc</goal>
      </goals>
      <configuration>
        <arguments>-copy-constructor</arguments>
        <extension>true</extension>
      </configuration>
    </execution>
  </executions>
</plugin>

Download

Releases

Releases are deployed to the central Maven 2 repository and to the Sourceforge file release system. The changes report contains information regarding changes between releases.

License

The CC-XJC Project Copyright

Copyright (C) 2009 The CC-XJC Project. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

o Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE CC-XJC PROJECT AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CC-XJC PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.