Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
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.CodeWriter; |
ohair@286 | 29 | import com.sun.codemodel.internal.writer.ProgressCodeWriter; |
alanb@368 | 30 | import com.sun.istack.internal.tools.DefaultAuthenticator; |
ohair@286 | 31 | import com.sun.tools.internal.ws.ToolVersion; |
ohair@286 | 32 | import com.sun.tools.internal.ws.api.TJavaGeneratorExtension; |
ohair@286 | 33 | import com.sun.tools.internal.ws.processor.generator.CustomExceptionGenerator; |
ohair@286 | 34 | import com.sun.tools.internal.ws.processor.generator.GeneratorBase; |
ohair@286 | 35 | import com.sun.tools.internal.ws.processor.generator.SeiGenerator; |
ohair@286 | 36 | import com.sun.tools.internal.ws.processor.generator.ServiceGenerator; |
ohair@286 | 37 | import com.sun.tools.internal.ws.processor.generator.JwsImplGenerator; |
ohair@286 | 38 | import com.sun.tools.internal.ws.processor.model.Model; |
ohair@286 | 39 | import com.sun.tools.internal.ws.processor.modeler.wsdl.ConsoleErrorReporter; |
ohair@286 | 40 | import com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler; |
ohair@286 | 41 | import com.sun.tools.internal.ws.processor.util.DirectoryUtil; |
ohair@286 | 42 | import com.sun.tools.internal.ws.resources.WscompileMessages; |
ohair@286 | 43 | import com.sun.tools.internal.ws.resources.WsdlMessages; |
ohair@286 | 44 | import com.sun.tools.internal.ws.util.WSDLFetcher; |
ohair@286 | 45 | import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder; |
ohair@286 | 46 | import com.sun.tools.internal.ws.wsdl.parser.WSDLInternalizationLogic; |
ohair@286 | 47 | import com.sun.tools.internal.xjc.util.NullStream; |
ohair@286 | 48 | import com.sun.xml.internal.ws.api.server.Container; |
ohair@286 | 49 | import com.sun.xml.internal.ws.util.ServiceFinder; |
ohair@286 | 50 | import com.sun.istack.internal.tools.ParallelWorldClassLoader; |
ohair@286 | 51 | import org.xml.sax.EntityResolver; |
ohair@286 | 52 | import org.xml.sax.SAXParseException; |
ohair@286 | 53 | |
ohair@286 | 54 | import javax.xml.bind.JAXBPermission; |
ohair@286 | 55 | import javax.xml.stream.*; |
ohair@286 | 56 | import javax.xml.ws.EndpointContext; |
ohair@286 | 57 | import java.io.*; |
ohair@286 | 58 | import java.util.*; |
alanb@368 | 59 | import java.text.MessageFormat; |
ohair@286 | 60 | import java.util.jar.JarEntry; |
ohair@286 | 61 | import java.util.jar.JarOutputStream; |
alanb@368 | 62 | import org.xml.sax.Locator; |
ohair@286 | 63 | import org.xml.sax.SAXException; |
ohair@286 | 64 | |
ohair@286 | 65 | /** |
ohair@286 | 66 | * @author Vivek Pandey |
ohair@286 | 67 | */ |
ohair@286 | 68 | public class WsimportTool { |
ohair@286 | 69 | private static final String WSIMPORT = "wsimport"; |
ohair@286 | 70 | private final PrintStream out; |
ohair@286 | 71 | private final Container container; |
ohair@286 | 72 | |
ohair@286 | 73 | /** |
ohair@286 | 74 | * Wsimport specific options |
ohair@286 | 75 | */ |
ohair@286 | 76 | protected WsimportOptions options = new WsimportOptions(); |
ohair@286 | 77 | |
ohair@286 | 78 | public WsimportTool(OutputStream out) { |
ohair@286 | 79 | this(out, null); |
ohair@286 | 80 | } |
ohair@286 | 81 | |
ohair@286 | 82 | public WsimportTool(OutputStream logStream, Container container) { |
ohair@286 | 83 | this.out = (logStream instanceof PrintStream)?(PrintStream)logStream:new PrintStream(logStream); |
ohair@286 | 84 | this.container = container; |
ohair@286 | 85 | } |
ohair@286 | 86 | |
ohair@286 | 87 | protected class Listener extends WsimportListener { |
ohair@286 | 88 | ConsoleErrorReporter cer = new ConsoleErrorReporter(out == null ? new PrintStream(new NullStream()) : out); |
ohair@286 | 89 | |
ohair@286 | 90 | @Override |
ohair@286 | 91 | public void generatedFile(String fileName) { |
ohair@286 | 92 | message(fileName); |
ohair@286 | 93 | } |
ohair@286 | 94 | |
ohair@286 | 95 | @Override |
ohair@286 | 96 | public void message(String msg) { |
ohair@286 | 97 | out.println(msg); |
ohair@286 | 98 | } |
ohair@286 | 99 | |
ohair@286 | 100 | @Override |
ohair@286 | 101 | public void error(SAXParseException exception) { |
ohair@286 | 102 | cer.error(exception); |
ohair@286 | 103 | } |
ohair@286 | 104 | |
ohair@286 | 105 | @Override |
ohair@286 | 106 | public void fatalError(SAXParseException exception) { |
ohair@286 | 107 | cer.fatalError(exception); |
ohair@286 | 108 | } |
ohair@286 | 109 | |
ohair@286 | 110 | @Override |
ohair@286 | 111 | public void warning(SAXParseException exception) { |
ohair@286 | 112 | cer.warning(exception); |
ohair@286 | 113 | } |
ohair@286 | 114 | |
ohair@286 | 115 | @Override |
ohair@286 | 116 | public void debug(SAXParseException exception) { |
ohair@286 | 117 | cer.debug(exception); |
ohair@286 | 118 | } |
ohair@286 | 119 | |
ohair@286 | 120 | @Override |
ohair@286 | 121 | public void info(SAXParseException exception) { |
ohair@286 | 122 | cer.info(exception); |
ohair@286 | 123 | } |
ohair@286 | 124 | |
ohair@286 | 125 | public void enableDebugging(){ |
ohair@286 | 126 | cer.enableDebugging(); |
ohair@286 | 127 | } |
ohair@286 | 128 | } |
ohair@286 | 129 | |
ohair@286 | 130 | protected class Receiver extends ErrorReceiverFilter { |
ohair@286 | 131 | |
ohair@286 | 132 | private Listener listener; |
ohair@286 | 133 | |
ohair@286 | 134 | public Receiver(Listener listener) { |
ohair@286 | 135 | super(listener); |
ohair@286 | 136 | this.listener = listener; |
ohair@286 | 137 | } |
ohair@286 | 138 | |
alanb@368 | 139 | @Override |
ohair@286 | 140 | public void info(SAXParseException exception) { |
ohair@286 | 141 | if (options.verbose) |
ohair@286 | 142 | super.info(exception); |
ohair@286 | 143 | } |
ohair@286 | 144 | |
alanb@368 | 145 | @Override |
ohair@286 | 146 | public void warning(SAXParseException exception) { |
ohair@286 | 147 | if (!options.quiet) |
ohair@286 | 148 | super.warning(exception); |
ohair@286 | 149 | } |
ohair@286 | 150 | |
ohair@286 | 151 | @Override |
ohair@286 | 152 | public void pollAbort() throws AbortException { |
ohair@286 | 153 | if (listener.isCanceled()) |
ohair@286 | 154 | throw new AbortException(); |
ohair@286 | 155 | } |
ohair@286 | 156 | |
ohair@286 | 157 | @Override |
ohair@286 | 158 | public void debug(SAXParseException exception){ |
ohair@286 | 159 | if(options.debugMode){ |
ohair@286 | 160 | listener.debug(exception); |
ohair@286 | 161 | } |
ohair@286 | 162 | } |
ohair@286 | 163 | } |
ohair@286 | 164 | |
ohair@286 | 165 | public boolean run(String[] args) { |
ohair@286 | 166 | Listener listener = new Listener(); |
ohair@286 | 167 | Receiver receiver = new Receiver(listener); |
ohair@286 | 168 | return run(args, listener, receiver); |
ohair@286 | 169 | } |
ohair@286 | 170 | |
ohair@286 | 171 | protected boolean run(String[] args, Listener listener, |
ohair@286 | 172 | Receiver receiver) { |
ohair@286 | 173 | for (String arg : args) { |
ohair@286 | 174 | if (arg.equals("-version")) { |
ohair@286 | 175 | listener.message( |
ohair@286 | 176 | WscompileMessages.WSIMPORT_VERSION(ToolVersion.VERSION.MAJOR_VERSION)); |
ohair@286 | 177 | return true; |
ohair@286 | 178 | } |
ohair@286 | 179 | if (arg.equals("-fullversion")) { |
ohair@286 | 180 | listener.message( |
ohair@286 | 181 | WscompileMessages.WSIMPORT_FULLVERSION(ToolVersion.VERSION.toString())); |
ohair@286 | 182 | return true; |
ohair@286 | 183 | } |
ohair@286 | 184 | } |
ohair@286 | 185 | |
ohair@286 | 186 | try { |
ohair@286 | 187 | parseArguments(args, listener, receiver); |
ohair@286 | 188 | |
ohair@286 | 189 | try { |
ohair@286 | 190 | Model wsdlModel = buildWsdlModel(listener, receiver); |
ohair@286 | 191 | if (wsdlModel == null) |
ohair@286 | 192 | return false; |
ohair@286 | 193 | |
ohair@286 | 194 | if (!generateCode(listener, receiver, wsdlModel, true)) |
ohair@286 | 195 | return false; |
ohair@286 | 196 | |
ohair@286 | 197 | /* Not so fast! |
ohair@286 | 198 | } catch(AbortException e){ |
ohair@286 | 199 | //error might have been reported |
ohair@286 | 200 | * |
ohair@286 | 201 | */ |
ohair@286 | 202 | }catch (IOException e) { |
ohair@286 | 203 | receiver.error(e); |
ohair@286 | 204 | return false; |
ohair@286 | 205 | }catch (XMLStreamException e) { |
ohair@286 | 206 | receiver.error(e); |
ohair@286 | 207 | return false; |
ohair@286 | 208 | } |
ohair@286 | 209 | if (!options.nocompile){ |
ohair@286 | 210 | if(!compileGeneratedClasses(receiver, listener)){ |
ohair@286 | 211 | listener.message(WscompileMessages.WSCOMPILE_COMPILATION_FAILED()); |
ohair@286 | 212 | return false; |
ohair@286 | 213 | } |
ohair@286 | 214 | } |
ohair@286 | 215 | try { |
ohair@286 | 216 | if (options.clientjar != null) { |
ohair@286 | 217 | //add all the generated class files to the list of generated files |
ohair@286 | 218 | addClassesToGeneratedFiles(); |
ohair@286 | 219 | jarArtifacts(listener); |
ohair@286 | 220 | |
ohair@286 | 221 | } |
ohair@286 | 222 | } catch (IOException e) { |
ohair@286 | 223 | receiver.error(e); |
ohair@286 | 224 | return false; |
ohair@286 | 225 | } |
ohair@286 | 226 | |
ohair@286 | 227 | } catch (Options.WeAreDone done) { |
ohair@286 | 228 | usage(done.getOptions()); |
ohair@286 | 229 | } catch (BadCommandLineException e) { |
ohair@286 | 230 | if (e.getMessage() != null) { |
ohair@286 | 231 | System.out.println(e.getMessage()); |
ohair@286 | 232 | System.out.println(); |
ohair@286 | 233 | } |
ohair@286 | 234 | usage(e.getOptions()); |
ohair@286 | 235 | return false; |
ohair@286 | 236 | } finally{ |
ohair@286 | 237 | deleteGeneratedFiles(); |
ohair@286 | 238 | if (!options.disableAuthenticator) { |
alanb@368 | 239 | DefaultAuthenticator.reset(); |
ohair@286 | 240 | } |
ohair@286 | 241 | } |
ohair@286 | 242 | if(receiver.hadError()) { |
ohair@286 | 243 | return false; |
ohair@286 | 244 | } |
ohair@286 | 245 | return true; |
ohair@286 | 246 | } |
ohair@286 | 247 | |
ohair@286 | 248 | private void deleteGeneratedFiles() { |
ohair@286 | 249 | Set<File> trackedRootPackages = new HashSet<File>(); |
ohair@286 | 250 | |
ohair@286 | 251 | if (options.clientjar != null) { |
ohair@286 | 252 | //remove all non-java artifacts as they will packaged in jar. |
ohair@286 | 253 | Iterable<File> generatedFiles = options.getGeneratedFiles(); |
ohair@286 | 254 | synchronized (generatedFiles) { |
ohair@286 | 255 | for (File file : generatedFiles) { |
ohair@286 | 256 | if (!file.getName().endsWith(".java")) { |
alanb@368 | 257 | boolean deleted = file.delete(); |
alanb@368 | 258 | if (options.verbose && !deleted) { |
alanb@368 | 259 | System.out.println(MessageFormat.format("{0} could not be deleted.", file)); |
alanb@368 | 260 | } |
ohair@286 | 261 | trackedRootPackages.add(file.getParentFile()); |
ohair@286 | 262 | } |
ohair@286 | 263 | } |
ohair@286 | 264 | } |
ohair@286 | 265 | //remove empty package dirs |
ohair@286 | 266 | for(File pkg:trackedRootPackages) { |
ohair@286 | 267 | |
ohair@286 | 268 | while(pkg.list() != null && pkg.list().length ==0 && !pkg.equals(options.destDir)) { |
ohair@286 | 269 | File parentPkg = pkg.getParentFile(); |
alanb@368 | 270 | boolean deleted = pkg.delete(); |
alanb@368 | 271 | if (options.verbose && !deleted) { |
alanb@368 | 272 | System.out.println(MessageFormat.format("{0} could not be deleted.", pkg)); |
alanb@368 | 273 | } |
ohair@286 | 274 | pkg = parentPkg; |
ohair@286 | 275 | } |
ohair@286 | 276 | } |
ohair@286 | 277 | } |
ohair@286 | 278 | if(!options.keep) { |
ohair@286 | 279 | options.removeGeneratedFiles(); |
ohair@286 | 280 | } |
ohair@286 | 281 | } |
ohair@286 | 282 | |
ohair@286 | 283 | private void addClassesToGeneratedFiles() throws IOException { |
ohair@286 | 284 | Iterable<File> generatedFiles = options.getGeneratedFiles(); |
ohair@286 | 285 | final List<File> trackedClassFiles = new ArrayList<File>(); |
ohair@286 | 286 | for(File f: generatedFiles) { |
ohair@286 | 287 | if(f.getName().endsWith(".java")) { |
ohair@286 | 288 | String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir); |
ohair@286 | 289 | final String className = f.getName().substring(0,f.getName().indexOf(".java")); |
ohair@286 | 290 | File classDir = new File(options.destDir,relativeDir); |
ohair@286 | 291 | if(classDir.exists()) { |
ohair@286 | 292 | classDir.listFiles(new FilenameFilter() { |
alanb@368 | 293 | @Override |
ohair@286 | 294 | public boolean accept(File dir, String name) { |
ohair@286 | 295 | if(name.equals(className+".class") || (name.startsWith(className+"$") && name.endsWith(".class"))) { |
ohair@286 | 296 | trackedClassFiles.add(new File(dir,name)); |
ohair@286 | 297 | return true; |
ohair@286 | 298 | } |
ohair@286 | 299 | return false; |
ohair@286 | 300 | } |
ohair@286 | 301 | }); |
ohair@286 | 302 | } |
ohair@286 | 303 | } |
ohair@286 | 304 | } |
ohair@286 | 305 | for(File f: trackedClassFiles) { |
ohair@286 | 306 | options.addGeneratedFile(f); |
ohair@286 | 307 | } |
ohair@286 | 308 | } |
ohair@286 | 309 | |
ohair@286 | 310 | private void jarArtifacts(WsimportListener listener) throws IOException { |
ohair@286 | 311 | File zipFile = new File(options.clientjar); |
ohair@286 | 312 | if(!zipFile.isAbsolute()) { |
ohair@286 | 313 | zipFile = new File(options.destDir, options.clientjar); |
ohair@286 | 314 | } |
ohair@286 | 315 | |
alanb@368 | 316 | FileOutputStream fos; |
alanb@368 | 317 | if (!options.quiet) { |
alanb@368 | 318 | listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile)); |
ohair@286 | 319 | } |
ohair@286 | 320 | |
alanb@368 | 321 | BufferedInputStream bis = null; |
alanb@368 | 322 | FileInputStream fi = null; |
ohair@286 | 323 | fos = new FileOutputStream(zipFile); |
ohair@286 | 324 | JarOutputStream jos = new JarOutputStream(fos); |
alanb@368 | 325 | try { |
alanb@368 | 326 | String base = options.destDir.getCanonicalPath(); |
alanb@368 | 327 | for(File f: options.getGeneratedFiles()) { |
alanb@368 | 328 | //exclude packaging the java files in the jar |
alanb@368 | 329 | if(f.getName().endsWith(".java")) { |
alanb@368 | 330 | continue; |
alanb@368 | 331 | } |
alanb@368 | 332 | if(options.verbose) { |
alanb@368 | 333 | listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar)); |
alanb@368 | 334 | } |
alanb@368 | 335 | String entry = f.getCanonicalPath().substring(base.length()+1); |
alanb@368 | 336 | fi = new FileInputStream(f); |
alanb@368 | 337 | bis = new BufferedInputStream(fi); |
alanb@368 | 338 | JarEntry jarEntry = new JarEntry(entry); |
alanb@368 | 339 | jos.putNextEntry(jarEntry); |
alanb@368 | 340 | int bytesRead; |
alanb@368 | 341 | byte[] buffer = new byte[1024]; |
alanb@368 | 342 | while ((bytesRead = bis.read(buffer)) != -1) { |
alanb@368 | 343 | jos.write(buffer, 0, bytesRead); |
alanb@368 | 344 | } |
ohair@286 | 345 | } |
alanb@368 | 346 | } finally { |
alanb@368 | 347 | try { |
alanb@368 | 348 | if (bis != null) { |
alanb@368 | 349 | bis.close(); |
alanb@368 | 350 | } |
alanb@368 | 351 | } finally { |
alanb@368 | 352 | if (jos != null) { |
alanb@368 | 353 | jos.close(); |
alanb@368 | 354 | } |
alanb@368 | 355 | if (fi != null) { |
alanb@368 | 356 | fi.close(); |
alanb@368 | 357 | } |
ohair@286 | 358 | } |
ohair@286 | 359 | } |
ohair@286 | 360 | } |
ohair@286 | 361 | |
ohair@286 | 362 | protected void parseArguments(String[] args, Listener listener, |
ohair@286 | 363 | Receiver receiver) throws BadCommandLineException { |
ohair@286 | 364 | options.parseArguments(args); |
ohair@286 | 365 | options.validate(); |
ohair@286 | 366 | if (options.debugMode) |
ohair@286 | 367 | listener.enableDebugging(); |
ohair@286 | 368 | options.parseBindings(receiver); |
ohair@286 | 369 | } |
ohair@286 | 370 | |
alanb@368 | 371 | protected Model buildWsdlModel(Listener listener, final Receiver receiver) |
alanb@368 | 372 | throws BadCommandLineException, XMLStreamException, IOException { |
ohair@286 | 373 | //set auth info |
ohair@286 | 374 | //if(options.authFile != null) |
ohair@286 | 375 | if (!options.disableAuthenticator) { |
alanb@368 | 376 | class AuthListener implements DefaultAuthenticator.Receiver { |
alanb@368 | 377 | |
alanb@368 | 378 | private final boolean isFatal; |
alanb@368 | 379 | |
alanb@368 | 380 | AuthListener(boolean isFatal) { |
alanb@368 | 381 | this.isFatal = isFatal; |
alanb@368 | 382 | } |
alanb@368 | 383 | |
alanb@368 | 384 | @Override |
alanb@368 | 385 | public void onParsingError(String text, Locator loc) { |
alanb@368 | 386 | error(new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(text), loc)); |
alanb@368 | 387 | } |
alanb@368 | 388 | |
alanb@368 | 389 | @Override |
alanb@368 | 390 | public void onError(Exception e, Locator loc) { |
alanb@368 | 391 | if (e instanceof FileNotFoundException) { |
alanb@368 | 392 | error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND( |
alanb@368 | 393 | loc.getSystemId(), WsimportOptions.defaultAuthfile), null)); |
alanb@368 | 394 | } else { |
alanb@368 | 395 | error(new SAXParseException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(loc.getSystemId(),e.getMessage()), loc)); |
alanb@368 | 396 | } |
alanb@368 | 397 | } |
alanb@368 | 398 | |
alanb@368 | 399 | private void error(SAXParseException e) { |
alanb@368 | 400 | if (isFatal) { |
alanb@368 | 401 | receiver.error(e); |
alanb@368 | 402 | } else { |
alanb@368 | 403 | receiver.debug(e); |
alanb@368 | 404 | } |
alanb@368 | 405 | } |
alanb@368 | 406 | } |
alanb@368 | 407 | |
alanb@368 | 408 | DefaultAuthenticator da = DefaultAuthenticator.getAuthenticator(); |
alanb@368 | 409 | if (options.proxyAuth != null) { |
alanb@368 | 410 | da.setProxyAuth(options.proxyAuth); |
alanb@368 | 411 | } |
alanb@368 | 412 | if (options.authFile != null) { |
alanb@368 | 413 | da.setAuth(options.authFile, new AuthListener(true)); |
alanb@368 | 414 | } else { |
alanb@368 | 415 | da.setAuth(new File(WsimportOptions.defaultAuthfile), new AuthListener(false)); |
alanb@368 | 416 | } |
alanb@368 | 417 | } |
alanb@368 | 418 | |
alanb@368 | 419 | if (!options.quiet) { |
alanb@368 | 420 | listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL()); |
ohair@286 | 421 | } |
ohair@286 | 422 | |
ohair@286 | 423 | MetadataFinder forest = new MetadataFinder(new WSDLInternalizationLogic(), options, receiver); |
ohair@286 | 424 | forest.parseWSDL(); |
ohair@286 | 425 | if (forest.isMexMetadata) |
ohair@286 | 426 | receiver.reset(); |
ohair@286 | 427 | |
ohair@286 | 428 | WSDLModeler wsdlModeler = new WSDLModeler(options, receiver,forest); |
ohair@286 | 429 | Model wsdlModel = wsdlModeler.buildModel(); |
ohair@286 | 430 | if (wsdlModel == null) { |
ohair@286 | 431 | listener.message(WsdlMessages.PARSING_PARSE_FAILED()); |
ohair@286 | 432 | } |
ohair@286 | 433 | |
ohair@286 | 434 | if(options.clientjar != null) { |
ohair@286 | 435 | if( !options.quiet ) |
ohair@286 | 436 | listener.message(WscompileMessages.WSIMPORT_FETCHING_METADATA()); |
ohair@286 | 437 | options.wsdlLocation = new WSDLFetcher(options,listener).fetchWsdls(forest); |
ohair@286 | 438 | } |
ohair@286 | 439 | |
ohair@286 | 440 | return wsdlModel; |
ohair@286 | 441 | } |
ohair@286 | 442 | |
ohair@286 | 443 | protected boolean generateCode(Listener listener, Receiver receiver, |
ohair@286 | 444 | Model wsdlModel, boolean generateService) |
ohair@286 | 445 | throws IOException { |
ohair@286 | 446 | //generated code |
ohair@286 | 447 | if( !options.quiet ) |
ohair@286 | 448 | listener.message(WscompileMessages.WSIMPORT_GENERATING_CODE()); |
ohair@286 | 449 | |
ohair@286 | 450 | TJavaGeneratorExtension[] genExtn = ServiceFinder.find(TJavaGeneratorExtension.class).toArray(); |
ohair@286 | 451 | CustomExceptionGenerator.generate(wsdlModel, options, receiver); |
ohair@286 | 452 | SeiGenerator.generate(wsdlModel, options, receiver, genExtn); |
ohair@286 | 453 | if(receiver.hadError()){ |
ohair@286 | 454 | throw new AbortException(); |
ohair@286 | 455 | } |
ohair@286 | 456 | if (generateService) |
ohair@286 | 457 | { |
ohair@286 | 458 | ServiceGenerator.generate(wsdlModel, options, receiver); |
ohair@286 | 459 | } |
ohair@286 | 460 | for (GeneratorBase g : ServiceFinder.find(GeneratorBase.class)) { |
ohair@286 | 461 | g.init(wsdlModel, options, receiver); |
ohair@286 | 462 | g.doGeneration(); |
ohair@286 | 463 | } |
ohair@286 | 464 | |
ohair@286 | 465 | List<String> implFiles = null; |
ohair@286 | 466 | if (options.isGenerateJWS) { |
ohair@286 | 467 | implFiles = JwsImplGenerator.generate(wsdlModel, options, receiver); |
ohair@286 | 468 | } |
ohair@286 | 469 | |
ohair@286 | 470 | for (Plugin plugin: options.activePlugins) { |
ohair@286 | 471 | try { |
ohair@286 | 472 | plugin.run(wsdlModel, options, receiver); |
ohair@286 | 473 | } catch (SAXException sex) { |
ohair@286 | 474 | // fatal error. error should have been reported |
ohair@286 | 475 | return false; |
ohair@286 | 476 | } |
ohair@286 | 477 | } |
ohair@286 | 478 | |
ohair@286 | 479 | CodeWriter cw; |
ohair@286 | 480 | if (options.filer != null) { |
ohair@286 | 481 | cw = new FilerCodeWriter(options.sourceDir, options); |
ohair@286 | 482 | } else { |
ohair@286 | 483 | cw = new WSCodeWriter(options.sourceDir, options); |
ohair@286 | 484 | } |
ohair@286 | 485 | |
ohair@286 | 486 | if (options.verbose) |
ohair@286 | 487 | cw = new ProgressCodeWriter(cw, out); |
ohair@286 | 488 | options.getCodeModel().build(cw); |
ohair@286 | 489 | |
ohair@286 | 490 | if (options.isGenerateJWS) { |
ohair@286 | 491 | //move Impl files to implDestDir |
ohair@286 | 492 | return JwsImplGenerator.moveToImplDestDir(implFiles, options, receiver); |
ohair@286 | 493 | } |
ohair@286 | 494 | |
ohair@286 | 495 | return true; |
ohair@286 | 496 | } |
ohair@286 | 497 | |
ohair@286 | 498 | public void setEntityResolver(EntityResolver resolver){ |
ohair@286 | 499 | this.options.entityResolver = resolver; |
ohair@286 | 500 | } |
ohair@286 | 501 | |
ohair@286 | 502 | /* |
ohair@286 | 503 | * To take care of JDK6-JDK6u3, where 2.1 API classes are not there |
ohair@286 | 504 | */ |
ohair@286 | 505 | private static boolean useBootClasspath(Class clazz) { |
ohair@286 | 506 | try { |
ohair@286 | 507 | ParallelWorldClassLoader.toJarUrl(clazz.getResource('/'+clazz.getName().replace('.','/')+".class")); |
ohair@286 | 508 | return true; |
ohair@286 | 509 | } catch(Exception e) { |
ohair@286 | 510 | return false; |
ohair@286 | 511 | } |
ohair@286 | 512 | } |
ohair@286 | 513 | |
ohair@286 | 514 | protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){ |
ohair@286 | 515 | List<String> sourceFiles = new ArrayList<String>(); |
ohair@286 | 516 | |
ohair@286 | 517 | for (File f : options.getGeneratedFiles()) { |
ohair@286 | 518 | if (f.exists() && f.getName().endsWith(".java")) { |
ohair@286 | 519 | sourceFiles.add(f.getAbsolutePath()); |
ohair@286 | 520 | } |
ohair@286 | 521 | } |
ohair@286 | 522 | |
ohair@286 | 523 | if (sourceFiles.size() > 0) { |
ohair@286 | 524 | String classDir = options.destDir.getAbsolutePath(); |
ohair@286 | 525 | String classpathString = createClasspathString(); |
ohair@286 | 526 | boolean bootCP = useBootClasspath(EndpointContext.class) || useBootClasspath(JAXBPermission.class); |
ohair@286 | 527 | String[] args = new String[4 + (bootCP ? 1 : 0) + (options.debug ? 1 : 0) |
ohair@286 | 528 | + (options.encoding != null ? 2 : 0) + sourceFiles.size()]; |
ohair@286 | 529 | args[0] = "-d"; |
ohair@286 | 530 | args[1] = classDir; |
ohair@286 | 531 | args[2] = "-classpath"; |
ohair@286 | 532 | args[3] = classpathString; |
ohair@286 | 533 | int baseIndex = 4; |
ohair@286 | 534 | //javac is not working in osgi as the url starts with a bundle |
ohair@286 | 535 | if (bootCP) { |
ohair@286 | 536 | args[baseIndex++] = "-Xbootclasspath/p:"+JavaCompilerHelper.getJarFile(EndpointContext.class)+File.pathSeparator+JavaCompilerHelper.getJarFile(JAXBPermission.class); |
ohair@286 | 537 | } |
ohair@286 | 538 | |
ohair@286 | 539 | if (options.debug) { |
ohair@286 | 540 | args[baseIndex++] = "-g"; |
ohair@286 | 541 | } |
ohair@286 | 542 | |
ohair@286 | 543 | if (options.encoding != null) { |
ohair@286 | 544 | args[baseIndex++] = "-encoding"; |
ohair@286 | 545 | args[baseIndex++] = options.encoding; |
ohair@286 | 546 | } |
ohair@286 | 547 | |
ohair@286 | 548 | for (int i = 0; i < sourceFiles.size(); ++i) { |
ohair@286 | 549 | args[baseIndex + i] = sourceFiles.get(i); |
ohair@286 | 550 | } |
ohair@286 | 551 | |
ohair@286 | 552 | listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE()); |
ohair@286 | 553 | if(options.verbose){ |
alanb@368 | 554 | StringBuilder argstr = new StringBuilder(); |
ohair@286 | 555 | for(String arg:args){ |
ohair@286 | 556 | argstr.append(arg).append(" "); |
ohair@286 | 557 | } |
ohair@286 | 558 | listener.message("javac "+ argstr.toString()); |
ohair@286 | 559 | } |
ohair@286 | 560 | |
ohair@286 | 561 | return JavaCompilerHelper.compile(args, out, receiver); |
ohair@286 | 562 | } |
ohair@286 | 563 | //there are no files to compile, so return true? |
ohair@286 | 564 | return true; |
ohair@286 | 565 | } |
ohair@286 | 566 | |
ohair@286 | 567 | private String createClasspathString() { |
ohair@286 | 568 | StringBuilder classpathStr = new StringBuilder(System.getProperty("java.class.path")); |
ohair@286 | 569 | for(String s: options.cmdlineJars) { |
ohair@286 | 570 | classpathStr.append(File.pathSeparator); |
ohair@286 | 571 | classpathStr.append(new File(s).toString()); |
ohair@286 | 572 | } |
ohair@286 | 573 | return classpathStr.toString(); |
ohair@286 | 574 | } |
ohair@286 | 575 | |
ohair@286 | 576 | protected void usage(Options options) { |
ohair@286 | 577 | System.out.println(WscompileMessages.WSIMPORT_HELP(WSIMPORT)); |
ohair@286 | 578 | System.out.println(WscompileMessages.WSIMPORT_USAGE_EXTENSIONS()); |
ohair@286 | 579 | System.out.println(WscompileMessages.WSIMPORT_USAGE_EXAMPLES()); |
ohair@286 | 580 | } |
ohair@286 | 581 | } |