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