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.