Class 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 Detail

      • ValueConstructorPlugin

        public ValueConstructorPlugin()
    • Method Detail

      • 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