src/share/jaxws_classes/com/sun/tools/internal/xjc/Plugin.java

changeset 286
f50545b5e2f1
parent 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/xjc/Plugin.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,245 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.xjc;
    1.30 +
    1.31 +import java.io.IOException;
    1.32 +import java.util.Collections;
    1.33 +import java.util.List;
    1.34 +
    1.35 +import com.sun.tools.internal.xjc.generator.bean.field.FieldRendererFactory;
    1.36 +import com.sun.tools.internal.xjc.model.CPluginCustomization;
    1.37 +import com.sun.tools.internal.xjc.model.Model;
    1.38 +import com.sun.tools.internal.xjc.outline.Outline;
    1.39 +
    1.40 +import org.xml.sax.ErrorHandler;
    1.41 +import org.xml.sax.SAXException;
    1.42 +
    1.43 +/**
    1.44 + * Add-on that works on the generated source code.
    1.45 + *
    1.46 + * <p>
    1.47 + * This add-on will be called after the default bean generation
    1.48 + * has finished.
    1.49 + *
    1.50 + * @author
    1.51 + *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    1.52 + *
    1.53 + * @since
    1.54 + *      JAXB RI 2.0 EA
    1.55 + */
    1.56 +public abstract class Plugin {
    1.57 +
    1.58 +    /**
    1.59 +     * Gets the option name to turn on this add-on.
    1.60 +     *
    1.61 +     * <p>
    1.62 +     * For example, if "abc" is returned, "-abc" will
    1.63 +     * turn on this plugin. A plugin needs to be turned
    1.64 +     * on explicitly, or else no other methods of {@link Plugin}
    1.65 +     * will be invoked.
    1.66 +     *
    1.67 +     * <p>
    1.68 +     * Starting 2.1, when an option matches the name returned
    1.69 +     * from this method, XJC will then invoke {@link #parseArgument(Options, String[], int)},
    1.70 +     * allowing plugins to handle arguments to this option.
    1.71 +     */
    1.72 +    public abstract String getOptionName();
    1.73 +
    1.74 +    /**
    1.75 +     * Gets the description of this add-on. Used to generate
    1.76 +     * a usage screen.
    1.77 +     *
    1.78 +     * @return
    1.79 +     *      localized description message. should be terminated by \n.
    1.80 +     */
    1.81 +    public abstract String getUsage();
    1.82 +
    1.83 +    /**
    1.84 +     * Parses an option <code>args[i]</code> and augment
    1.85 +     * the <code>opt</code> object appropriately, then return
    1.86 +     * the number of tokens consumed.
    1.87 +     *
    1.88 +     * <p>
    1.89 +     * The callee doesn't need to recognize the option that the
    1.90 +     * getOptionName method returns.
    1.91 +     *
    1.92 +     * <p>
    1.93 +     * Once a plugin is activated, this method is called
    1.94 +     * for options that XJC didn't recognize. This allows
    1.95 +     * a plugin to define additional options to customize
    1.96 +     * its behavior.
    1.97 +     *
    1.98 +     * <p>
    1.99 +     * Since options can appear in no particular order,
   1.100 +     * XJC allows sub-options of a plugin to show up before
   1.101 +     * the option that activates a plugin (one that's returned
   1.102 +     * by {@link #getOptionName().)
   1.103 +     *
   1.104 +     * But nevertheless a {@link Plugin} needs to be activated
   1.105 +     * to participate in further processing.
   1.106 +     *
   1.107 +     * @return
   1.108 +     *      0 if the argument is not understood.
   1.109 +     *      Otherwise return the number of tokens that are
   1.110 +     *      consumed, including the option itself.
   1.111 +     *      (so if you have an option like "-foo 3", return 2.)
   1.112 +     * @exception BadCommandLineException
   1.113 +     *      If the option was recognized but there's an error.
   1.114 +     *      This halts the argument parsing process and causes
   1.115 +     *      XJC to abort, reporting an error.
   1.116 +     */
   1.117 +    public int parseArgument( Options opt, String[] args, int i ) throws BadCommandLineException, IOException {
   1.118 +        return 0;
   1.119 +    }
   1.120 +
   1.121 +    /**
   1.122 +     * Returns the list of namespace URIs that are supported by this plug-in
   1.123 +     * as schema annotations.
   1.124 +     *
   1.125 +     * <p>
   1.126 +     * If a plug-in returns a non-empty list, the JAXB RI will recognize
   1.127 +     * these namespace URIs as vendor extensions
   1.128 +     * (much like "http://java.sun.com/xml/ns/jaxb/xjc"). This allows users
   1.129 +     * to write those annotations inside a schema, or in external binding files,
   1.130 +     * and later plug-ins can access those annotations as DOM nodes.
   1.131 +     *
   1.132 +     * <p>
   1.133 +     * See <a href="http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html">
   1.134 +     * http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html</a>
   1.135 +     * for the syntax that users need to use to enable extension URIs.
   1.136 +     *
   1.137 +     * @return
   1.138 +     *      can be empty, be never be null.
   1.139 +     */
   1.140 +    public List<String> getCustomizationURIs() {
   1.141 +        return Collections.emptyList();
   1.142 +    }
   1.143 +
   1.144 +    /**
   1.145 +     * Checks if the given tag name is a valid tag name for the customization element in this plug-in.
   1.146 +     *
   1.147 +     * <p>
   1.148 +     * This method is invoked by XJC to determine if the user-specified customization element
   1.149 +     * is really a customization or not. This information is used to pick the proper error message.
   1.150 +     *
   1.151 +     * <p>
   1.152 +     * A plug-in is still encouraged to do the validation of the customization element in the
   1.153 +     * {@link #run} method before using any {@link CPluginCustomization}, to make sure that it
   1.154 +     * has proper child elements and attributes.
   1.155 +     *
   1.156 +     * @param nsUri
   1.157 +     *      the namespace URI of the element. Never null.
   1.158 +     * @param localName
   1.159 +     *      the local name of the element. Never null.
   1.160 +     */
   1.161 +    public boolean isCustomizationTagName(String nsUri,String localName) {
   1.162 +        return false;
   1.163 +    }
   1.164 +
   1.165 +    /**
   1.166 +     * Notifies a plugin that it's activated.
   1.167 +     *
   1.168 +     * <p>
   1.169 +     * This method is called when a plugin is activated
   1.170 +     * through the command line option (as specified by {@link #getOptionName()}.
   1.171 +     *
   1.172 +     * <p>
   1.173 +     * This is a good opportunity to use
   1.174 +     * {@link Options#setFieldRendererFactory(FieldRendererFactory, Plugin)}
   1.175 +     * if a plugin so desires.
   1.176 +     *
   1.177 +     * <p>
   1.178 +     * Noop by default.
   1.179 +     *
   1.180 +     * @since JAXB 2.0 EA4
   1.181 +     */
   1.182 +    public void onActivated(Options opts) throws BadCommandLineException {
   1.183 +        // noop
   1.184 +    }
   1.185 +
   1.186 +    /**
   1.187 +     * Performs the post-processing of the {@link Model}.
   1.188 +     *
   1.189 +     * <p>
   1.190 +     * This method is invoked after XJC has internally finished
   1.191 +     * the model construction. This is a chance for a plugin to
   1.192 +     * affect the way code generation is performed.
   1.193 +     *
   1.194 +     * <p>
   1.195 +     * Compared to the {@link #run(Outline, Options, ErrorHandler)}
   1.196 +     * method, this method allows a plugin to work at the higher level
   1.197 +     * conceptually closer to the abstract JAXB model, as opposed to
   1.198 +     * Java syntax level.
   1.199 +     *
   1.200 +     * <p>
   1.201 +     * Note that this method is invoked only when a {@link Plugin}
   1.202 +     * is activated.
   1.203 +     *
   1.204 +     * @param model
   1.205 +     *      The object that represents the classes/properties to
   1.206 +     *      be generated.
   1.207 +     *
   1.208 +     * @param errorHandler
   1.209 +     *      Errors should be reported to this handler.
   1.210 +     *
   1.211 +     * @since JAXB 2.0.2
   1.212 +     */
   1.213 +    public void postProcessModel(Model model, ErrorHandler errorHandler) {
   1.214 +        // noop
   1.215 +    }
   1.216 +
   1.217 +    /**
   1.218 +     * Run the add-on.
   1.219 +     *
   1.220 +     * <p>
   1.221 +     * This method is invoked after XJC has internally finished
   1.222 +     * the code generation. Plugins can tweak some of the generated
   1.223 +     * code (or add more code) by using {@link Outline} and {@link Options}.
   1.224 +     *
   1.225 +     * <p>
   1.226 +     * Note that this method is invoked only when a {@link Plugin}
   1.227 +     * is activated.
   1.228 +     *
   1.229 +     * @param outline
   1.230 +     *      This object allows access to various generated code.
   1.231 +     *
   1.232 +     * @param errorHandler
   1.233 +     *      Errors should be reported to this handler.
   1.234 +     *
   1.235 +     * @return
   1.236 +     *      If the add-on executes successfully, return true.
   1.237 +     *      If it detects some errors but those are reported and
   1.238 +     *      recovered gracefully, return false.
   1.239 +     *
   1.240 +     * @throws SAXException
   1.241 +     *      After an error is reported to {@link ErrorHandler}, the
   1.242 +     *      same exception can be thrown to indicate a fatal irrecoverable
   1.243 +     *      error. {@link ErrorHandler} itself may throw it, if it chooses
   1.244 +     *      not to recover from the error.
   1.245 +     */
   1.246 +    public abstract boolean run(
   1.247 +        Outline outline, Options opt, ErrorHandler errorHandler ) throws SAXException ;
   1.248 +}

mercurial