1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsimportOptions.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,783 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.internal.ws.wscompile; 1.30 + 1.31 +import com.sun.codemodel.internal.JCodeModel; 1.32 +import com.sun.tools.internal.ws.processor.generator.GeneratorExtension; 1.33 +import com.sun.tools.internal.ws.resources.ConfigurationMessages; 1.34 +import com.sun.tools.internal.ws.resources.WscompileMessages; 1.35 +import com.sun.tools.internal.ws.util.ForkEntityResolver; 1.36 +import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants; 1.37 +import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants; 1.38 +import com.sun.tools.internal.xjc.api.SchemaCompiler; 1.39 +import com.sun.tools.internal.xjc.api.SpecVersion; 1.40 +import com.sun.tools.internal.xjc.api.XJC; 1.41 +import com.sun.tools.internal.xjc.reader.Util; 1.42 +import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory; 1.43 +import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; 1.44 +import com.sun.xml.internal.ws.util.ServiceFinder; 1.45 +import com.sun.xml.internal.ws.util.JAXWSUtils; 1.46 +import com.sun.xml.internal.ws.util.xml.XmlUtil; 1.47 +import org.w3c.dom.Element; 1.48 +import org.xml.sax.EntityResolver; 1.49 +import org.xml.sax.InputSource; 1.50 +import org.xml.sax.helpers.LocatorImpl; 1.51 + 1.52 +import javax.xml.namespace.QName; 1.53 +import javax.xml.stream.XMLStreamReader; 1.54 + 1.55 +import java.io.ByteArrayInputStream; 1.56 +import java.io.ByteArrayOutputStream; 1.57 +import java.io.File; 1.58 +import java.io.IOException; 1.59 +import java.io.InputStream; 1.60 +import java.io.Reader; 1.61 +import java.lang.reflect.Array; 1.62 +import java.net.MalformedURLException; 1.63 +import java.net.URL; 1.64 +import java.util.ArrayList; 1.65 +import java.util.Arrays; 1.66 +import java.util.List; 1.67 +import java.util.HashMap; 1.68 +import java.util.logging.Level; 1.69 +import java.util.logging.Logger; 1.70 + 1.71 +/** 1.72 + * @author Vivek Pandey 1.73 + */ 1.74 +public class WsimportOptions extends Options { 1.75 + /** 1.76 + * -wsdlLocation 1.77 + */ 1.78 + public String wsdlLocation; 1.79 + 1.80 + /** 1.81 + * Actually stores {@link com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver}, but the field 1.82 + * type is made to {@link org.xml.sax.EntityResolver} so that XJC can be 1.83 + * used even if resolver.jar is not available in the classpath. 1.84 + */ 1.85 + public EntityResolver entityResolver = null; 1.86 + 1.87 + /** 1.88 + * The -p option that should control the default Java package that 1.89 + * will contain the generated code. Null if unspecified. 1.90 + */ 1.91 + public String defaultPackage = null; 1.92 + 1.93 + /** 1.94 + * The -clientjar option to package client artifacts as jar 1.95 + */ 1.96 + public String clientjar = null; 1.97 + 1.98 + /** 1.99 + * -XadditionalHeaders 1.100 + */ 1.101 + public boolean additionalHeaders; 1.102 + 1.103 + /** 1.104 + * The option indicates the dir where the jwsImpl will be generated. 1.105 + */ 1.106 + public File implDestDir = null; 1.107 + 1.108 + /** 1.109 + * optional, generated impl file only for the ordered serviceName 1.110 + * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part 1.111 + */ 1.112 + public String implServiceName = null; 1.113 + 1.114 + /** 1.115 + * optional, generated impl file only for the ordered portName 1.116 + * Note: It is a QName string, formatted as: "{" + Namespace URI + "}" + local part 1.117 + */ 1.118 + public String implPortName = null; 1.119 + 1.120 + /** 1.121 + * optional, if true JWS file is generated 1.122 + */ 1.123 + public boolean isGenerateJWS = false; 1.124 + 1.125 + /** 1.126 + * Setting disableSSLHostVerification to true disables the SSL Hostname verification while fetching the wsdls. 1.127 + * -XdisableSSLHostVerification 1.128 + */ 1.129 + public boolean disableSSLHostnameVerification; 1.130 + 1.131 + /** 1.132 + * Setting useBaseResourceAndURLToLoadWSDL to true causes generated Service classes to load the WSDL file from 1.133 + * a URL generated from the base resource. 1.134 + * -XuseBaseResourceAndURLToLoadWSDL 1.135 + */ 1.136 + public boolean useBaseResourceAndURLToLoadWSDL = false; 1.137 + 1.138 + /** 1.139 + * JAXB's {@link SchemaCompiler} to be used for handling the schema portion. 1.140 + * This object is also configured through options. 1.141 + */ 1.142 + private SchemaCompiler schemaCompiler = XJC.createSchemaCompiler(); 1.143 + 1.144 + /** 1.145 + * Authentication file 1.146 + */ 1.147 + public File authFile = null; 1.148 + 1.149 + //can user.home value be null? 1.150 + public static final String defaultAuthfile 1.151 + = System.getProperty("user.home") + System.getProperty("file.separator") 1.152 + + ".metro" + System.getProperty("file.separator") + "auth"; 1.153 + 1.154 + /** 1.155 + * Setting disableAuthenticator to true disables the DefaultAuthenticator. 1.156 + * -XdisableAuthenticator 1.157 + */ 1.158 + public boolean disableAuthenticator; 1.159 + 1.160 + public String proxyAuth = null; 1.161 + private String proxyHost = null; 1.162 + private String proxyPort = null; 1.163 + 1.164 + /** 1.165 + * Additional arguments 1.166 + */ 1.167 + public HashMap<String, String> extensionOptions = new HashMap<String, String>(); 1.168 + 1.169 + /** 1.170 + * All discovered {@link Plugin}s. 1.171 + * This is lazily parsed, so that we can take '-cp' option into account. 1.172 + * 1.173 + * @see #getAllPlugins() 1.174 + */ 1.175 + private List<Plugin> allPlugins; 1.176 + 1.177 + /** 1.178 + * {@link Plugin}s that are enabled in this compilation. 1.179 + */ 1.180 + public final List<Plugin> activePlugins = new ArrayList<Plugin>(); 1.181 + 1.182 + public JCodeModel getCodeModel() { 1.183 + if(codeModel == null) 1.184 + codeModel = new JCodeModel(); 1.185 + return codeModel; 1.186 + } 1.187 + 1.188 + public SchemaCompiler getSchemaCompiler() { 1.189 + schemaCompiler.setTargetVersion(SpecVersion.parse(target.getVersion())); 1.190 + if(entityResolver != null) { 1.191 + //set if its not null so as not to override catalog option specified via xjc args 1.192 + schemaCompiler.setEntityResolver(entityResolver); 1.193 + } 1.194 + return schemaCompiler; 1.195 + } 1.196 + 1.197 + public void setCodeModel(JCodeModel codeModel) { 1.198 + this.codeModel = codeModel; 1.199 + } 1.200 + 1.201 + private JCodeModel codeModel; 1.202 + 1.203 + /** 1.204 + * This captures jars passed on the commandline and passes them to XJC and puts them in the classpath for compilation 1.205 + */ 1.206 + public List<String> cmdlineJars = new ArrayList<String>(); 1.207 + 1.208 + /** 1.209 + * Gets all the {@link Plugin}s discovered so far. 1.210 + * 1.211 + * <p> 1.212 + * A plugins are enumerated when this method is called for the first time, 1.213 + * by taking {@link #classpath} into account. That means 1.214 + * "-cp plugin.jar" has to come before you specify options to enable it. 1.215 + */ 1.216 + public List<Plugin> getAllPlugins() { 1.217 + if(allPlugins==null) { 1.218 + allPlugins = new ArrayList<Plugin>(); 1.219 + allPlugins.addAll(Arrays.asList(findServices(Plugin.class, getClassLoader()))); 1.220 + } 1.221 + return allPlugins; 1.222 + } 1.223 + 1.224 + /** 1.225 + * Parses arguments and fill fields of this object. 1.226 + * 1.227 + * @exception BadCommandLineException 1.228 + * thrown when there's a problem in the command-line arguments 1.229 + */ 1.230 + @Override 1.231 + public final void parseArguments( String[] args ) throws BadCommandLineException { 1.232 + 1.233 + for (int i = 0; i < args.length; i++) { 1.234 + if(args[i].length()==0) 1.235 + throw new BadCommandLineException(); 1.236 + if (args[i].charAt(0) == '-') { 1.237 + int j = parseArguments(args,i); 1.238 + if(j==0) 1.239 + throw new BadCommandLineException(WscompileMessages.WSCOMPILE_INVALID_OPTION(args[i])); 1.240 + i += (j-1); 1.241 + } else { 1.242 + if(args[i].endsWith(".jar")) { 1.243 + 1.244 + try { 1.245 + cmdlineJars.add(args[i]); 1.246 + schemaCompiler.getOptions().scanEpisodeFile(new File(args[i])); 1.247 + 1.248 + } catch (com.sun.tools.internal.xjc.BadCommandLineException e) { 1.249 + //Driver.usage(jaxbOptions,false); 1.250 + throw new BadCommandLineException(e.getMessage(), e); 1.251 + } 1.252 + } else{ 1.253 + addFile(args[i]); 1.254 + } 1.255 + } 1.256 + } 1.257 + 1.258 + if (encoding != null && schemaCompiler.getOptions().encoding == null) { 1.259 + try { 1.260 + schemaCompiler.getOptions().parseArgument( 1.261 + new String[] {"-encoding", encoding}, 0); 1.262 + } catch (com.sun.tools.internal.xjc.BadCommandLineException ex) { 1.263 + Logger.getLogger(WsimportOptions.class.getName()).log(Level.SEVERE, null, ex); 1.264 + } 1.265 + } 1.266 + 1.267 + if(destDir == null) 1.268 + destDir = new File("."); 1.269 + if(sourceDir == null) 1.270 + sourceDir = destDir; 1.271 + } 1.272 + 1.273 + /** -Xno-addressing-databinding option to disable addressing namespace data binding. This is 1.274 + * experimental switch and will be working as a temporary workaround till 1.275 + * jaxb can provide a better way to selelctively disable compiling of an 1.276 + * schema component. 1.277 + * **/ 1.278 + public boolean noAddressingBbinding; 1.279 + 1.280 + @Override 1.281 + public int parseArguments(String[] args, int i) throws BadCommandLineException { 1.282 + int j = super.parseArguments(args ,i); 1.283 + if(j>0) return j; // understood by the super class 1.284 + 1.285 + if (args[i].equals("-b")) { 1.286 + addBindings(requireArgument("-b", args, ++i)); 1.287 + return 2; 1.288 + } else if (args[i].equals("-wsdllocation")) { 1.289 + wsdlLocation = requireArgument("-wsdllocation", args, ++i); 1.290 + return 2; 1.291 + } else if (args[i].equals("-XadditionalHeaders")) { 1.292 + additionalHeaders = true; 1.293 + return 1; 1.294 + } else if (args[i].equals("-XdisableSSLHostnameVerification")) { 1.295 + disableSSLHostnameVerification = true; 1.296 + return 1; 1.297 + } else if (args[i].equals("-p")) { 1.298 + defaultPackage = requireArgument("-p", args, ++i); 1.299 + return 2; 1.300 + } else if (args[i].equals("-catalog")) { 1.301 + String catalog = requireArgument("-catalog", args, ++i); 1.302 + try { 1.303 + if (entityResolver == null) { 1.304 + if (catalog != null && catalog.length() > 0) 1.305 + entityResolver = XmlUtil.createEntityResolver(JAXWSUtils.getFileOrURL(JAXWSUtils.absolutize(Util.escapeSpace(catalog)))); 1.306 + } else if (catalog != null && catalog.length() > 0) { 1.307 + EntityResolver er = XmlUtil.createEntityResolver(JAXWSUtils.getFileOrURL(JAXWSUtils.absolutize(Util.escapeSpace(catalog)))); 1.308 + entityResolver = new ForkEntityResolver(er, entityResolver); 1.309 + } 1.310 + } catch (IOException e) { 1.311 + throw new BadCommandLineException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(catalog, e.getMessage())); 1.312 + } 1.313 + return 2; 1.314 + } else if (args[i].startsWith("-httpproxy:")) { 1.315 + String value = args[i].substring(11); 1.316 + if (value.length() == 0) { 1.317 + throw new BadCommandLineException(WscompileMessages.WSCOMPILE_INVALID_OPTION(args[i])); 1.318 + } 1.319 + parseProxy(value); 1.320 + if (proxyHost != null || proxyPort != null) { 1.321 + System.setProperty("proxySet", "true"); 1.322 + } 1.323 + if (proxyHost != null) { 1.324 + System.setProperty("proxyHost", proxyHost); 1.325 + } 1.326 + if (proxyPort != null) { 1.327 + System.setProperty("proxyPort", proxyPort); 1.328 + } 1.329 + return 1; 1.330 + } else if (args[i].equals("-Xno-addressing-databinding")) { 1.331 + noAddressingBbinding = true; 1.332 + return 1; 1.333 + } else if (args[i].startsWith("-B")) { 1.334 + // JAXB option pass through. 1.335 + String[] subCmd = new String[args.length-i]; 1.336 + System.arraycopy(args,i,subCmd,0,subCmd.length); 1.337 + subCmd[0] = subCmd[0].substring(2); // trim off the first "-B" 1.338 + 1.339 + com.sun.tools.internal.xjc.Options jaxbOptions = schemaCompiler.getOptions(); 1.340 + try { 1.341 + int r = jaxbOptions.parseArgument(subCmd, 0); 1.342 + if(r==0) { 1.343 + //Driver.usage(jaxbOptions,false); 1.344 + throw new BadCommandLineException(WscompileMessages.WSIMPORT_NO_SUCH_JAXB_OPTION(subCmd[0])); 1.345 + } 1.346 + return r; 1.347 + } catch (com.sun.tools.internal.xjc.BadCommandLineException e) { 1.348 + //Driver.usage(jaxbOptions,false); 1.349 + throw new BadCommandLineException(e.getMessage(),e); 1.350 + } 1.351 + } else if (args[i].equals("-Xauthfile")) { 1.352 + String authfile = requireArgument("-Xauthfile", args, ++i); 1.353 + authFile = new File(authfile); 1.354 + return 2; 1.355 + } else if (args[i].equals("-clientjar")) { 1.356 + clientjar = requireArgument("-clientjar", args, ++i); 1.357 + return 2; 1.358 + } else if (args[i].equals("-implDestDir")) { 1.359 + implDestDir = new File(requireArgument("-implDestDir", args, ++i)); 1.360 + if (!implDestDir.exists()) 1.361 + throw new BadCommandLineException(WscompileMessages.WSCOMPILE_NO_SUCH_DIRECTORY(implDestDir.getPath())); 1.362 + return 2; 1.363 + } else if (args[i].equals("-implServiceName")) { 1.364 + implServiceName = requireArgument("-implServiceName", args, ++i); 1.365 + return 2; 1.366 + } else if (args[i].equals("-implPortName")) { 1.367 + implPortName = requireArgument("-implPortName", args, ++i); 1.368 + return 2; 1.369 + } else if (args[i].equals("-generateJWS")) { 1.370 + isGenerateJWS = true; 1.371 + return 1; 1.372 + } else if (args[i].equals("-XuseBaseResourceAndURLToLoadWSDL")) { 1.373 + useBaseResourceAndURLToLoadWSDL = true; 1.374 + return 1; 1.375 + } else if (args[i].equals("-XdisableAuthenticator")) { 1.376 + disableAuthenticator = true; 1.377 + return 1; 1.378 + } 1.379 + 1.380 + // handle additional options 1.381 + for (GeneratorExtension f:ServiceFinder.find(GeneratorExtension.class)) { 1.382 + if (f.validateOption(args[i])) { 1.383 + extensionOptions.put(args[i], requireArgument(args[i], args, ++i)); 1.384 + return 2; 1.385 + } 1.386 + } 1.387 + 1.388 + // see if this is one of the extensions 1.389 + for( Plugin plugin : getAllPlugins() ) { 1.390 + try { 1.391 + if(('-' + plugin.getOptionName()).equals(args[i])) { 1.392 + activePlugins.add(plugin); 1.393 + plugin.onActivated(this); 1.394 + return 1; 1.395 + } 1.396 + int r = plugin.parseArgument(this, args, i); 1.397 + if (r != 0) { 1.398 + return r; 1.399 + } 1.400 + } catch (IOException e) { 1.401 + throw new BadCommandLineException(e.getMessage(),e); 1.402 + } 1.403 + } 1.404 + 1.405 + return 0; // what's this option? 1.406 + } 1.407 + 1.408 + public void validate() throws BadCommandLineException { 1.409 + if (wsdls.isEmpty()) { 1.410 + throw new BadCommandLineException(WscompileMessages.WSIMPORT_MISSING_FILE()); 1.411 + } 1.412 + 1.413 + if(wsdlLocation !=null && clientjar != null) { 1.414 + throw new BadCommandLineException(WscompileMessages.WSIMPORT_WSDLLOCATION_CLIENTJAR()); 1.415 + } 1.416 + if(wsdlLocation == null){ 1.417 + wsdlLocation = wsdls.get(0).getSystemId(); 1.418 + } 1.419 + 1.420 + 1.421 + } 1.422 + 1.423 + @Override 1.424 + protected void addFile(String arg) throws BadCommandLineException { 1.425 + addFile(arg, wsdls, ".wsdl"); 1.426 + } 1.427 + 1.428 + private final List<InputSource> wsdls = new ArrayList<InputSource>(); 1.429 + private final List<InputSource> schemas = new ArrayList<InputSource>(); 1.430 + private final List<InputSource> bindingFiles = new ArrayList<InputSource>(); 1.431 + private final List<InputSource> jaxwsCustomBindings = new ArrayList<InputSource>(); 1.432 + private final List<InputSource> jaxbCustomBindings = new ArrayList<InputSource>(); 1.433 + private final List<Element> handlerConfigs = new ArrayList<Element>(); 1.434 + 1.435 + /** 1.436 + * There is supposed to be one handler chain per generated SEI. 1.437 + * TODO: There is possible bug, how to associate a @HandlerChain 1.438 + * with each port on the generated SEI. For now lets preserve the JAXWS 2.0 FCS 1.439 + * behaviour and generate only one @HandlerChain on the SEI 1.440 + */ 1.441 + public Element getHandlerChainConfiguration(){ 1.442 + if(handlerConfigs.size() > 0) 1.443 + return handlerConfigs.get(0); 1.444 + return null; 1.445 + } 1.446 + 1.447 + public void addHandlerChainConfiguration(Element config){ 1.448 + handlerConfigs.add(config); 1.449 + } 1.450 + 1.451 + public InputSource[] getWSDLs() { 1.452 + return wsdls.toArray(new InputSource[wsdls.size()]); 1.453 + } 1.454 + 1.455 + public InputSource[] getSchemas() { 1.456 + return schemas.toArray(new InputSource[schemas.size()]); 1.457 + } 1.458 + 1.459 + public InputSource[] getWSDLBindings() { 1.460 + return jaxwsCustomBindings.toArray(new InputSource[jaxwsCustomBindings.size()]); 1.461 + } 1.462 + 1.463 + public InputSource[] getSchemaBindings() { 1.464 + return jaxbCustomBindings.toArray(new InputSource[jaxbCustomBindings.size()]); 1.465 + } 1.466 + 1.467 + public void addWSDL(File source) { 1.468 + addWSDL(fileToInputSource(source)); 1.469 + } 1.470 + 1.471 + public void addWSDL(InputSource is) { 1.472 + wsdls.add(absolutize(is)); 1.473 + } 1.474 + 1.475 + public void addSchema(File source) { 1.476 + addSchema(fileToInputSource(source)); 1.477 + } 1.478 + 1.479 + public void addSchema(InputSource is) { 1.480 + schemas.add(is); 1.481 + } 1.482 + 1.483 + private InputSource fileToInputSource(File source) { 1.484 + try { 1.485 + String url = source.toURL().toExternalForm(); 1.486 + return new InputSource(Util.escapeSpace(url)); 1.487 + } catch (MalformedURLException e) { 1.488 + return new InputSource(source.getPath()); 1.489 + } 1.490 + } 1.491 + 1.492 + /** 1.493 + * Recursively scan directories and add all XSD files in it. 1.494 + */ 1.495 + public void addGrammarRecursive(File dir) { 1.496 + addRecursive(dir, ".wsdl", wsdls); 1.497 + addRecursive(dir, ".xsd", schemas); 1.498 + } 1.499 + 1.500 + /** 1.501 + * Adds a new input schema. 1.502 + */ 1.503 + public void addWSDLBindFile(InputSource is) { 1.504 + jaxwsCustomBindings.add(new RereadInputSource(absolutize(is))); 1.505 + } 1.506 + 1.507 + public void addSchemmaBindFile(InputSource is) { 1.508 + jaxbCustomBindings.add(new RereadInputSource(absolutize(is))); 1.509 + } 1.510 + 1.511 + private void addRecursive(File dir, String suffix, List<InputSource> result) { 1.512 + File[] files = dir.listFiles(); 1.513 + if (files == null) return; // work defensively 1.514 + 1.515 + for (File f : files) { 1.516 + if (f.isDirectory()) 1.517 + addRecursive(f, suffix, result); 1.518 + else if (f.getPath().endsWith(suffix)) 1.519 + result.add(absolutize(fileToInputSource(f))); 1.520 + } 1.521 + } 1.522 + 1.523 + private InputSource absolutize(InputSource is) { 1.524 + // absolutize all the system IDs in the input, 1.525 + // so that we can map system IDs to DOM trees. 1.526 + try { 1.527 + URL baseURL = new File(".").getCanonicalFile().toURL(); 1.528 + is.setSystemId(new URL(baseURL, is.getSystemId()).toExternalForm()); 1.529 + } catch (IOException e) { 1.530 + // ignore 1.531 + } 1.532 + return is; 1.533 + } 1.534 + 1.535 + public void addBindings(String name) throws BadCommandLineException { 1.536 + addFile(name, bindingFiles, null); 1.537 + } 1.538 + 1.539 + /** 1.540 + * Parses a token to a file (or a set of files) 1.541 + * and add them as {@link InputSource} to the specified list. 1.542 + * 1.543 + * @param suffix If the given token is a directory name, we do a recusive search 1.544 + * and find all files that have the given suffix. 1.545 + */ 1.546 + private void addFile(String name, List<InputSource> target, String suffix) throws BadCommandLineException { 1.547 + Object src; 1.548 + try { 1.549 + src = Util.getFileOrURL(name); 1.550 + } catch (IOException e) { 1.551 + throw new BadCommandLineException(WscompileMessages.WSIMPORT_NOT_A_FILE_NOR_URL(name)); 1.552 + } 1.553 + if (src instanceof URL) { 1.554 + target.add(absolutize(new InputSource(Util.escapeSpace(((URL) src).toExternalForm())))); 1.555 + } else { 1.556 + File fsrc = (File) src; 1.557 + if (fsrc.isDirectory()) { 1.558 + addRecursive(fsrc, suffix, target); 1.559 + } else { 1.560 + target.add(absolutize(fileToInputSource(fsrc))); 1.561 + } 1.562 + } 1.563 + } 1.564 + 1.565 + 1.566 + /** 1.567 + * Exposing it as a public method to allow external tools such as NB to read from wsdl model and work on it. 1.568 + * TODO: WSDL model needs to be exposed - basically at tool time we need to use the runtimw wsdl model 1.569 + * 1.570 + * 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 1.571 + * to JAXB in {@link com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder} 1.572 + * 1.573 + * @param receiver {@link ErrorReceiver} 1.574 + */ 1.575 + public final void parseBindings(ErrorReceiver receiver){ 1.576 + for (InputSource is : bindingFiles) { 1.577 + XMLStreamReader reader = 1.578 + XMLStreamReaderFactory.create(is,true); 1.579 + XMLStreamReaderUtil.nextElementContent(reader); 1.580 + if (reader.getName().equals(JAXWSBindingsConstants.JAXWS_BINDINGS)) { 1.581 + jaxwsCustomBindings.add(new RereadInputSource(is)); 1.582 + } else if (reader.getName().equals(JAXWSBindingsConstants.JAXB_BINDINGS) || 1.583 + reader.getName().equals(new QName(SchemaConstants.NS_XSD, "schema"))) { 1.584 + jaxbCustomBindings.add(new RereadInputSource(is)); 1.585 + } else { 1.586 + LocatorImpl locator = new LocatorImpl(); 1.587 + locator.setSystemId(reader.getLocation().getSystemId()); 1.588 + locator.setPublicId(reader.getLocation().getPublicId()); 1.589 + locator.setLineNumber(reader.getLocation().getLineNumber()); 1.590 + locator.setColumnNumber(reader.getLocation().getColumnNumber()); 1.591 + receiver.warning(locator, ConfigurationMessages.CONFIGURATION_NOT_BINDING_FILE(is.getSystemId())); 1.592 + } 1.593 + } 1.594 + } 1.595 + 1.596 + /** 1.597 + * Get extension argument 1.598 + */ 1.599 + public String getExtensionOption(String argument) { 1.600 + return extensionOptions.get(argument); 1.601 + } 1.602 + 1.603 + private void parseProxy(String text) throws BadCommandLineException { 1.604 + int i = text.lastIndexOf('@'); 1.605 + int j = text.lastIndexOf(':'); 1.606 + 1.607 + if (i > 0) { 1.608 + proxyAuth = text.substring(0, i); 1.609 + if (j > i) { 1.610 + proxyHost = text.substring(i + 1, j); 1.611 + proxyPort = text.substring(j + 1); 1.612 + } else { 1.613 + proxyHost = text.substring(i + 1); 1.614 + proxyPort = "8080"; 1.615 + } 1.616 + } else { 1.617 + //no auth info 1.618 + if (j < 0) { 1.619 + //no port 1.620 + proxyHost = text; 1.621 + proxyPort = "8080"; 1.622 + } else { 1.623 + proxyHost = text.substring(0, j); 1.624 + proxyPort = text.substring(j + 1); 1.625 + } 1.626 + } 1.627 + try { 1.628 + Integer.valueOf(proxyPort); 1.629 + } catch (NumberFormatException e) { 1.630 + throw new BadCommandLineException(WscompileMessages.WSIMPORT_ILLEGAL_PROXY(text)); 1.631 + } 1.632 + } 1.633 + 1.634 + /** 1.635 + * Looks for all "META-INF/services/[className]" files and 1.636 + * create one instance for each class name found inside this file. 1.637 + */ 1.638 + private static <T> T[] findServices(Class<T> clazz, ClassLoader classLoader) { 1.639 + ServiceFinder<T> serviceFinder = ServiceFinder.find(clazz, classLoader); 1.640 + List<T> r = new ArrayList<T>(); 1.641 + for (T t : serviceFinder) { 1.642 + r.add(t); 1.643 + } 1.644 + return r.toArray((T[]) Array.newInstance(clazz, r.size())); 1.645 + } 1.646 + 1.647 + private static final class ByteStream extends ByteArrayOutputStream { 1.648 + byte[] getBuffer() { 1.649 + return buf; 1.650 + } 1.651 + } 1.652 + 1.653 + private static final class RereadInputStream extends InputStream { 1.654 + private InputStream is; 1.655 + private ByteStream bs; 1.656 + 1.657 + RereadInputStream(InputStream is) { 1.658 + this.is = is; 1.659 + this.bs = new ByteStream(); 1.660 + } 1.661 + 1.662 + @Override 1.663 + public int available() throws IOException { 1.664 + return is.available(); 1.665 + } 1.666 + 1.667 + @Override 1.668 + public void close() throws IOException { 1.669 + if (bs != null) { 1.670 + InputStream i = new ByteArrayInputStream(bs.getBuffer()); 1.671 + bs = null; 1.672 + is.close(); 1.673 + is = i; 1.674 + } 1.675 + } 1.676 + 1.677 + @Override 1.678 + public synchronized void mark(int readlimit) { 1.679 + is.mark(readlimit); 1.680 + } 1.681 + 1.682 + @Override 1.683 + public boolean markSupported() { 1.684 + return is.markSupported(); 1.685 + } 1.686 + 1.687 + @Override 1.688 + public int read() throws IOException { 1.689 + int r = is.read(); 1.690 + if (bs != null) 1.691 + bs.write(r); 1.692 + return r; 1.693 + } 1.694 + 1.695 + @Override 1.696 + public int read(byte[] b, int off, int len) throws IOException { 1.697 + int r = is.read(b, off, len); 1.698 + if (r > 0 && bs != null) 1.699 + bs.write(b, off, r); 1.700 + return r; 1.701 + } 1.702 + 1.703 + @Override 1.704 + public int read(byte[] b) throws IOException { 1.705 + int r = is.read(b); 1.706 + if (r > 0 && bs != null) 1.707 + bs.write(b, 0, r); 1.708 + return r; 1.709 + } 1.710 + 1.711 + @Override 1.712 + public synchronized void reset() throws IOException { 1.713 + is.reset(); 1.714 + } 1.715 + } 1.716 + 1.717 + private static final class RereadInputSource extends InputSource { 1.718 + private InputSource is; 1.719 + 1.720 + RereadInputSource(InputSource is) { 1.721 + this.is = is; 1.722 + } 1.723 + 1.724 + @Override 1.725 + public InputStream getByteStream() { 1.726 + InputStream i = is.getByteStream(); 1.727 + if (i != null && !(i instanceof RereadInputStream)) { 1.728 + i = new RereadInputStream(i); 1.729 + is.setByteStream(i); 1.730 + } 1.731 + return i; 1.732 + } 1.733 + 1.734 + @Override 1.735 + public Reader getCharacterStream() { 1.736 + // TODO Auto-generated method stub 1.737 + return is.getCharacterStream(); 1.738 + } 1.739 + 1.740 + @Override 1.741 + public String getEncoding() { 1.742 + return is.getEncoding(); 1.743 + } 1.744 + 1.745 + @Override 1.746 + public String getPublicId() { 1.747 + return is.getPublicId(); 1.748 + } 1.749 + 1.750 + @Override 1.751 + public String getSystemId() { 1.752 + return is.getSystemId(); 1.753 + } 1.754 + 1.755 + @Override 1.756 + public void setByteStream(InputStream byteStream) { 1.757 + is.setByteStream(byteStream); 1.758 + } 1.759 + 1.760 + @Override 1.761 + public void setCharacterStream(Reader characterStream) { 1.762 + is.setCharacterStream(characterStream); 1.763 + } 1.764 + 1.765 + @Override 1.766 + public void setEncoding(String encoding) { 1.767 + is.setEncoding(encoding); 1.768 + } 1.769 + 1.770 + @Override 1.771 + public void setPublicId(String publicId) { 1.772 + is.setPublicId(publicId); 1.773 + } 1.774 + 1.775 + @Override 1.776 + public void setSystemId(String systemId) { 1.777 + is.setSystemId(systemId); 1.778 + } 1.779 + } 1.780 + 1.781 + @Override 1.782 + protected void disableXmlSecurity() { 1.783 + super.disableXmlSecurity(); 1.784 + schemaCompiler.getOptions().disableXmlSecurity = true; 1.785 + } 1.786 +}