All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.tools.xjc.Plugin Maven / Gradle / Ivy

There is a newer version: 4.0.5
Show newest version
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 * 
 * You can obtain a copy of the license at
 * https://jwsdp.dev.java.net/CDDLv1.0.html
 * See the License for the specific language governing
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL
 * HEADER in each file and include the License file at
 * https://jwsdp.dev.java.net/CDDLv1.0.html  If applicable,
 * add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your
 * own identifying information: Portions Copyright [yyyy]
 * [name of copyright owner]
 */
package com.sun.tools.xjc;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import com.sun.tools.xjc.model.CPluginCustomization;
import com.sun.tools.xjc.outline.Outline;
import com.sun.tools.xjc.generator.bean.field.FieldRendererFactory;

import org.xml.sax.ErrorHandler;

/**
 * Add-on that works on the generated source code.
 * 
 * 

* This add-on will be called after the default bean generation * has finished. * * @author * Kohsuke Kawaguchi ([email protected]) * * @since * JAXB RI 2.0 EA */ public abstract class Plugin { /** * Gets the option name to turn on this add-on. * *

* 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 {@link Plugin} * will be invoked. */ public abstract String getOptionName(); /** * Gets the description of this add-on. Used to generate * a usage screen. * * @return * localized description message. should be terminated by \n. */ public abstract String getUsage(); /** * Parses an option 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 {@link #getOptionName().) * * But nevertheless a {@link Plugin} needs to be activated * to participate in further processing. * * @return * 0 if the argument is not understood. * Otherwise return the number of tokens that are * consumed, including the option itself. * (so if you have an option like "-foo 3", return 2.) * @exception 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. */ public int parseArgument( Options opt, String[] args, int i ) throws BadCommandLineException, IOException { return 0; } /** * Returns the list of namespace URIs that are supported by this plug-in * as schema annotations. * *

* 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. * * @return * can be empty, be never be null. */ public List getCustomizationURIs() { return Collections.emptyList(); } /** * Checks if the given tag name is a valid tag name for the customization element in this plug-in. * *

* 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 * {@link #run} method before using any {@link CPluginCustomization}, to make sure that it * has proper child elements and attributes. * * @param nsUri * the namespace URI of the element. Never null. * @param localName * the local name of the element. Never null. */ public boolean isCustomizationTagName(String nsUri,String localName) { return false; } /** * Notifies a plugin that it's activated. * *

* This method is called when a plugin is activated * through the command line option (as specified by {@link #getOptionName()}. * *

* This is a good opportunity to use * {@link Options#setFieldRendererFactory(FieldRendererFactory, Plugin)} * if a plugin so desires. * *

* Noop by default. * * @since JAXB 2.0 EA4 */ public void onActivated(Options opts) throws BadCommandLineException { // noop } /** * Run the add-on. * *

* 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 {@link Outline} and {@link Options}. * *

* Note that this method is invoked only when a {@link Plugin} * is activated. * * @param outline * This object allows access to various generated code. * * @param errorHandler * Errors should be reported to this handler. * * @return * If the add-on executes successfully, return true. * If it detects some errors but those are reported and * recovered gracefully, return false. */ public abstract boolean run( Outline outline, Options opt, ErrorHandler errorHandler ); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy