1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/Plugin.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,135 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, 2012, 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.ws.wscompile; 1.30 + 1.31 +import com.sun.codemodel.internal.JCodeModel; 1.32 +import com.sun.tools.internal.ws.processor.model.Model; 1.33 +import java.io.IOException; 1.34 +import org.xml.sax.SAXException; 1.35 + 1.36 +/** 1.37 + * Add-on that works on the generated source code. 1.38 + * 1.39 + * <p> This add-on will be called after the default generation has finished. 1.40 + * 1.41 + * @author Lukas Jungmann 1.42 + * @since 2.2.6 1.43 + */ 1.44 +public abstract class Plugin { 1.45 + 1.46 + /** 1.47 + * Gets the option name to turn on this add-on. 1.48 + * 1.49 + * <p> For example, if "abc" is returned, "-abc" will turn on this plugin. A 1.50 + * plugin needs to be turned on explicitly, or else no other methods of {@link Plugin} 1.51 + * will be invoked. 1.52 + * 1.53 + * <p> When an option matches the name returned from this method, WsImport 1.54 + * will then invoke {@link #parseArgument(Options, String[], int)}, allowing 1.55 + * plugins to handle arguments to this option. 1.56 + */ 1.57 + public abstract String getOptionName(); 1.58 + 1.59 + /** 1.60 + * Gets the description of this add-on. Used to generate a usage screen. 1.61 + * 1.62 + * @return localized description message. should be terminated by \n. 1.63 + */ 1.64 + public abstract String getUsage(); 1.65 + 1.66 + /** 1.67 + * Parses an option <code>args[i]</code> and augment the <code>opt</code> object 1.68 + * appropriately, then return the number of tokens consumed. 1.69 + * 1.70 + * <p> The callee doesn't need to recognize the option that the 1.71 + * getOptionName method returns. 1.72 + * 1.73 + * <p> Once a plugin is activated, this method is called for options that 1.74 + * WsImport didn't recognize. This allows a plugin to define additional 1.75 + * options to customize its behavior. 1.76 + * 1.77 + * <p> Since options can appear in no particular order, WsImport allows 1.78 + * sub-options of a plugin to show up before the option that activates a 1.79 + * plugin (one that's returned by {@link #getOptionName()}.) 1.80 + * 1.81 + * But nevertheless a {@link Plugin} needs to be activated to participate in 1.82 + * further processing. 1.83 + * 1.84 + * @return 0 if the argument is not understood. Otherwise return the number 1.85 + * of tokens that are consumed, including the option itself. (so if you have 1.86 + * an option like "-foo 3", return 2.) 1.87 + * @exception BadCommandLineException If the option was recognized but 1.88 + * there's an error. This halts the argument parsing process and causes 1.89 + * WsImport to abort, reporting an error. 1.90 + */ 1.91 + public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException { 1.92 + return 0; 1.93 + } 1.94 + 1.95 + /** 1.96 + * Notifies a plugin that it's activated. 1.97 + * 1.98 + * <p> This method is called when a plugin is activated through the command 1.99 + * line option (as specified by {@link #getOptionName()}. 1.100 + * 1.101 + * <p> Noop by default. 1.102 + * 1.103 + */ 1.104 + public void onActivated(Options opts) throws BadCommandLineException { 1.105 + // noop 1.106 + } 1.107 + 1.108 + /** 1.109 + * Run the add-on. 1.110 + * 1.111 + * <p> This method is invoked after WsImport has internally finished the 1.112 + * code generation. Plugins can tweak some of the generated code (or add 1.113 + * more code) by altering {@link JCodeModel} obtained from {@link WsimportOptions#getCodeModel() 1.114 + * } according to the current 1.115 + * {@link Model WSDL model} and {@link WsimportOptions}. 1.116 + * 1.117 + * <p> Note that this method is invoked only when a {@link Plugin} is 1.118 + * activated. 1.119 + * 1.120 + * @param wsdlModel This object allows access to the WSDL model used for 1.121 + * code generation. 1.122 + * 1.123 + * @param options This object allows access to various options used for code 1.124 + * generation as well as access to the generated code. 1.125 + * 1.126 + * @param errorReceiver Errors should be reported to this handler. 1.127 + * 1.128 + * @return If the add-on executes successfully, return true. If it detects 1.129 + * some errors but those are reported and recovered gracefully, return 1.130 + * false. 1.131 + * 1.132 + * @throws SAXException After an error is reported to {@link ErrorReceiver}, 1.133 + * the same exception can be thrown to indicate a fatal irrecoverable error. {@link ErrorReceiver} 1.134 + * itself may throw it, if it chooses not to recover from the error. 1.135 + */ 1.136 + public abstract boolean run( 1.137 + Model wsdlModel, WsimportOptions options, ErrorReceiver errorReceiver) throws SAXException; 1.138 +}