src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsimportOptions.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.internal.ws.wscompile;
    28 import com.sun.codemodel.internal.JCodeModel;
    29 import com.sun.tools.internal.ws.processor.generator.GeneratorExtension;
    30 import com.sun.tools.internal.ws.resources.ConfigurationMessages;
    31 import com.sun.tools.internal.ws.resources.WscompileMessages;
    32 import com.sun.tools.internal.ws.util.ForkEntityResolver;
    33 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
    34 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
    35 import com.sun.tools.internal.xjc.api.SchemaCompiler;
    36 import com.sun.tools.internal.xjc.api.SpecVersion;
    37 import com.sun.tools.internal.xjc.api.XJC;
    38 import com.sun.tools.internal.xjc.reader.Util;
    39 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
    40 import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
    41 import com.sun.xml.internal.ws.util.ServiceFinder;
    42 import com.sun.xml.internal.ws.util.JAXWSUtils;
    43 import com.sun.xml.internal.ws.util.xml.XmlUtil;
    44 import org.w3c.dom.Element;
    45 import org.xml.sax.EntityResolver;
    46 import org.xml.sax.InputSource;
    47 import org.xml.sax.helpers.LocatorImpl;
    49 import javax.xml.namespace.QName;
    50 import javax.xml.stream.XMLStreamReader;
    52 import java.io.ByteArrayInputStream;
    53 import java.io.ByteArrayOutputStream;
    54 import java.io.File;
    55 import java.io.IOException;
    56 import java.io.InputStream;
    57 import java.io.Reader;
    58 import java.lang.reflect.Array;
    59 import java.net.MalformedURLException;
    60 import java.net.URL;
    61 import java.util.ArrayList;
    62 import java.util.Arrays;
    63 import java.util.List;
    64 import java.util.HashMap;
    65 import java.util.logging.Level;
    66 import java.util.logging.Logger;
    68 /**
    69  * @author Vivek Pandey
    70  */
    71 public class WsimportOptions extends Options {
    72     /**
    73      * -wsdlLocation
    74      */
    75     public String wsdlLocation;
    77     /**
    78      * Actually stores {@link com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver}, but the field
    79      * type is made to {@link org.xml.sax.EntityResolver} so that XJC can be
    80      * used even if resolver.jar is not available in the classpath.
    81      */
    82     public EntityResolver entityResolver = null;
    84     /**
    85      * The -p option that should control the default Java package that
    86      * will contain the generated code. Null if unspecified.
    87      */
    88     public String defaultPackage = null;
    90     /**
    91      * The -clientjar option to package client artifacts as jar
    92      */
    93     public String clientjar = null;
    95     /**
    96      * -XadditionalHeaders
    97      */
    98     public boolean additionalHeaders;
   100     /**
   101      * The option indicates the dir where the jwsImpl will be generated.
   102      */
   103     public File implDestDir = null;
   105     /**
   106      * optional, generated impl file only for the ordered serviceName
   107      * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part
   108      */
   109     public String implServiceName = null;
   111     /**
   112      * optional, generated impl file only for the ordered portName
   113      * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part
   114      */
   115     public String implPortName = null;
   117     /**
   118      * optional, if true JWS file is generated
   119      */
   120     public boolean isGenerateJWS = false;
   122     /**
   123      * Setting disableSSLHostVerification to true disables the SSL Hostname verification while fetching the wsdls.
   124      * -XdisableSSLHostVerification
   125      */
   126     public boolean disableSSLHostnameVerification;
   128     /**
   129      * Setting useBaseResourceAndURLToLoadWSDL to true causes generated Service classes to load the WSDL file from
   130      * a URL generated from the base resource.
   131      * -XuseBaseResourceAndURLToLoadWSDL
   132      */
   133     public boolean useBaseResourceAndURLToLoadWSDL = false;
   135     /**
   136      * JAXB's {@link SchemaCompiler} to be used for handling the schema portion.
   137      * This object is also configured through options.
   138      */
   139     private SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
   141     /**
   142      * Authentication file
   143      */
   144     public File authFile = null;
   146     //can user.home value be null?
   147     public static final String defaultAuthfile
   148             = System.getProperty("user.home") + System.getProperty("file.separator")
   149             + ".metro" + System.getProperty("file.separator") + "auth";
   151     /**
   152      * Setting disableAuthenticator to true disables the DefaultAuthenticator.
   153      * -XdisableAuthenticator
   154      */
   155     public boolean disableAuthenticator;
   157     public String proxyAuth = null;
   158     private String proxyHost = null;
   159     private String proxyPort = null;
   161     /**
   162      * Additional arguments
   163      */
   164     public HashMap<String, String> extensionOptions = new HashMap<String, String>();
   166     /**
   167      * All discovered {@link Plugin}s.
   168      * This is lazily parsed, so that we can take '-cp' option into account.
   169      *
   170      * @see #getAllPlugins()
   171      */
   172     private List<Plugin> allPlugins;
   174     /**
   175      * {@link Plugin}s that are enabled in this compilation.
   176      */
   177     public final List<Plugin> activePlugins = new ArrayList<Plugin>();
   179     public JCodeModel getCodeModel() {
   180         if(codeModel == null)
   181             codeModel = new JCodeModel();
   182         return codeModel;
   183     }
   185     public SchemaCompiler getSchemaCompiler() {
   186         schemaCompiler.setTargetVersion(SpecVersion.parse(target.getVersion()));
   187         if(entityResolver != null) {
   188             //set if its not null so as not to override catalog option specified via xjc args
   189             schemaCompiler.setEntityResolver(entityResolver);
   190         }
   191         return schemaCompiler;
   192     }
   194     public void setCodeModel(JCodeModel codeModel) {
   195         this.codeModel = codeModel;
   196     }
   198     private JCodeModel codeModel;
   200     /**
   201      * This captures jars passed on the commandline and passes them to XJC and puts them in the classpath for compilation
   202      */
   203     public List<String> cmdlineJars = new ArrayList<String>();
   205     /**
   206      * Gets all the {@link Plugin}s discovered so far.
   207      *
   208      * <p>
   209      * A plugins are enumerated when this method is called for the first time,
   210      * by taking {@link #classpath} into account. That means
   211      * "-cp plugin.jar" has to come before you specify options to enable it.
   212      */
   213     public List<Plugin> getAllPlugins() {
   214         if(allPlugins==null) {
   215             allPlugins = new ArrayList<Plugin>();
   216             allPlugins.addAll(Arrays.asList(findServices(Plugin.class, getClassLoader())));
   217         }
   218         return allPlugins;
   219     }
   221     /**
   222      * Parses arguments and fill fields of this object.
   223      *
   224      * @exception BadCommandLineException
   225      *      thrown when there's a problem in the command-line arguments
   226      */
   227     @Override
   228     public final void parseArguments( String[] args ) throws BadCommandLineException {
   230         for (int i = 0; i < args.length; i++) {
   231             if(args[i].length()==0)
   232                 throw new BadCommandLineException();
   233             if (args[i].charAt(0) == '-') {
   234                 int j = parseArguments(args,i);
   235                 if(j==0)
   236                     throw new BadCommandLineException(WscompileMessages.WSCOMPILE_INVALID_OPTION(args[i]));
   237                 i += (j-1);
   238             } else {
   239                 if(args[i].endsWith(".jar")) {
   241                     try {
   242                 cmdlineJars.add(args[i]);
   243                 schemaCompiler.getOptions().scanEpisodeFile(new File(args[i]));
   245             } catch (com.sun.tools.internal.xjc.BadCommandLineException e) {
   246                 //Driver.usage(jaxbOptions,false);
   247                 throw new BadCommandLineException(e.getMessage(), e);
   248             }
   249                 } else{
   250                     addFile(args[i]);
   251                 }
   252             }
   253         }
   255         if (encoding != null && schemaCompiler.getOptions().encoding == null) {
   256             try {
   257                 schemaCompiler.getOptions().parseArgument(
   258                         new String[] {"-encoding", encoding}, 0);
   259             } catch (com.sun.tools.internal.xjc.BadCommandLineException ex) {
   260                 Logger.getLogger(WsimportOptions.class.getName()).log(Level.SEVERE, null, ex);
   261             }
   262         }
   264         if(destDir == null)
   265             destDir = new File(".");
   266         if(sourceDir == null)
   267             sourceDir = destDir;
   268     }
   270     /** -Xno-addressing-databinding option to disable addressing namespace data binding. This is
   271      * experimental switch and will be working as a temporary workaround till
   272      * jaxb can provide a better way to selelctively disable compiling of an
   273      * schema component.
   274      * **/
   275     public boolean noAddressingBbinding;
   277     @Override
   278     public int parseArguments(String[] args, int i) throws BadCommandLineException {
   279         int j = super.parseArguments(args ,i);
   280         if(j>0) return j;   // understood by the super class
   282         if (args[i].equals("-b")) {
   283             addBindings(requireArgument("-b", args, ++i));
   284             return 2;
   285         } else if (args[i].equals("-wsdllocation")) {
   286             wsdlLocation = requireArgument("-wsdllocation", args, ++i);
   287             return 2;
   288         } else if (args[i].equals("-XadditionalHeaders")) {
   289             additionalHeaders = true;
   290             return 1;
   291         } else if (args[i].equals("-XdisableSSLHostnameVerification")) {
   292             disableSSLHostnameVerification = true;
   293             return 1;
   294         } else if (args[i].equals("-p")) {
   295             defaultPackage = requireArgument("-p", args, ++i);
   296             return 2;
   297         } else if (args[i].equals("-catalog")) {
   298             String catalog = requireArgument("-catalog", args, ++i);
   299             try {
   300                 if (entityResolver == null) {
   301                     if (catalog != null && catalog.length() > 0)
   302                         entityResolver = XmlUtil.createEntityResolver(JAXWSUtils.getFileOrURL(JAXWSUtils.absolutize(Util.escapeSpace(catalog))));
   303                 } else if (catalog != null && catalog.length() > 0) {
   304                     EntityResolver er = XmlUtil.createEntityResolver(JAXWSUtils.getFileOrURL(JAXWSUtils.absolutize(Util.escapeSpace(catalog))));
   305                     entityResolver = new ForkEntityResolver(er, entityResolver);
   306                 }
   307             } catch (IOException e) {
   308                 throw new BadCommandLineException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(catalog, e.getMessage()));
   309             }
   310             return 2;
   311         } else if (args[i].startsWith("-httpproxy:")) {
   312             String value = args[i].substring(11);
   313             if (value.length() == 0) {
   314                 throw new BadCommandLineException(WscompileMessages.WSCOMPILE_INVALID_OPTION(args[i]));
   315             }
   316             parseProxy(value);
   317             if (proxyHost != null || proxyPort != null) {
   318                 System.setProperty("proxySet", "true");
   319             }
   320             if (proxyHost != null) {
   321                 System.setProperty("proxyHost", proxyHost);
   322             }
   323             if (proxyPort != null) {
   324                 System.setProperty("proxyPort", proxyPort);
   325             }
   326             return 1;
   327         } else if (args[i].equals("-Xno-addressing-databinding")) {
   328             noAddressingBbinding = true;
   329             return 1;
   330         } else if (args[i].startsWith("-B")) {
   331             // JAXB option pass through.
   332             String[] subCmd = new String[args.length-i];
   333             System.arraycopy(args,i,subCmd,0,subCmd.length);
   334             subCmd[0] = subCmd[0].substring(2); // trim off the first "-B"
   336             com.sun.tools.internal.xjc.Options jaxbOptions = schemaCompiler.getOptions();
   337             try {
   338                 int r = jaxbOptions.parseArgument(subCmd, 0);
   339                 if(r==0) {
   340                     //Driver.usage(jaxbOptions,false);
   341                     throw new BadCommandLineException(WscompileMessages.WSIMPORT_NO_SUCH_JAXB_OPTION(subCmd[0]));
   342                 }
   343                 return r;
   344             } catch (com.sun.tools.internal.xjc.BadCommandLineException e) {
   345                 //Driver.usage(jaxbOptions,false);
   346                 throw new BadCommandLineException(e.getMessage(),e);
   347             }
   348         } else if (args[i].equals("-Xauthfile")) {
   349             String authfile = requireArgument("-Xauthfile", args, ++i);
   350             authFile = new File(authfile);
   351             return 2;
   352         } else if (args[i].equals("-clientjar")) {
   353             clientjar = requireArgument("-clientjar", args, ++i);
   354             return 2;
   355         } else if (args[i].equals("-implDestDir")) {
   356                         implDestDir = new File(requireArgument("-implDestDir", args, ++i));
   357             if (!implDestDir.exists())
   358               throw new BadCommandLineException(WscompileMessages.WSCOMPILE_NO_SUCH_DIRECTORY(implDestDir.getPath()));
   359                         return 2;
   360         } else if (args[i].equals("-implServiceName")) {
   361                 implServiceName = requireArgument("-implServiceName", args, ++i);
   362           return 2;
   363         } else if (args[i].equals("-implPortName")) {
   364                 implPortName = requireArgument("-implPortName", args, ++i);
   365           return 2;
   366         } else if (args[i].equals("-generateJWS")) {
   367             isGenerateJWS = true;
   368             return 1;
   369         } else if (args[i].equals("-XuseBaseResourceAndURLToLoadWSDL")) {
   370                 useBaseResourceAndURLToLoadWSDL = true;
   371             return 1;
   372         } else if (args[i].equals("-XdisableAuthenticator")) {
   373             disableAuthenticator = true;
   374             return 1;
   375         }
   377         // handle additional options
   378         for (GeneratorExtension f:ServiceFinder.find(GeneratorExtension.class)) {
   379             if (f.validateOption(args[i])) {
   380                 extensionOptions.put(args[i], requireArgument(args[i], args, ++i));
   381                 return 2;
   382             }
   383         }
   385         // see if this is one of the extensions
   386         for( Plugin plugin : getAllPlugins() ) {
   387             try {
   388                 if(('-' + plugin.getOptionName()).equals(args[i])) {
   389                     activePlugins.add(plugin);
   390                     plugin.onActivated(this);
   391                     return 1;
   392                 }
   393                 int r = plugin.parseArgument(this, args, i);
   394                 if (r != 0) {
   395                     return r;
   396                 }
   397             } catch (IOException e) {
   398                 throw new BadCommandLineException(e.getMessage(),e);
   399             }
   400         }
   402         return 0; // what's this option?
   403     }
   405     public void validate() throws BadCommandLineException {
   406         if (wsdls.isEmpty()) {
   407             throw new BadCommandLineException(WscompileMessages.WSIMPORT_MISSING_FILE());
   408         }
   410         if(wsdlLocation !=null && clientjar != null) {
   411            throw new BadCommandLineException(WscompileMessages.WSIMPORT_WSDLLOCATION_CLIENTJAR());
   412         }
   413         if(wsdlLocation == null){
   414             wsdlLocation = wsdls.get(0).getSystemId();
   415         }
   418     }
   420     @Override
   421     protected void addFile(String arg) throws BadCommandLineException {
   422         addFile(arg, wsdls, ".wsdl");
   423     }
   425     private final List<InputSource> wsdls = new ArrayList<InputSource>();
   426     private final List<InputSource> schemas = new ArrayList<InputSource>();
   427     private final List<InputSource> bindingFiles = new ArrayList<InputSource>();
   428     private final List<InputSource> jaxwsCustomBindings = new ArrayList<InputSource>();
   429     private final List<InputSource> jaxbCustomBindings = new ArrayList<InputSource>();
   430     private final List<Element> handlerConfigs = new ArrayList<Element>();
   432     /**
   433      * There is supposed to be one handler chain per generated SEI.
   434      * TODO: There is possible bug, how to associate a @HandlerChain
   435      * with each port on the generated SEI. For now lets preserve the JAXWS 2.0 FCS
   436      * behaviour and generate only one @HandlerChain on the SEI
   437      */
   438     public Element getHandlerChainConfiguration(){
   439         if(handlerConfigs.size() > 0)
   440             return handlerConfigs.get(0);
   441         return null;
   442     }
   444     public void addHandlerChainConfiguration(Element config){
   445         handlerConfigs.add(config);
   446     }
   448     public InputSource[] getWSDLs() {
   449         return wsdls.toArray(new InputSource[wsdls.size()]);
   450     }
   452     public InputSource[] getSchemas() {
   453         return schemas.toArray(new InputSource[schemas.size()]);
   454     }
   456     public InputSource[] getWSDLBindings() {
   457         return jaxwsCustomBindings.toArray(new InputSource[jaxwsCustomBindings.size()]);
   458     }
   460     public InputSource[] getSchemaBindings() {
   461         return jaxbCustomBindings.toArray(new InputSource[jaxbCustomBindings.size()]);
   462     }
   464     public void addWSDL(File source) {
   465         addWSDL(fileToInputSource(source));
   466     }
   468     public void addWSDL(InputSource is) {
   469         wsdls.add(absolutize(is));
   470     }
   472     public void addSchema(File source) {
   473         addSchema(fileToInputSource(source));
   474     }
   476     public void addSchema(InputSource is) {
   477         schemas.add(is);
   478     }
   480     private InputSource fileToInputSource(File source) {
   481         try {
   482             String url = source.toURL().toExternalForm();
   483             return new InputSource(Util.escapeSpace(url));
   484         } catch (MalformedURLException e) {
   485             return new InputSource(source.getPath());
   486         }
   487     }
   489     /**
   490      * Recursively scan directories and add all XSD files in it.
   491      */
   492     public void addGrammarRecursive(File dir) {
   493         addRecursive(dir, ".wsdl", wsdls);
   494         addRecursive(dir, ".xsd", schemas);
   495     }
   497     /**
   498      * Adds a new input schema.
   499      */
   500     public void addWSDLBindFile(InputSource is) {
   501         jaxwsCustomBindings.add(new RereadInputSource(absolutize(is)));
   502     }
   504     public void addSchemmaBindFile(InputSource is) {
   505         jaxbCustomBindings.add(new RereadInputSource(absolutize(is)));
   506     }
   508     private void addRecursive(File dir, String suffix, List<InputSource> result) {
   509         File[] files = dir.listFiles();
   510         if (files == null) return; // work defensively
   512         for (File f : files) {
   513             if (f.isDirectory())
   514                 addRecursive(f, suffix, result);
   515             else if (f.getPath().endsWith(suffix))
   516                 result.add(absolutize(fileToInputSource(f)));
   517         }
   518     }
   520     private InputSource absolutize(InputSource is) {
   521         // absolutize all the system IDs in the input,
   522         // so that we can map system IDs to DOM trees.
   523         try {
   524             URL baseURL = new File(".").getCanonicalFile().toURL();
   525             is.setSystemId(new URL(baseURL, is.getSystemId()).toExternalForm());
   526         } catch (IOException e) {
   527             // ignore
   528         }
   529         return is;
   530     }
   532     public void addBindings(String name) throws BadCommandLineException {
   533         addFile(name, bindingFiles, null);
   534     }
   536     /**
   537      * Parses a token to a file (or a set of files)
   538      * and add them as {@link InputSource} to the specified list.
   539      *
   540      * @param suffix If the given token is a directory name, we do a recusive search
   541      *               and find all files that have the given suffix.
   542      */
   543     private void addFile(String name, List<InputSource> target, String suffix) throws BadCommandLineException {
   544         Object src;
   545         try {
   546             src = Util.getFileOrURL(name);
   547         } catch (IOException e) {
   548             throw new BadCommandLineException(WscompileMessages.WSIMPORT_NOT_A_FILE_NOR_URL(name));
   549         }
   550         if (src instanceof URL) {
   551             target.add(absolutize(new InputSource(Util.escapeSpace(((URL) src).toExternalForm()))));
   552         } else {
   553             File fsrc = (File) src;
   554             if (fsrc.isDirectory()) {
   555                 addRecursive(fsrc, suffix, target);
   556             } else {
   557                 target.add(absolutize(fileToInputSource(fsrc)));
   558             }
   559         }
   560     }
   563     /**
   564      * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it.
   565      * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model
   566      *
   567      * 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
   568      * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder}
   569      *
   570      * @param receiver {@link ErrorReceiver}
   571      */
   572     public final void parseBindings(ErrorReceiver receiver){
   573         for (InputSource is : bindingFiles) {
   574             XMLStreamReader reader =
   575                     XMLStreamReaderFactory.create(is,true);
   576             XMLStreamReaderUtil.nextElementContent(reader);
   577             if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) {
   578                 jaxwsCustomBindings.add(new RereadInputSource(is));
   579             } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) ||
   580                     reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) {
   581                 jaxbCustomBindings.add(new RereadInputSource(is));
   582             } else {
   583                 LocatorImpl locator = new LocatorImpl();
   584                 locator.setSystemId(reader.getLocation().getSystemId());
   585                 locator.setPublicId(reader.getLocation().getPublicId());
   586                 locator.setLineNumber(reader.getLocation().getLineNumber());
   587                 locator.setColumnNumber(reader.getLocation().getColumnNumber());
   588                 receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId()));
   589             }
   590         }
   591     }
   593     /**
   594      * Get extension argument
   595      */
   596     public String getExtensionOption(String argument) {
   597         return extensionOptions.get(argument);
   598     }
   600     private void parseProxy(String text) throws BadCommandLineException {
   601         int i = text.lastIndexOf('@');
   602         int j = text.lastIndexOf(':');
   604         if (i > 0) {
   605             proxyAuth = text.substring(0, i);
   606             if (j > i) {
   607                 proxyHost = text.substring(i + 1, j);
   608                 proxyPort = text.substring(j + 1);
   609             } else {
   610                 proxyHost = text.substring(i + 1);
   611                 proxyPort = "8080";
   612             }
   613         } else {
   614             //no auth info
   615             if (j < 0) {
   616                 //no port
   617                 proxyHost = text;
   618                 proxyPort = "8080";
   619             } else {
   620                 proxyHost = text.substring(0, j);
   621                 proxyPort = text.substring(j + 1);
   622             }
   623         }
   624         try {
   625             Integer.valueOf(proxyPort);
   626         } catch (NumberFormatException e) {
   627             throw new BadCommandLineException(WscompileMessages.WSIMPORT_ILLEGAL_PROXY(text));
   628         }
   629     }
   631     /**
   632      * Looks for all "META-INF/services/[className]" files and
   633      * create one instance for each class name found inside this file.
   634      */
   635     private static <T> T[] findServices(Class<T> clazz, ClassLoader classLoader) {
   636         ServiceFinder<T> serviceFinder = ServiceFinder.find(clazz, classLoader);
   637         List<T> r = new ArrayList<T>();
   638         for (T t : serviceFinder) {
   639             r.add(t);
   640         }
   641         return r.toArray((T[]) Array.newInstance(clazz, r.size()));
   642     }
   644     private static final class ByteStream extends ByteArrayOutputStream {
   645         byte[] getBuffer() {
   646                 return buf;
   647         }
   648     }
   650     private static final class RereadInputStream extends InputStream {
   651         private InputStream is;
   652         private ByteStream bs;
   654         RereadInputStream(InputStream is) {
   655                 this.is = is;
   656                 this.bs = new ByteStream();
   657         }
   659                 @Override
   660                 public int available() throws IOException {
   661                         return is.available();
   662                 }
   664                 @Override
   665                 public void close() throws IOException {
   666                         if (bs != null) {
   667                                 InputStream i = new ByteArrayInputStream(bs.getBuffer());
   668                                 bs = null;
   669                                 is.close();
   670                                 is = i;
   671                         }
   672                 }
   674                 @Override
   675                 public synchronized void mark(int readlimit) {
   676                         is.mark(readlimit);
   677                 }
   679                 @Override
   680                 public boolean markSupported() {
   681                         return is.markSupported();
   682                 }
   684                 @Override
   685                 public int read() throws IOException {
   686                         int r = is.read();
   687                         if (bs != null)
   688                                 bs.write(r);
   689                         return r;
   690                 }
   692                 @Override
   693                 public int read(byte[] b, int off, int len) throws IOException {
   694                         int r = is.read(b, off, len);
   695                         if (r > 0 && bs != null)
   696                                 bs.write(b, off, r);
   697                         return r;
   698                 }
   700                 @Override
   701                 public int read(byte[] b) throws IOException {
   702                         int r = is.read(b);
   703                         if (r > 0 && bs != null)
   704                                 bs.write(b, 0, r);
   705                         return r;
   706                 }
   708                 @Override
   709                 public synchronized void reset() throws IOException {
   710                         is.reset();
   711                 }
   712     }
   714     private static final class RereadInputSource extends InputSource {
   715         private InputSource is;
   717         RereadInputSource(InputSource is) {
   718                 this.is = is;
   719         }
   721                 @Override
   722                 public InputStream getByteStream() {
   723                         InputStream i = is.getByteStream();
   724                         if (i != null && !(i instanceof RereadInputStream)) {
   725                                 i = new RereadInputStream(i);
   726                                 is.setByteStream(i);
   727                         }
   728                         return i;
   729                 }
   731                 @Override
   732                 public Reader getCharacterStream() {
   733                         // TODO Auto-generated method stub
   734                         return is.getCharacterStream();
   735                 }
   737                 @Override
   738                 public String getEncoding() {
   739                         return is.getEncoding();
   740                 }
   742                 @Override
   743                 public String getPublicId() {
   744                         return is.getPublicId();
   745                 }
   747                 @Override
   748                 public String getSystemId() {
   749                         return is.getSystemId();
   750                 }
   752                 @Override
   753                 public void setByteStream(InputStream byteStream) {
   754                         is.setByteStream(byteStream);
   755                 }
   757                 @Override
   758                 public void setCharacterStream(Reader characterStream) {
   759                         is.setCharacterStream(characterStream);
   760                 }
   762                 @Override
   763                 public void setEncoding(String encoding) {
   764                         is.setEncoding(encoding);
   765                 }
   767                 @Override
   768                 public void setPublicId(String publicId) {
   769                         is.setPublicId(publicId);
   770                 }
   772                 @Override
   773                 public void setSystemId(String systemId) {
   774                         is.setSystemId(systemId);
   775                 }
   776     }
   778     @Override
   779     protected void disableXmlSecurity() {
   780         super.disableXmlSecurity();
   781         schemaCompiler.getOptions().disableXmlSecurity = true;
   782     }
   783 }

mercurial