aoqi@0: /* aoqi@0: * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.ws.wscompile; aoqi@0: aoqi@0: import com.sun.codemodel.internal.JCodeModel; aoqi@0: import com.sun.tools.internal.ws.processor.model.Model; aoqi@0: import java.io.IOException; aoqi@0: import org.xml.sax.SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Add-on that works on the generated source code. aoqi@0: * aoqi@0: *

This add-on will be called after the default generation has finished. aoqi@0: * aoqi@0: * @author Lukas Jungmann aoqi@0: * @since 2.2.6 aoqi@0: */ aoqi@0: public abstract class Plugin { aoqi@0: aoqi@0: /** aoqi@0: * Gets the option name to turn on this add-on. aoqi@0: * aoqi@0: *

For example, if "abc" is returned, "-abc" will turn on this plugin. A aoqi@0: * plugin needs to be turned on explicitly, or else no other methods of {@link Plugin} aoqi@0: * will be invoked. aoqi@0: * aoqi@0: *

When an option matches the name returned from this method, WsImport aoqi@0: * will then invoke {@link #parseArgument(Options, String[], int)}, allowing aoqi@0: * plugins to handle arguments to this option. aoqi@0: */ aoqi@0: public abstract String getOptionName(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the description of this add-on. Used to generate a usage screen. aoqi@0: * aoqi@0: * @return localized description message. should be terminated by \n. aoqi@0: */ aoqi@0: public abstract String getUsage(); aoqi@0: aoqi@0: /** aoqi@0: * Parses an option args[i] and augment the opt object aoqi@0: * appropriately, then return the number of tokens consumed. aoqi@0: * aoqi@0: *

The callee doesn't need to recognize the option that the aoqi@0: * getOptionName method returns. aoqi@0: * aoqi@0: *

Once a plugin is activated, this method is called for options that aoqi@0: * WsImport didn't recognize. This allows a plugin to define additional aoqi@0: * options to customize its behavior. aoqi@0: * aoqi@0: *

Since options can appear in no particular order, WsImport allows aoqi@0: * sub-options of a plugin to show up before the option that activates a aoqi@0: * plugin (one that's returned by {@link #getOptionName()}.) aoqi@0: * aoqi@0: * But nevertheless a {@link Plugin} needs to be activated to participate in aoqi@0: * further processing. aoqi@0: * aoqi@0: * @return 0 if the argument is not understood. Otherwise return the number aoqi@0: * of tokens that are consumed, including the option itself. (so if you have aoqi@0: * an option like "-foo 3", return 2.) aoqi@0: * @exception BadCommandLineException If the option was recognized but aoqi@0: * there's an error. This halts the argument parsing process and causes aoqi@0: * WsImport to abort, reporting an error. aoqi@0: */ aoqi@0: public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException { aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Notifies a plugin that it's activated. aoqi@0: * aoqi@0: *

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

Noop by default. aoqi@0: * aoqi@0: */ aoqi@0: public void onActivated(Options opts) throws BadCommandLineException { aoqi@0: // noop aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Run the add-on. aoqi@0: * aoqi@0: *

This method is invoked after WsImport has internally finished the aoqi@0: * code generation. Plugins can tweak some of the generated code (or add aoqi@0: * more code) by altering {@link JCodeModel} obtained from {@link WsimportOptions#getCodeModel() aoqi@0: * } according to the current aoqi@0: * {@link Model WSDL model} and {@link WsimportOptions}. aoqi@0: * aoqi@0: *

Note that this method is invoked only when a {@link Plugin} is aoqi@0: * activated. aoqi@0: * aoqi@0: * @param wsdlModel This object allows access to the WSDL model used for aoqi@0: * code generation. aoqi@0: * aoqi@0: * @param options This object allows access to various options used for code aoqi@0: * generation as well as access to the generated code. aoqi@0: * aoqi@0: * @param errorReceiver Errors should be reported to this handler. aoqi@0: * aoqi@0: * @return If the add-on executes successfully, return true. If it detects aoqi@0: * some errors but those are reported and recovered gracefully, return aoqi@0: * false. aoqi@0: * aoqi@0: * @throws SAXException After an error is reported to {@link ErrorReceiver}, aoqi@0: * the same exception can be thrown to indicate a fatal irrecoverable error. {@link ErrorReceiver} aoqi@0: * itself may throw it, if it chooses not to recover from the error. aoqi@0: */ aoqi@0: public abstract boolean run( aoqi@0: Model wsdlModel, WsimportOptions options, ErrorReceiver errorReceiver) throws SAXException; aoqi@0: }