public abstract class Plugin extends Object
This add-on will be called after the default bean generation has finished.
Constructor and Description |
---|
Plugin() |
Modifier and Type | Method and Description |
---|---|
List<String> |
getCustomizationURIs()
Returns the list of namespace URIs that are supported by this plug-in
as schema annotations.
|
abstract String |
getOptionName()
Gets the option name to turn on this add-on.
|
abstract String |
getUsage()
Gets the description of this add-on.
|
boolean |
isCustomizationTagName(String nsUri,
String localName)
Checks if the given tag name is a valid tag name for the customization element in this plug-in.
|
void |
onActivated(Options opts)
Notifies a plugin that it's activated.
|
int |
parseArgument(Options opt,
String[] args,
int i)
Parses an option
args[i] and augment
the opt object appropriately, then return
the number of tokens consumed. |
void |
postProcessModel(Model model,
ErrorHandler errorHandler)
Performs the post-processing of the
Model . |
abstract boolean |
run(Outline outline,
Options opt,
ErrorHandler errorHandler)
Run the add-on.
|
public abstract String getOptionName()
For example, if "abc" is returned, "-abc" will
turn on this plugin. A plugin needs to be turned
on explicitly, or else no other methods of Plugin
will be invoked.
Starting 2.1, when an option matches the name returned
from this method, XJC will then invoke parseArgument(Options, String[], int)
,
allowing plugins to handle arguments to this option.
public abstract String getUsage()
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException
args[i]
and augment
the opt
object appropriately, then return
the number of tokens consumed.
The callee doesn't need to recognize the option that the getOptionName method returns.
Once a plugin is activated, this method is called for options that XJC didn't recognize. This allows a plugin to define additional options to customize its behavior.
Since options can appear in no particular order,
XJC allows sub-options of a plugin to show up before
the option that activates a plugin (one that's returned
by getOptionName()
.
But nevertheless a Plugin
needs to be activated
to participate in further processing.
BadCommandLineException
- If the option was recognized but there's an error.
This halts the argument parsing process and causes
XJC to abort, reporting an error.IOException
public List<String> getCustomizationURIs()
If a plug-in returns a non-empty list, the JAXB RI will recognize these namespace URIs as vendor extensions (much like "http://java.sun.com/xml/ns/jaxb/xjc"). This allows users to write those annotations inside a schema, or in external binding files, and later plug-ins can access those annotations as DOM nodes.
See http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html for the syntax that users need to use to enable extension URIs.
public boolean isCustomizationTagName(String nsUri, String localName)
This method is invoked by XJC to determine if the user-specified customization element is really a customization or not. This information is used to pick the proper error message.
A plug-in is still encouraged to do the validation of the customization element in the
run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler)
method before using any CPluginCustomization
, to make sure that it
has proper child elements and attributes.
nsUri
- the namespace URI of the element. Never null.localName
- the local name of the element. Never null.public void onActivated(Options opts) throws BadCommandLineException
This method is called when a plugin is activated
through the command line option (as specified by getOptionName()
.
This is a good opportunity to use
Options.setFieldRendererFactory(FieldRendererFactory, Plugin)
if a plugin so desires.
Noop by default.
BadCommandLineException
public void postProcessModel(Model model, ErrorHandler errorHandler)
Model
.
This method is invoked after XJC has internally finished the model construction. This is a chance for a plugin to affect the way code generation is performed.
Compared to the run(Outline, Options, ErrorHandler)
method, this method allows a plugin to work at the higher level
conceptually closer to the abstract JAXB model, as opposed to
Java syntax level.
Note that this method is invoked only when a Plugin
is activated.
model
- The object that represents the classes/properties to
be generated.errorHandler
- Errors should be reported to this handler.public abstract boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException
This method is invoked after XJC has internally finished
the code generation. Plugins can tweak some of the generated
code (or add more code) by using Outline
and Options
.
Note that this method is invoked only when a Plugin
is activated.
outline
- This object allows access to various generated code.errorHandler
- Errors should be reported to this handler.SAXException
- After an error is reported to ErrorHandler
, the
same exception can be thrown to indicate a fatal irrecoverable
error. ErrorHandler
itself may throw it, if it chooses
not to recover from the error.Copyright © 2019 JBoss by Red Hat. All rights reserved.