ohair@286: /* alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.tools.internal.ws.wscompile; ohair@286: ohair@286: import com.sun.codemodel.internal.JCodeModel; ohair@286: import com.sun.tools.internal.ws.processor.generator.GeneratorExtension; ohair@286: import com.sun.tools.internal.ws.resources.ConfigurationMessages; ohair@286: import com.sun.tools.internal.ws.resources.WscompileMessages; ohair@286: import com.sun.tools.internal.ws.util.ForkEntityResolver; ohair@286: import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants; ohair@286: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants; ohair@286: import com.sun.tools.internal.xjc.api.SchemaCompiler; ohair@286: import com.sun.tools.internal.xjc.api.SpecVersion; ohair@286: import com.sun.tools.internal.xjc.api.XJC; ohair@286: import com.sun.tools.internal.xjc.reader.Util; ohair@286: import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory; ohair@286: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; ohair@286: import com.sun.xml.internal.ws.util.ServiceFinder; ohair@286: import com.sun.xml.internal.ws.util.JAXWSUtils; ohair@286: import com.sun.xml.internal.ws.util.xml.XmlUtil; ohair@286: import org.w3c.dom.Element; ohair@286: import org.xml.sax.EntityResolver; ohair@286: import org.xml.sax.InputSource; ohair@286: import org.xml.sax.helpers.LocatorImpl; ohair@286: ohair@286: import javax.xml.namespace.QName; ohair@286: import javax.xml.stream.XMLStreamReader; ohair@286: ohair@286: import java.io.ByteArrayInputStream; ohair@286: import java.io.ByteArrayOutputStream; ohair@286: import java.io.File; ohair@286: import java.io.IOException; ohair@286: import java.io.InputStream; ohair@286: import java.io.Reader; ohair@286: import java.lang.reflect.Array; ohair@286: import java.net.MalformedURLException; ohair@286: import java.net.URL; ohair@286: import java.util.ArrayList; ohair@286: import java.util.Arrays; ohair@286: import java.util.List; ohair@286: import java.util.HashMap; alanb@368: import java.util.logging.Level; alanb@368: import java.util.logging.Logger; ohair@286: ohair@286: /** ohair@286: * @author Vivek Pandey ohair@286: */ ohair@286: public class WsimportOptions extends Options { ohair@286: /** ohair@286: * -wsdlLocation ohair@286: */ ohair@286: public String wsdlLocation; ohair@286: ohair@286: /** ohair@286: * Actually stores {@link com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver}, but the field ohair@286: * type is made to {@link org.xml.sax.EntityResolver} so that XJC can be ohair@286: * used even if resolver.jar is not available in the classpath. ohair@286: */ ohair@286: public EntityResolver entityResolver = null; ohair@286: ohair@286: /** ohair@286: * The -p option that should control the default Java package that ohair@286: * will contain the generated code. Null if unspecified. ohair@286: */ ohair@286: public String defaultPackage = null; ohair@286: ohair@286: /** ohair@286: * The -clientjar option to package client artifacts as jar ohair@286: */ ohair@286: public String clientjar = null; ohair@286: ohair@286: /** ohair@286: * -XadditionalHeaders ohair@286: */ ohair@286: public boolean additionalHeaders; ohair@286: ohair@286: /** ohair@286: * The option indicates the dir where the jwsImpl will be generated. ohair@286: */ ohair@286: public File implDestDir = null; ohair@286: ohair@286: /** ohair@286: * optional, generated impl file only for the ordered serviceName ohair@286: * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part ohair@286: */ ohair@286: public String implServiceName = null; ohair@286: ohair@286: /** ohair@286: * optional, generated impl file only for the ordered portName ohair@286: * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part ohair@286: */ ohair@286: public String implPortName = null; ohair@286: ohair@286: /** ohair@286: * optional, if true JWS file is generated ohair@286: */ ohair@286: public boolean isGenerateJWS = false; ohair@286: ohair@286: /** ohair@286: * Setting disableSSLHostVerification to true disables the SSL Hostname verification while fetching the wsdls. ohair@286: * -XdisableSSLHostVerification ohair@286: */ ohair@286: public boolean disableSSLHostnameVerification; ohair@286: ohair@286: /** ohair@286: * Setting useBaseResourceAndURLToLoadWSDL to true causes generated Service classes to load the WSDL file from ohair@286: * a URL generated from the base resource. ohair@286: * -XuseBaseResourceAndURLToLoadWSDL ohair@286: */ ohair@286: public boolean useBaseResourceAndURLToLoadWSDL = false; ohair@286: ohair@286: /** ohair@286: * JAXB's {@link SchemaCompiler} to be used for handling the schema portion. ohair@286: * This object is also configured through options. ohair@286: */ ohair@286: private SchemaCompiler schemaCompiler = XJC.createSchemaCompiler(); ohair@286: ohair@286: /** ohair@286: * Authentication file ohair@286: */ alanb@368: public File authFile = null; alanb@368: alanb@368: //can user.home value be null? alanb@368: public static final String defaultAuthfile alanb@368: = System.getProperty("user.home") + System.getProperty("file.separator") alanb@368: + ".metro" + System.getProperty("file.separator") + "auth"; ohair@286: ohair@286: /** ohair@286: * Setting disableAuthenticator to true disables the DefaultAuthenticator. ohair@286: * -XdisableAuthenticator ohair@286: */ ohair@286: public boolean disableAuthenticator; ohair@286: alanb@368: public String proxyAuth = null; alanb@368: private String proxyHost = null; alanb@368: private String proxyPort = null; alanb@368: ohair@286: /** ohair@286: * Additional arguments ohair@286: */ ohair@286: public HashMap extensionOptions = new HashMap(); ohair@286: ohair@286: /** ohair@286: * All discovered {@link Plugin}s. ohair@286: * This is lazily parsed, so that we can take '-cp' option into account. ohair@286: * ohair@286: * @see #getAllPlugins() ohair@286: */ ohair@286: private List allPlugins; ohair@286: ohair@286: /** ohair@286: * {@link Plugin}s that are enabled in this compilation. ohair@286: */ ohair@286: public final List activePlugins = new ArrayList(); ohair@286: ohair@286: public JCodeModel getCodeModel() { ohair@286: if(codeModel == null) ohair@286: codeModel = new JCodeModel(); ohair@286: return codeModel; ohair@286: } ohair@286: ohair@286: public SchemaCompiler getSchemaCompiler() { ohair@286: schemaCompiler.setTargetVersion(SpecVersion.parse(target.getVersion())); ohair@286: if(entityResolver != null) { ohair@286: //set if its not null so as not to override catalog option specified via xjc args ohair@286: schemaCompiler.setEntityResolver(entityResolver); ohair@286: } ohair@286: return schemaCompiler; ohair@286: } ohair@286: ohair@286: public void setCodeModel(JCodeModel codeModel) { ohair@286: this.codeModel = codeModel; ohair@286: } ohair@286: ohair@286: private JCodeModel codeModel; ohair@286: ohair@286: /** ohair@286: * This captures jars passed on the commandline and passes them to XJC and puts them in the classpath for compilation ohair@286: */ ohair@286: public List cmdlineJars = new ArrayList(); ohair@286: ohair@286: /** ohair@286: * Gets all the {@link Plugin}s discovered so far. ohair@286: * ohair@286: *

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