Class ValueConstructorPlugin

java.lang.Object
com.sun.tools.xjc.Plugin
org.jvnet.jaxb.plugin.value_constructor.ValueConstructorPlugin

public class ValueConstructorPlugin extends com.sun.tools.xjc.Plugin
Generate two constructors for each generated class, one of which is a default constructor, the other takes an argument for each field in the class and initialises the field with the argument value. Without this plugin, XJC will not generate any explicit constructors.
Author:
Kenny MacLeod $Id: XjcValueConstructorPlugin.java,v 1.7 2007-11-26 18:35:27 skaffman Exp $
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    generateConstructorParameter(com.sun.codemodel.JFieldVar field)
    Whether or not to generate a constructor parameter for the given field.
    protected Collection<com.sun.codemodel.JFieldVar>
    getInstanceFields(Collection<com.sun.codemodel.JFieldVar> fields)
    Takes a collection of fields, and returns a new collection containing only the instance (i.e. non-static) fields.
     
    protected List<com.sun.codemodel.JFieldVar>
    getSuperclassFields(com.sun.codemodel.JDefinedClass implClass)
    Retrieve a List of the fields of each ancestor class.
     
    boolean
    run(com.sun.tools.xjc.outline.Outline outline, com.sun.tools.xjc.Options options, ErrorHandler errorHandler)
     

    Methods inherited from class com.sun.tools.xjc.Plugin

    getCustomizationURIs, isCustomizationTagName, onActivated, parseArgument, postProcessModel

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ValueConstructorPlugin

      public ValueConstructorPlugin()
  • Method Details

    • getOptionName

      public String getOptionName()
      Specified by:
      getOptionName in class com.sun.tools.xjc.Plugin
    • getUsage

      public String getUsage()
      Specified by:
      getUsage in class com.sun.tools.xjc.Plugin
    • run

      public boolean run(com.sun.tools.xjc.outline.Outline outline, com.sun.tools.xjc.Options options, ErrorHandler errorHandler)
      Specified by:
      run in class com.sun.tools.xjc.Plugin
    • getInstanceFields

      protected Collection<com.sun.codemodel.JFieldVar> getInstanceFields(Collection<com.sun.codemodel.JFieldVar> fields)
      Takes a collection of fields, and returns a new collection containing only the instance (i.e. non-static) fields.
      Parameters:
      fields - fields to get non-static fields
      Returns:
      new List containing only non-static fields
    • generateConstructorParameter

      protected boolean generateConstructorParameter(com.sun.codemodel.JFieldVar field)
      Whether or not to generate a constructor parameter for the given field.
      Parameters:
      field - field to test
      Returns:
      true if we need to generate a constructor for the given field
    • getSuperclassFields

      protected List<com.sun.codemodel.JFieldVar> getSuperclassFields(com.sun.codemodel.JDefinedClass implClass)
      Retrieve a List of the fields of each ancestor class. I walk up the class hierarchy until I reach a class that isn't being generated by JAXB.
      Parameters:
      implClass - the class to get fields from
      Returns:
      List of fields in each ancestor class