com.legstar.jaxb.plugin
Class CobolJAXBAnnotator

java.lang.Object
  extended by com.sun.tools.xjc.Plugin
      extended by com.legstar.jaxb.plugin.CobolJAXBAnnotator

public class CobolJAXBAnnotator
extends com.sun.tools.xjc.Plugin

This is an extension to the JAXB XJC plugin. It is being invoked by the JAXB XML to Java compilation and injects supplementary cobol annotations into the generated Java classes. Add -Dcom.sun.tools.xjc.Options.findServices=true to VM arguments to help solve classpath issues.


Nested Class Summary
protected  class CobolJAXBAnnotator.EciCompatibleNameConverter
          This overrides the standard JAXB name converter when in ECI compatible mode.
protected  class CobolJAXBAnnotator.WinCompatibleNameConverter
          Some file names are forbidden on Windows.
 
Field Summary
static String OPTION_NAME
          Option passed to XJC to enable this cobol plugin.
static String OPTION_USAGE
          Command line help for cobol plugin XJC option.
 
Constructor Summary
CobolJAXBAnnotator()
           
 
Method Summary
protected  void annotateClass(com.sun.tools.xjc.outline.ClassOutline co)
          Propagate xsd complex type annotations on a class type.
 List<String> getCustomizationURIs()
          
 String getOptionName()
          
 String getUsage()
          
 boolean isCustomizationTagName(String nsUri, String localName)
          
 boolean isEciCompatible()
           
protected  void mapAnnotations(com.sun.tools.xjc.model.CPluginCustomization c, com.sun.codemodel.JAnnotationUse ce)
          Each annotation is extracted from the XML schema customization and injected back into the JAXB class code.
 int parseArgument(com.sun.tools.xjc.Options opt, String[] args, int i)
           .
 void postProcessModel(com.sun.tools.xjc.model.Model model, ErrorHandler errorHandler)
           XJC has built an abstract in-memory model of the target classes.
 boolean run(com.sun.tools.xjc.outline.Outline model, com.sun.tools.xjc.Options opt, ErrorHandler errorHandler)
           This is where the real action takes place.
protected  void setBooleanParm(Element e, String xmlMarkup, com.sun.codemodel.JAnnotationUse ce)
          Move an attribute value from the XML markup to the Cobol annotation.
protected  void setDefaultValue(com.sun.codemodel.JFieldVar jf, Element e)
          Attempts to set a default value for the java field based on the COBOL default value.
protected  void setNumericParm(Element e, String xmlMarkup, com.sun.codemodel.JAnnotationUse ce)
          Move an attribute value from the XML markup to the Cobol annotation.
protected  void setStringParm(Element e, String xmlMarkup, com.sun.codemodel.JAnnotationUse ce)
          Move an attribute value from the XML markup to the Cobol annotation.
 
Methods inherited from class com.sun.tools.xjc.Plugin
onActivated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_NAME

public static final String OPTION_NAME
Option passed to XJC to enable this cobol plugin.

See Also:
Constant Field Values

OPTION_USAGE

public static final String OPTION_USAGE
Command line help for cobol plugin XJC option.

See Also:
Constant Field Values
Constructor Detail

CobolJAXBAnnotator

public CobolJAXBAnnotator()
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

getCustomizationURIs

public List<String> getCustomizationURIs()

Overrides:
getCustomizationURIs in class com.sun.tools.xjc.Plugin

isCustomizationTagName

public boolean isCustomizationTagName(String nsUri,
                                      String localName)

Overrides:
isCustomizationTagName in class com.sun.tools.xjc.Plugin

parseArgument

public int parseArgument(com.sun.tools.xjc.Options opt,
                         String[] args,
                         int i)
                  throws com.sun.tools.xjc.BadCommandLineException,
                         IOException
. Since we have no direct way of communicating with the annotator, we pass options as extra XJC command line parameters.

Overrides:
parseArgument in class com.sun.tools.xjc.Plugin
Throws:
com.sun.tools.xjc.BadCommandLineException
IOException

postProcessModel

public void postProcessModel(com.sun.tools.xjc.model.Model model,
                             ErrorHandler errorHandler)

XJC has built an abstract in-memory model of the target classes. We are given a chance to tweak it.

Overrides:
postProcessModel in class com.sun.tools.xjc.Plugin

run

public boolean run(com.sun.tools.xjc.outline.Outline model,
                   com.sun.tools.xjc.Options opt,
                   ErrorHandler errorHandler)

This is where the real action takes place. XJC has done its job of building an in-memory model of the soon-to-be generated java classes. We are given a chance to change that model so that the generated classes will include the extra annotations that we need.

Specified by:
run in class com.sun.tools.xjc.Plugin

setDefaultValue

protected void setDefaultValue(com.sun.codemodel.JFieldVar jf,
                               Element e)
Attempts to set a default value for the java field based on the COBOL default value.

Will not attempt to initialize arrays or complex types.

Strings which COBOL peer defaults to low values or high values are initialized with an empty string.

Leading plus signs are removed from numerics, they cause NumberFormatException.

Parameters:
jf - the java field
e - the XML node holding COBOL annotations

annotateClass

protected void annotateClass(com.sun.tools.xjc.outline.ClassOutline co)
Propagate xsd complex type annotations on a class type.

Parameters:
co - the class outline

mapAnnotations

protected void mapAnnotations(com.sun.tools.xjc.model.CPluginCustomization c,
                              com.sun.codemodel.JAnnotationUse ce)
Each annotation is extracted from the XML schema customization and injected back into the JAXB class code.

Parameters:
c - the XML Schema annotation element
ce - the Java code Cobol annotation

setBooleanParm

protected void setBooleanParm(Element e,
                              String xmlMarkup,
                              com.sun.codemodel.JAnnotationUse ce)
Move an attribute value from the XML markup to the Cobol annotation.

Parameters:
e - the Node holding the XML markup
xmlMarkup - the name of the XML markup tag
ce - the target annotation recipient

setNumericParm

protected void setNumericParm(Element e,
                              String xmlMarkup,
                              com.sun.codemodel.JAnnotationUse ce)
Move an attribute value from the XML markup to the Cobol annotation.

Parameters:
e - the Node holding the XML markup
xmlMarkup - the name of the XML markup tag
ce - the target annotation recipient

setStringParm

protected void setStringParm(Element e,
                             String xmlMarkup,
                             com.sun.codemodel.JAnnotationUse ce)
Move an attribute value from the XML markup to the Cobol annotation.

Parameters:
e - the Node holding the XML markup
xmlMarkup - the name of the XML markup tag
ce - the target annotation recipient

isEciCompatible

public boolean isEciCompatible()
Returns:
true in ECI compatibility mode


Copyright © 2014 LegSem. All Rights Reserved.