Issue Stats Issue Stats

jaxb2-rich-contract-plugin

A collection of JAXB / XJC plugins to generate advanced contract scenarios from XSD

Current Version: 2.0.0

This module is a collection of several plugins for the JAXB2 (Java API for XML binding) “XSD to Java Compiler” (XJC). These plugins are intended to add support for additional contracts to the classes generated by XJC. Currently, there are 7 plugin classes:

  1. fluent-builder: Generates a builder class for every class generated. Builders are implemented as inner classes, static methods are provided for a fluent builder pattern in the form MyClass.builder().withPropertyA(...).withPropertyB(...).build(). Builders also contain “copy…” methods to initialize the builder from another instance. Partial copying is also supported in the same way as in copy. This is particularly useful together with -Ximmutable (see above), but not usable together with -Xconstrained-properties (see below). fluent-builder offers a bunch of cool stuff usually not found in standard builder generators, such as generating builder from existing instances with optional partial copying, chained builders, <choice> expansion, etc.
  2. immutable: Will make generated classes immutable. Only makes sense together with “fluent-builder” plugin (see below), or any other builder or initialisation facility, like the well-known “value-constructor” plugin.
  3. group-contract: When using <attributeGroup> or <group> elements in an XSD, they are transformed as interface definitions, and any complexTypes using the groups will be generated as classes implementing this interface.
  4. clone: Will generate a simple deep “clone” method for the generated classes based on the heuristic that it only makes sense to traverse further down in the cloned object tree for members of types that are actually cloenable themselves.
  5. copy: Similar to “clone”, will generate a simple deep “createCopy” method. The java API contract for the java.lang.Cloneable interface and the rules for overriding Object.clone() are defective by design. So the “copy” plugin uses its own API to realize the desired behavior. Also can generate a “partial createCopy” method, that takes a PropertyTree object which represents an include/exclude rule for nodes in the object tree to clone. Excluded nodes will not be cloned and left alone. Optionally, corresponding copy constructors can also be generated.
  6. constrained-properties: Will generate a complexTypes element members as bound and/or constrained properties as per the JavaBeans spec.
  7. meta: Generates a nested class representing a static metamodel of the generated classes. In the “enhanced” version, this contains information about the type and the XSD element from which the property was generated, in “simple” mode, there are only constants for the property names.