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