aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, 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.generator.GeneratorExtension; aoqi@0: import com.sun.tools.internal.ws.resources.ConfigurationMessages; aoqi@0: import com.sun.tools.internal.ws.resources.WscompileMessages; aoqi@0: import com.sun.tools.internal.ws.util.ForkEntityResolver; aoqi@0: import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants; aoqi@0: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants; aoqi@0: import com.sun.tools.internal.xjc.api.SchemaCompiler; aoqi@0: import com.sun.tools.internal.xjc.api.SpecVersion; aoqi@0: import com.sun.tools.internal.xjc.api.XJC; aoqi@0: import com.sun.tools.internal.xjc.reader.Util; aoqi@0: import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory; aoqi@0: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; aoqi@0: import com.sun.xml.internal.ws.util.ServiceFinder; aoqi@0: import com.sun.xml.internal.ws.util.JAXWSUtils; aoqi@0: import com.sun.xml.internal.ws.util.xml.XmlUtil; aoqi@0: import org.w3c.dom.Element; aoqi@0: import org.xml.sax.EntityResolver; aoqi@0: import org.xml.sax.InputSource; aoqi@0: import org.xml.sax.helpers.LocatorImpl; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.stream.XMLStreamReader; aoqi@0: aoqi@0: import java.io.ByteArrayInputStream; aoqi@0: import java.io.ByteArrayOutputStream; aoqi@0: import java.io.File; aoqi@0: import java.io.IOException; aoqi@0: import java.io.InputStream; aoqi@0: import java.io.Reader; aoqi@0: import java.lang.reflect.Array; aoqi@0: import java.net.MalformedURLException; aoqi@0: import java.net.URL; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Arrays; aoqi@0: import java.util.List; aoqi@0: import java.util.HashMap; aoqi@0: import java.util.logging.Level; aoqi@0: import java.util.logging.Logger; aoqi@0: aoqi@0: /** aoqi@0: * @author Vivek Pandey aoqi@0: */ aoqi@0: public class WsimportOptions extends Options { aoqi@0: /** aoqi@0: * -wsdlLocation aoqi@0: */ aoqi@0: public String wsdlLocation; aoqi@0: aoqi@0: /** aoqi@0: * Actually stores {@link com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver}, but the field aoqi@0: * type is made to {@link org.xml.sax.EntityResolver} so that XJC can be aoqi@0: * used even if resolver.jar is not available in the classpath. aoqi@0: */ aoqi@0: public EntityResolver entityResolver = null; aoqi@0: aoqi@0: /** aoqi@0: * The -p option that should control the default Java package that aoqi@0: * will contain the generated code. Null if unspecified. aoqi@0: */ aoqi@0: public String defaultPackage = null; aoqi@0: aoqi@0: /** aoqi@0: * The -clientjar option to package client artifacts as jar aoqi@0: */ aoqi@0: public String clientjar = null; aoqi@0: aoqi@0: /** aoqi@0: * -XadditionalHeaders aoqi@0: */ aoqi@0: public boolean additionalHeaders; aoqi@0: aoqi@0: /** aoqi@0: * The option indicates the dir where the jwsImpl will be generated. aoqi@0: */ aoqi@0: public File implDestDir = null; aoqi@0: aoqi@0: /** aoqi@0: * optional, generated impl file only for the ordered serviceName aoqi@0: * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part aoqi@0: */ aoqi@0: public String implServiceName = null; aoqi@0: aoqi@0: /** aoqi@0: * optional, generated impl file only for the ordered portName aoqi@0: * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part aoqi@0: */ aoqi@0: public String implPortName = null; aoqi@0: aoqi@0: /** aoqi@0: * optional, if true JWS file is generated aoqi@0: */ aoqi@0: public boolean isGenerateJWS = false; aoqi@0: aoqi@0: /** aoqi@0: * Setting disableSSLHostVerification to true disables the SSL Hostname verification while fetching the wsdls. aoqi@0: * -XdisableSSLHostVerification aoqi@0: */ aoqi@0: public boolean disableSSLHostnameVerification; aoqi@0: aoqi@0: /** aoqi@0: * Setting useBaseResourceAndURLToLoadWSDL to true causes generated Service classes to load the WSDL file from aoqi@0: * a URL generated from the base resource. aoqi@0: * -XuseBaseResourceAndURLToLoadWSDL aoqi@0: */ aoqi@0: public boolean useBaseResourceAndURLToLoadWSDL = false; aoqi@0: aoqi@0: /** aoqi@0: * JAXB's {@link SchemaCompiler} to be used for handling the schema portion. aoqi@0: * This object is also configured through options. aoqi@0: */ aoqi@0: private SchemaCompiler schemaCompiler = XJC.createSchemaCompiler(); aoqi@0: aoqi@0: /** aoqi@0: * Authentication file aoqi@0: */ aoqi@0: public File authFile = null; aoqi@0: aoqi@0: //can user.home value be null? aoqi@0: public static final String defaultAuthfile aoqi@0: = System.getProperty("user.home") + System.getProperty("file.separator") aoqi@0: + ".metro" + System.getProperty("file.separator") + "auth"; aoqi@0: aoqi@0: /** aoqi@0: * Setting disableAuthenticator to true disables the DefaultAuthenticator. aoqi@0: * -XdisableAuthenticator aoqi@0: */ aoqi@0: public boolean disableAuthenticator; aoqi@0: aoqi@0: public String proxyAuth = null; aoqi@0: private String proxyHost = null; aoqi@0: private String proxyPort = null; aoqi@0: aoqi@0: /** aoqi@0: * Additional arguments aoqi@0: */ aoqi@0: public HashMap extensionOptions = new HashMap(); aoqi@0: aoqi@0: /** aoqi@0: * All discovered {@link Plugin}s. aoqi@0: * This is lazily parsed, so that we can take '-cp' option into account. aoqi@0: * aoqi@0: * @see #getAllPlugins() aoqi@0: */ aoqi@0: private List allPlugins; aoqi@0: aoqi@0: /** aoqi@0: * {@link Plugin}s that are enabled in this compilation. aoqi@0: */ aoqi@0: public final List activePlugins = new ArrayList(); aoqi@0: aoqi@0: public JCodeModel getCodeModel() { aoqi@0: if(codeModel == null) aoqi@0: codeModel = new JCodeModel(); aoqi@0: return codeModel; aoqi@0: } aoqi@0: aoqi@0: public SchemaCompiler getSchemaCompiler() { aoqi@0: schemaCompiler.setTargetVersion(SpecVersion.parse(target.getVersion())); aoqi@0: if(entityResolver != null) { aoqi@0: //set if its not null so as not to override catalog option specified via xjc args aoqi@0: schemaCompiler.setEntityResolver(entityResolver); aoqi@0: } aoqi@0: return schemaCompiler; aoqi@0: } aoqi@0: aoqi@0: public void setCodeModel(JCodeModel codeModel) { aoqi@0: this.codeModel = codeModel; aoqi@0: } aoqi@0: aoqi@0: private JCodeModel codeModel; aoqi@0: aoqi@0: /** aoqi@0: * This captures jars passed on the commandline and passes them to XJC and puts them in the classpath for compilation aoqi@0: */ aoqi@0: public List cmdlineJars = new ArrayList(); aoqi@0: aoqi@0: /** aoqi@0: * Gets all the {@link Plugin}s discovered so far. aoqi@0: * aoqi@0: *

aoqi@0: * A plugins are enumerated when this method is called for the first time, aoqi@0: * by taking {@link #classpath} into account. That means aoqi@0: * "-cp plugin.jar" has to come before you specify options to enable it. aoqi@0: */ aoqi@0: public List getAllPlugins() { aoqi@0: if(allPlugins==null) { aoqi@0: allPlugins = new ArrayList(); aoqi@0: allPlugins.addAll(Arrays.asList(findServices(Plugin.class, getClassLoader()))); aoqi@0: } aoqi@0: return allPlugins; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Parses arguments and fill fields of this object. aoqi@0: * aoqi@0: * @exception BadCommandLineException aoqi@0: * thrown when there's a problem in the command-line arguments aoqi@0: */ aoqi@0: @Override aoqi@0: public final void parseArguments( String[] args ) throws BadCommandLineException { aoqi@0: aoqi@0: for (int i = 0; i < args.length; i++) { aoqi@0: if(args[i].length()==0) aoqi@0: throw new BadCommandLineException(); aoqi@0: if (args[i].charAt(0) == '-') { aoqi@0: int j = parseArguments(args,i); aoqi@0: if(j==0) aoqi@0: throw new BadCommandLineException(WscompileMessages.WSCOMPILE_INVALID_OPTION(args[i])); aoqi@0: i += (j-1); aoqi@0: } else { aoqi@0: if(args[i].endsWith(".jar")) { aoqi@0: aoqi@0: try { aoqi@0: cmdlineJars.add(args[i]); aoqi@0: schemaCompiler.getOptions().scanEpisodeFile(new File(args[i])); aoqi@0: aoqi@0: } catch (com.sun.tools.internal.xjc.BadCommandLineException e) { aoqi@0: //Driver.usage(jaxbOptions,false); aoqi@0: throw new BadCommandLineException(e.getMessage(), e); aoqi@0: } aoqi@0: } else{ aoqi@0: addFile(args[i]); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (encoding != null && schemaCompiler.getOptions().encoding == null) { aoqi@0: try { aoqi@0: schemaCompiler.getOptions().parseArgument( aoqi@0: new String[] {"-encoding", encoding}, 0); aoqi@0: } catch (com.sun.tools.internal.xjc.BadCommandLineException ex) { aoqi@0: Logger.getLogger(WsimportOptions.class.getName()).log(Level.SEVERE, null, ex); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if(destDir == null) aoqi@0: destDir = new File("."); aoqi@0: if(sourceDir == null) aoqi@0: sourceDir = destDir; aoqi@0: } aoqi@0: aoqi@0: /** -Xno-addressing-databinding option to disable addressing namespace data binding. This is aoqi@0: * experimental switch and will be working as a temporary workaround till aoqi@0: * jaxb can provide a better way to selelctively disable compiling of an aoqi@0: * schema component. aoqi@0: * **/ aoqi@0: public boolean noAddressingBbinding; aoqi@0: aoqi@0: @Override aoqi@0: public int parseArguments(String[] args, int i) throws BadCommandLineException { aoqi@0: int j = super.parseArguments(args ,i); aoqi@0: if(j>0) return j; // understood by the super class aoqi@0: aoqi@0: if (args[i].equals("-b")) { aoqi@0: addBindings(requireArgument("-b", args, ++i)); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-wsdllocation")) { aoqi@0: wsdlLocation = requireArgument("-wsdllocation", args, ++i); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-XadditionalHeaders")) { aoqi@0: additionalHeaders = true; aoqi@0: return 1; aoqi@0: } else if (args[i].equals("-XdisableSSLHostnameVerification")) { aoqi@0: disableSSLHostnameVerification = true; aoqi@0: return 1; aoqi@0: } else if (args[i].equals("-p")) { aoqi@0: defaultPackage = requireArgument("-p", args, ++i); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-catalog")) { aoqi@0: String catalog = requireArgument("-catalog", args, ++i); aoqi@0: try { aoqi@0: if (entityResolver == null) { aoqi@0: if (catalog != null && catalog.length() > 0) aoqi@0: entityResolver = XmlUtil.createEntityResolver(JAXWSUtils.getFileOrURL(JAXWSUtils.absolutize(Util.escapeSpace(catalog)))); aoqi@0: } else if (catalog != null && catalog.length() > 0) { aoqi@0: EntityResolver er = XmlUtil.createEntityResolver(JAXWSUtils.getFileOrURL(JAXWSUtils.absolutize(Util.escapeSpace(catalog)))); aoqi@0: entityResolver = new ForkEntityResolver(er, entityResolver); aoqi@0: } aoqi@0: } catch (IOException e) { aoqi@0: throw new BadCommandLineException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(catalog, e.getMessage())); aoqi@0: } aoqi@0: return 2; aoqi@0: } else if (args[i].startsWith("-httpproxy:")) { aoqi@0: String value = args[i].substring(11); aoqi@0: if (value.length() == 0) { aoqi@0: throw new BadCommandLineException(WscompileMessages.WSCOMPILE_INVALID_OPTION(args[i])); aoqi@0: } aoqi@0: parseProxy(value); aoqi@0: if (proxyHost != null || proxyPort != null) { aoqi@0: System.setProperty("proxySet", "true"); aoqi@0: } aoqi@0: if (proxyHost != null) { aoqi@0: System.setProperty("proxyHost", proxyHost); aoqi@0: } aoqi@0: if (proxyPort != null) { aoqi@0: System.setProperty("proxyPort", proxyPort); aoqi@0: } aoqi@0: return 1; aoqi@0: } else if (args[i].equals("-Xno-addressing-databinding")) { aoqi@0: noAddressingBbinding = true; aoqi@0: return 1; aoqi@0: } else if (args[i].startsWith("-B")) { aoqi@0: // JAXB option pass through. aoqi@0: String[] subCmd = new String[args.length-i]; aoqi@0: System.arraycopy(args,i,subCmd,0,subCmd.length); aoqi@0: subCmd[0] = subCmd[0].substring(2); // trim off the first "-B" aoqi@0: aoqi@0: com.sun.tools.internal.xjc.Options jaxbOptions = schemaCompiler.getOptions(); aoqi@0: try { aoqi@0: int r = jaxbOptions.parseArgument(subCmd, 0); aoqi@0: if(r==0) { aoqi@0: //Driver.usage(jaxbOptions,false); aoqi@0: throw new BadCommandLineException(WscompileMessages.WSIMPORT_NO_SUCH_JAXB_OPTION(subCmd[0])); aoqi@0: } aoqi@0: return r; aoqi@0: } catch (com.sun.tools.internal.xjc.BadCommandLineException e) { aoqi@0: //Driver.usage(jaxbOptions,false); aoqi@0: throw new BadCommandLineException(e.getMessage(),e); aoqi@0: } aoqi@0: } else if (args[i].equals("-Xauthfile")) { aoqi@0: String authfile = requireArgument("-Xauthfile", args, ++i); aoqi@0: authFile = new File(authfile); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-clientjar")) { aoqi@0: clientjar = requireArgument("-clientjar", args, ++i); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-implDestDir")) { aoqi@0: implDestDir = new File(requireArgument("-implDestDir", args, ++i)); aoqi@0: if (!implDestDir.exists()) aoqi@0: throw new BadCommandLineException(WscompileMessages.WSCOMPILE_NO_SUCH_DIRECTORY(implDestDir.getPath())); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-implServiceName")) { aoqi@0: implServiceName = requireArgument("-implServiceName", args, ++i); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-implPortName")) { aoqi@0: implPortName = requireArgument("-implPortName", args, ++i); aoqi@0: return 2; aoqi@0: } else if (args[i].equals("-generateJWS")) { aoqi@0: isGenerateJWS = true; aoqi@0: return 1; aoqi@0: } else if (args[i].equals("-XuseBaseResourceAndURLToLoadWSDL")) { aoqi@0: useBaseResourceAndURLToLoadWSDL = true; aoqi@0: return 1; aoqi@0: } else if (args[i].equals("-XdisableAuthenticator")) { aoqi@0: disableAuthenticator = true; aoqi@0: return 1; aoqi@0: } aoqi@0: aoqi@0: // handle additional options aoqi@0: for (GeneratorExtension f:ServiceFinder.find(GeneratorExtension.class)) { aoqi@0: if (f.validateOption(args[i])) { aoqi@0: extensionOptions.put(args[i], requireArgument(args[i], args, ++i)); aoqi@0: return 2; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // see if this is one of the extensions aoqi@0: for( Plugin plugin : getAllPlugins() ) { aoqi@0: try { aoqi@0: if(('-' + plugin.getOptionName()).equals(args[i])) { aoqi@0: activePlugins.add(plugin); aoqi@0: plugin.onActivated(this); aoqi@0: return 1; aoqi@0: } aoqi@0: int r = plugin.parseArgument(this, args, i); aoqi@0: if (r != 0) { aoqi@0: return r; aoqi@0: } aoqi@0: } catch (IOException e) { aoqi@0: throw new BadCommandLineException(e.getMessage(),e); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return 0; // what's this option? aoqi@0: } aoqi@0: aoqi@0: public void validate() throws BadCommandLineException { aoqi@0: if (wsdls.isEmpty()) { aoqi@0: throw new BadCommandLineException(WscompileMessages.WSIMPORT_MISSING_FILE()); aoqi@0: } aoqi@0: aoqi@0: if(wsdlLocation !=null && clientjar != null) { aoqi@0: throw new BadCommandLineException(WscompileMessages.WSIMPORT_WSDLLOCATION_CLIENTJAR()); aoqi@0: } aoqi@0: if(wsdlLocation == null){ aoqi@0: wsdlLocation = wsdls.get(0).getSystemId(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: protected void addFile(String arg) throws BadCommandLineException { aoqi@0: addFile(arg, wsdls, ".wsdl"); aoqi@0: } aoqi@0: aoqi@0: private final List wsdls = new ArrayList(); aoqi@0: private final List schemas = new ArrayList(); aoqi@0: private final List bindingFiles = new ArrayList(); aoqi@0: private final List jaxwsCustomBindings = new ArrayList(); aoqi@0: private final List jaxbCustomBindings = new ArrayList(); aoqi@0: private final List handlerConfigs = new ArrayList(); aoqi@0: aoqi@0: /** aoqi@0: * There is supposed to be one handler chain per generated SEI. aoqi@0: * TODO: There is possible bug, how to associate a @HandlerChain aoqi@0: * with each port on the generated SEI. For now lets preserve the JAXWS 2.0 FCS aoqi@0: * behaviour and generate only one @HandlerChain on the SEI aoqi@0: */ aoqi@0: public Element getHandlerChainConfiguration(){ aoqi@0: if(handlerConfigs.size() > 0) aoqi@0: return handlerConfigs.get(0); aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public void addHandlerChainConfiguration(Element config){ aoqi@0: handlerConfigs.add(config); aoqi@0: } aoqi@0: aoqi@0: public InputSource[] getWSDLs() { aoqi@0: return wsdls.toArray(new InputSource[wsdls.size()]); aoqi@0: } aoqi@0: aoqi@0: public InputSource[] getSchemas() { aoqi@0: return schemas.toArray(new InputSource[schemas.size()]); aoqi@0: } aoqi@0: aoqi@0: public InputSource[] getWSDLBindings() { aoqi@0: return jaxwsCustomBindings.toArray(new InputSource[jaxwsCustomBindings.size()]); aoqi@0: } aoqi@0: aoqi@0: public InputSource[] getSchemaBindings() { aoqi@0: return jaxbCustomBindings.toArray(new InputSource[jaxbCustomBindings.size()]); aoqi@0: } aoqi@0: aoqi@0: public void addWSDL(File source) { aoqi@0: addWSDL(fileToInputSource(source)); aoqi@0: } aoqi@0: aoqi@0: public void addWSDL(InputSource is) { aoqi@0: wsdls.add(absolutize(is)); aoqi@0: } aoqi@0: aoqi@0: public void addSchema(File source) { aoqi@0: addSchema(fileToInputSource(source)); aoqi@0: } aoqi@0: aoqi@0: public void addSchema(InputSource is) { aoqi@0: schemas.add(is); aoqi@0: } aoqi@0: aoqi@0: private InputSource fileToInputSource(File source) { aoqi@0: try { aoqi@0: String url = source.toURL().toExternalForm(); aoqi@0: return new InputSource(Util.escapeSpace(url)); aoqi@0: } catch (MalformedURLException e) { aoqi@0: return new InputSource(source.getPath()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Recursively scan directories and add all XSD files in it. aoqi@0: */ aoqi@0: public void addGrammarRecursive(File dir) { aoqi@0: addRecursive(dir, ".wsdl", wsdls); aoqi@0: addRecursive(dir, ".xsd", schemas); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Adds a new input schema. aoqi@0: */ aoqi@0: public void addWSDLBindFile(InputSource is) { aoqi@0: jaxwsCustomBindings.add(new RereadInputSource(absolutize(is))); aoqi@0: } aoqi@0: aoqi@0: public void addSchemmaBindFile(InputSource is) { aoqi@0: jaxbCustomBindings.add(new RereadInputSource(absolutize(is))); aoqi@0: } aoqi@0: aoqi@0: private void addRecursive(File dir, String suffix, List result) { aoqi@0: File[] files = dir.listFiles(); aoqi@0: if (files == null) return; // work defensively aoqi@0: aoqi@0: for (File f : files) { aoqi@0: if (f.isDirectory()) aoqi@0: addRecursive(f, suffix, result); aoqi@0: else if (f.getPath().endsWith(suffix)) aoqi@0: result.add(absolutize(fileToInputSource(f))); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private InputSource absolutize(InputSource is) { aoqi@0: // absolutize all the system IDs in the input, aoqi@0: // so that we can map system IDs to DOM trees. aoqi@0: try { aoqi@0: URL baseURL = new File(".").getCanonicalFile().toURL(); aoqi@0: is.setSystemId(new URL(baseURL, is.getSystemId()).toExternalForm()); aoqi@0: } catch (IOException e) { aoqi@0: // ignore aoqi@0: } aoqi@0: return is; aoqi@0: } aoqi@0: aoqi@0: public void addBindings(String name) throws BadCommandLineException { aoqi@0: addFile(name, bindingFiles, null); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Parses a token to a file (or a set of files) aoqi@0: * and add them as {@link InputSource} to the specified list. aoqi@0: * aoqi@0: * @param suffix If the given token is a directory name, we do a recusive search aoqi@0: * and find all files that have the given suffix. aoqi@0: */ aoqi@0: private void addFile(String name, List target, String suffix) throws BadCommandLineException { aoqi@0: Object src; aoqi@0: try { aoqi@0: src = Util.getFileOrURL(name); aoqi@0: } catch (IOException e) { aoqi@0: throw new BadCommandLineException(WscompileMessages.WSIMPORT_NOT_A_FILE_NOR_URL(name)); aoqi@0: } aoqi@0: if (src instanceof URL) { aoqi@0: target.add(absolutize(new InputSource(Util.escapeSpace(((URL) src).toExternalForm())))); aoqi@0: } else { aoqi@0: File fsrc = (File) src; aoqi@0: if (fsrc.isDirectory()) { aoqi@0: addRecursive(fsrc, suffix, target); aoqi@0: } else { aoqi@0: target.add(absolutize(fileToInputSource(fsrc))); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it. aoqi@0: * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model aoqi@0: * aoqi@0: * Binding files could be jaxws or jaxb. This method identifies jaxws and jaxb binding files and keeps them separately. jaxb binding files are given separately aoqi@0: * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder} aoqi@0: * aoqi@0: * @param receiver {@link ErrorReceiver} aoqi@0: */ aoqi@0: public final void parseBindings(ErrorReceiver receiver){ aoqi@0: for (InputSource is : bindingFiles) { aoqi@0: XMLStreamReader reader = aoqi@0: XMLStreamReaderFactory.create(is,true); aoqi@0: XMLStreamReaderUtil.nextElementContent(reader); aoqi@0: if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) { aoqi@0: jaxwsCustomBindings.add(new RereadInputSource(is)); aoqi@0: } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) || aoqi@0: reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) { aoqi@0: jaxbCustomBindings.add(new RereadInputSource(is)); aoqi@0: } else { aoqi@0: LocatorImpl locator = new LocatorImpl(); aoqi@0: locator.setSystemId(reader.getLocation().getSystemId()); aoqi@0: locator.setPublicId(reader.getLocation().getPublicId()); aoqi@0: locator.setLineNumber(reader.getLocation().getLineNumber()); aoqi@0: locator.setColumnNumber(reader.getLocation().getColumnNumber()); aoqi@0: receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId())); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get extension argument aoqi@0: */ aoqi@0: public String getExtensionOption(String argument) { aoqi@0: return extensionOptions.get(argument); aoqi@0: } aoqi@0: aoqi@0: private void parseProxy(String text) throws BadCommandLineException { aoqi@0: int i = text.lastIndexOf('@'); aoqi@0: int j = text.lastIndexOf(':'); aoqi@0: aoqi@0: if (i > 0) { aoqi@0: proxyAuth = text.substring(0, i); aoqi@0: if (j > i) { aoqi@0: proxyHost = text.substring(i + 1, j); aoqi@0: proxyPort = text.substring(j + 1); aoqi@0: } else { aoqi@0: proxyHost = text.substring(i + 1); aoqi@0: proxyPort = "8080"; aoqi@0: } aoqi@0: } else { aoqi@0: //no auth info aoqi@0: if (j < 0) { aoqi@0: //no port aoqi@0: proxyHost = text; aoqi@0: proxyPort = "8080"; aoqi@0: } else { aoqi@0: proxyHost = text.substring(0, j); aoqi@0: proxyPort = text.substring(j + 1); aoqi@0: } aoqi@0: } aoqi@0: try { aoqi@0: Integer.valueOf(proxyPort); aoqi@0: } catch (NumberFormatException e) { aoqi@0: throw new BadCommandLineException(WscompileMessages.WSIMPORT_ILLEGAL_PROXY(text)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Looks for all "META-INF/services/[className]" files and aoqi@0: * create one instance for each class name found inside this file. aoqi@0: */ aoqi@0: private static T[] findServices(Class clazz, ClassLoader classLoader) { aoqi@0: ServiceFinder serviceFinder = ServiceFinder.find(clazz, classLoader); aoqi@0: List r = new ArrayList(); aoqi@0: for (T t : serviceFinder) { aoqi@0: r.add(t); aoqi@0: } aoqi@0: return r.toArray((T[]) Array.newInstance(clazz, r.size())); aoqi@0: } aoqi@0: aoqi@0: private static final class ByteStream extends ByteArrayOutputStream { aoqi@0: byte[] getBuffer() { aoqi@0: return buf; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static final class RereadInputStream extends InputStream { aoqi@0: private InputStream is; aoqi@0: private ByteStream bs; aoqi@0: aoqi@0: RereadInputStream(InputStream is) { aoqi@0: this.is = is; aoqi@0: this.bs = new ByteStream(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int available() throws IOException { aoqi@0: return is.available(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void close() throws IOException { aoqi@0: if (bs != null) { aoqi@0: InputStream i = new ByteArrayInputStream(bs.getBuffer()); aoqi@0: bs = null; aoqi@0: is.close(); aoqi@0: is = i; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public synchronized void mark(int readlimit) { aoqi@0: is.mark(readlimit); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public boolean markSupported() { aoqi@0: return is.markSupported(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int read() throws IOException { aoqi@0: int r = is.read(); aoqi@0: if (bs != null) aoqi@0: bs.write(r); aoqi@0: return r; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int read(byte[] b, int off, int len) throws IOException { aoqi@0: int r = is.read(b, off, len); aoqi@0: if (r > 0 && bs != null) aoqi@0: bs.write(b, off, r); aoqi@0: return r; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int read(byte[] b) throws IOException { aoqi@0: int r = is.read(b); aoqi@0: if (r > 0 && bs != null) aoqi@0: bs.write(b, 0, r); aoqi@0: return r; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public synchronized void reset() throws IOException { aoqi@0: is.reset(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static final class RereadInputSource extends InputSource { aoqi@0: private InputSource is; aoqi@0: aoqi@0: RereadInputSource(InputSource is) { aoqi@0: this.is = is; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public InputStream getByteStream() { aoqi@0: InputStream i = is.getByteStream(); aoqi@0: if (i != null && !(i instanceof RereadInputStream)) { aoqi@0: i = new RereadInputStream(i); aoqi@0: is.setByteStream(i); aoqi@0: } aoqi@0: return i; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public Reader getCharacterStream() { aoqi@0: // TODO Auto-generated method stub aoqi@0: return is.getCharacterStream(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getEncoding() { aoqi@0: return is.getEncoding(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getPublicId() { aoqi@0: return is.getPublicId(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getSystemId() { aoqi@0: return is.getSystemId(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void setByteStream(InputStream byteStream) { aoqi@0: is.setByteStream(byteStream); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void setCharacterStream(Reader characterStream) { aoqi@0: is.setCharacterStream(characterStream); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void setEncoding(String encoding) { aoqi@0: is.setEncoding(encoding); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void setPublicId(String publicId) { aoqi@0: is.setPublicId(publicId); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void setSystemId(String systemId) { aoqi@0: is.setSystemId(systemId); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: protected void disableXmlSecurity() { aoqi@0: super.disableXmlSecurity(); aoqi@0: schemaCompiler.getOptions().disableXmlSecurity = true; aoqi@0: } aoqi@0: }