Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.internal.xjc; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.IOException; |
aoqi@0 | 29 | import java.util.Collections; |
aoqi@0 | 30 | import java.util.List; |
aoqi@0 | 31 | |
aoqi@0 | 32 | import com.sun.tools.internal.xjc.generator.bean.field.FieldRendererFactory; |
aoqi@0 | 33 | import com.sun.tools.internal.xjc.model.CPluginCustomization; |
aoqi@0 | 34 | import com.sun.tools.internal.xjc.model.Model; |
aoqi@0 | 35 | import com.sun.tools.internal.xjc.outline.Outline; |
aoqi@0 | 36 | |
aoqi@0 | 37 | import org.xml.sax.ErrorHandler; |
aoqi@0 | 38 | import org.xml.sax.SAXException; |
aoqi@0 | 39 | |
aoqi@0 | 40 | /** |
aoqi@0 | 41 | * Add-on that works on the generated source code. |
aoqi@0 | 42 | * |
aoqi@0 | 43 | * <p> |
aoqi@0 | 44 | * This add-on will be called after the default bean generation |
aoqi@0 | 45 | * has finished. |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * @author |
aoqi@0 | 48 | * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
aoqi@0 | 49 | * |
aoqi@0 | 50 | * @since |
aoqi@0 | 51 | * JAXB RI 2.0 EA |
aoqi@0 | 52 | */ |
aoqi@0 | 53 | public abstract class Plugin { |
aoqi@0 | 54 | |
aoqi@0 | 55 | /** |
aoqi@0 | 56 | * Gets the option name to turn on this add-on. |
aoqi@0 | 57 | * |
aoqi@0 | 58 | * <p> |
aoqi@0 | 59 | * For example, if "abc" is returned, "-abc" will |
aoqi@0 | 60 | * turn on this plugin. A plugin needs to be turned |
aoqi@0 | 61 | * on explicitly, or else no other methods of {@link Plugin} |
aoqi@0 | 62 | * will be invoked. |
aoqi@0 | 63 | * |
aoqi@0 | 64 | * <p> |
aoqi@0 | 65 | * Starting 2.1, when an option matches the name returned |
aoqi@0 | 66 | * from this method, XJC will then invoke {@link #parseArgument(Options, String[], int)}, |
aoqi@0 | 67 | * allowing plugins to handle arguments to this option. |
aoqi@0 | 68 | */ |
aoqi@0 | 69 | public abstract String getOptionName(); |
aoqi@0 | 70 | |
aoqi@0 | 71 | /** |
aoqi@0 | 72 | * Gets the description of this add-on. Used to generate |
aoqi@0 | 73 | * a usage screen. |
aoqi@0 | 74 | * |
aoqi@0 | 75 | * @return |
aoqi@0 | 76 | * localized description message. should be terminated by \n. |
aoqi@0 | 77 | */ |
aoqi@0 | 78 | public abstract String getUsage(); |
aoqi@0 | 79 | |
aoqi@0 | 80 | /** |
aoqi@0 | 81 | * Parses an option <code>args[i]</code> and augment |
aoqi@0 | 82 | * the <code>opt</code> object appropriately, then return |
aoqi@0 | 83 | * the number of tokens consumed. |
aoqi@0 | 84 | * |
aoqi@0 | 85 | * <p> |
aoqi@0 | 86 | * The callee doesn't need to recognize the option that the |
aoqi@0 | 87 | * getOptionName method returns. |
aoqi@0 | 88 | * |
aoqi@0 | 89 | * <p> |
aoqi@0 | 90 | * Once a plugin is activated, this method is called |
aoqi@0 | 91 | * for options that XJC didn't recognize. This allows |
aoqi@0 | 92 | * a plugin to define additional options to customize |
aoqi@0 | 93 | * its behavior. |
aoqi@0 | 94 | * |
aoqi@0 | 95 | * <p> |
aoqi@0 | 96 | * Since options can appear in no particular order, |
aoqi@0 | 97 | * XJC allows sub-options of a plugin to show up before |
aoqi@0 | 98 | * the option that activates a plugin (one that's returned |
aoqi@0 | 99 | * by {@link #getOptionName().) |
aoqi@0 | 100 | * |
aoqi@0 | 101 | * But nevertheless a {@link Plugin} needs to be activated |
aoqi@0 | 102 | * to participate in further processing. |
aoqi@0 | 103 | * |
aoqi@0 | 104 | * @return |
aoqi@0 | 105 | * 0 if the argument is not understood. |
aoqi@0 | 106 | * Otherwise return the number of tokens that are |
aoqi@0 | 107 | * consumed, including the option itself. |
aoqi@0 | 108 | * (so if you have an option like "-foo 3", return 2.) |
aoqi@0 | 109 | * @exception BadCommandLineException |
aoqi@0 | 110 | * If the option was recognized but there's an error. |
aoqi@0 | 111 | * This halts the argument parsing process and causes |
aoqi@0 | 112 | * XJC to abort, reporting an error. |
aoqi@0 | 113 | */ |
aoqi@0 | 114 | public int parseArgument( Options opt, String[] args, int i ) throws BadCommandLineException, IOException { |
aoqi@0 | 115 | return 0; |
aoqi@0 | 116 | } |
aoqi@0 | 117 | |
aoqi@0 | 118 | /** |
aoqi@0 | 119 | * Returns the list of namespace URIs that are supported by this plug-in |
aoqi@0 | 120 | * as schema annotations. |
aoqi@0 | 121 | * |
aoqi@0 | 122 | * <p> |
aoqi@0 | 123 | * If a plug-in returns a non-empty list, the JAXB RI will recognize |
aoqi@0 | 124 | * these namespace URIs as vendor extensions |
aoqi@0 | 125 | * (much like "http://java.sun.com/xml/ns/jaxb/xjc"). This allows users |
aoqi@0 | 126 | * to write those annotations inside a schema, or in external binding files, |
aoqi@0 | 127 | * and later plug-ins can access those annotations as DOM nodes. |
aoqi@0 | 128 | * |
aoqi@0 | 129 | * <p> |
aoqi@0 | 130 | * See <a href="http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html"> |
aoqi@0 | 131 | * http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html</a> |
aoqi@0 | 132 | * for the syntax that users need to use to enable extension URIs. |
aoqi@0 | 133 | * |
aoqi@0 | 134 | * @return |
aoqi@0 | 135 | * can be empty, be never be null. |
aoqi@0 | 136 | */ |
aoqi@0 | 137 | public List<String> getCustomizationURIs() { |
aoqi@0 | 138 | return Collections.emptyList(); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * Checks if the given tag name is a valid tag name for the customization element in this plug-in. |
aoqi@0 | 143 | * |
aoqi@0 | 144 | * <p> |
aoqi@0 | 145 | * This method is invoked by XJC to determine if the user-specified customization element |
aoqi@0 | 146 | * is really a customization or not. This information is used to pick the proper error message. |
aoqi@0 | 147 | * |
aoqi@0 | 148 | * <p> |
aoqi@0 | 149 | * A plug-in is still encouraged to do the validation of the customization element in the |
aoqi@0 | 150 | * {@link #run} method before using any {@link CPluginCustomization}, to make sure that it |
aoqi@0 | 151 | * has proper child elements and attributes. |
aoqi@0 | 152 | * |
aoqi@0 | 153 | * @param nsUri |
aoqi@0 | 154 | * the namespace URI of the element. Never null. |
aoqi@0 | 155 | * @param localName |
aoqi@0 | 156 | * the local name of the element. Never null. |
aoqi@0 | 157 | */ |
aoqi@0 | 158 | public boolean isCustomizationTagName(String nsUri,String localName) { |
aoqi@0 | 159 | return false; |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | /** |
aoqi@0 | 163 | * Notifies a plugin that it's activated. |
aoqi@0 | 164 | * |
aoqi@0 | 165 | * <p> |
aoqi@0 | 166 | * This method is called when a plugin is activated |
aoqi@0 | 167 | * through the command line option (as specified by {@link #getOptionName()}. |
aoqi@0 | 168 | * |
aoqi@0 | 169 | * <p> |
aoqi@0 | 170 | * This is a good opportunity to use |
aoqi@0 | 171 | * {@link Options#setFieldRendererFactory(FieldRendererFactory, Plugin)} |
aoqi@0 | 172 | * if a plugin so desires. |
aoqi@0 | 173 | * |
aoqi@0 | 174 | * <p> |
aoqi@0 | 175 | * Noop by default. |
aoqi@0 | 176 | * |
aoqi@0 | 177 | * @since JAXB 2.0 EA4 |
aoqi@0 | 178 | */ |
aoqi@0 | 179 | public void onActivated(Options opts) throws BadCommandLineException { |
aoqi@0 | 180 | // noop |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | /** |
aoqi@0 | 184 | * Performs the post-processing of the {@link Model}. |
aoqi@0 | 185 | * |
aoqi@0 | 186 | * <p> |
aoqi@0 | 187 | * This method is invoked after XJC has internally finished |
aoqi@0 | 188 | * the model construction. This is a chance for a plugin to |
aoqi@0 | 189 | * affect the way code generation is performed. |
aoqi@0 | 190 | * |
aoqi@0 | 191 | * <p> |
aoqi@0 | 192 | * Compared to the {@link #run(Outline, Options, ErrorHandler)} |
aoqi@0 | 193 | * method, this method allows a plugin to work at the higher level |
aoqi@0 | 194 | * conceptually closer to the abstract JAXB model, as opposed to |
aoqi@0 | 195 | * Java syntax level. |
aoqi@0 | 196 | * |
aoqi@0 | 197 | * <p> |
aoqi@0 | 198 | * Note that this method is invoked only when a {@link Plugin} |
aoqi@0 | 199 | * is activated. |
aoqi@0 | 200 | * |
aoqi@0 | 201 | * @param model |
aoqi@0 | 202 | * The object that represents the classes/properties to |
aoqi@0 | 203 | * be generated. |
aoqi@0 | 204 | * |
aoqi@0 | 205 | * @param errorHandler |
aoqi@0 | 206 | * Errors should be reported to this handler. |
aoqi@0 | 207 | * |
aoqi@0 | 208 | * @since JAXB 2.0.2 |
aoqi@0 | 209 | */ |
aoqi@0 | 210 | public void postProcessModel(Model model, ErrorHandler errorHandler) { |
aoqi@0 | 211 | // noop |
aoqi@0 | 212 | } |
aoqi@0 | 213 | |
aoqi@0 | 214 | /** |
aoqi@0 | 215 | * Run the add-on. |
aoqi@0 | 216 | * |
aoqi@0 | 217 | * <p> |
aoqi@0 | 218 | * This method is invoked after XJC has internally finished |
aoqi@0 | 219 | * the code generation. Plugins can tweak some of the generated |
aoqi@0 | 220 | * code (or add more code) by using {@link Outline} and {@link Options}. |
aoqi@0 | 221 | * |
aoqi@0 | 222 | * <p> |
aoqi@0 | 223 | * Note that this method is invoked only when a {@link Plugin} |
aoqi@0 | 224 | * is activated. |
aoqi@0 | 225 | * |
aoqi@0 | 226 | * @param outline |
aoqi@0 | 227 | * This object allows access to various generated code. |
aoqi@0 | 228 | * |
aoqi@0 | 229 | * @param errorHandler |
aoqi@0 | 230 | * Errors should be reported to this handler. |
aoqi@0 | 231 | * |
aoqi@0 | 232 | * @return |
aoqi@0 | 233 | * If the add-on executes successfully, return true. |
aoqi@0 | 234 | * If it detects some errors but those are reported and |
aoqi@0 | 235 | * recovered gracefully, return false. |
aoqi@0 | 236 | * |
aoqi@0 | 237 | * @throws SAXException |
aoqi@0 | 238 | * After an error is reported to {@link ErrorHandler}, the |
aoqi@0 | 239 | * same exception can be thrown to indicate a fatal irrecoverable |
aoqi@0 | 240 | * error. {@link ErrorHandler} itself may throw it, if it chooses |
aoqi@0 | 241 | * not to recover from the error. |
aoqi@0 | 242 | */ |
aoqi@0 | 243 | public abstract boolean run( |
aoqi@0 | 244 | Outline outline, Options opt, ErrorHandler errorHandler ) throws SAXException ; |
aoqi@0 | 245 | } |