< prev index next >

src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wscompile/WsgenTool.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.wscompile;
  27 
  28 import com.oracle.webservices.internal.api.databinding.WSDLResolver;
  29 import com.sun.istack.internal.tools.ParallelWorldClassLoader;
  30 import com.sun.tools.internal.ws.ToolVersion;
  31 import com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAp;
  32 import com.sun.tools.internal.ws.processor.modeler.wsdl.ConsoleErrorReporter;
  33 import com.sun.tools.internal.ws.resources.WscompileMessages;
  34 import com.sun.tools.internal.xjc.util.NullStream;
  35 import com.sun.xml.internal.txw2.TXW;
  36 import com.sun.xml.internal.txw2.TypedXmlWriter;
  37 import com.sun.xml.internal.txw2.annotation.XmlAttribute;
  38 import com.sun.xml.internal.txw2.annotation.XmlElement;
  39 import com.sun.xml.internal.txw2.output.StreamSerializer;
  40 import com.sun.xml.internal.ws.api.BindingID;
  41 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
  42 import com.sun.xml.internal.ws.api.databinding.DatabindingFactory;
  43 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
  44 import com.sun.xml.internal.ws.api.server.Container;
  45 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension;
  46 import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
  47 import com.sun.xml.internal.ws.model.ExternalMetadataReader;
  48 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
  49 import com.sun.xml.internal.ws.util.ServiceFinder;
  50 import org.xml.sax.SAXParseException;
  51 
  52 import javax.tools.DiagnosticCollector;
  53 import javax.tools.JavaCompiler;
  54 import javax.tools.JavaFileObject;
  55 import javax.tools.StandardJavaFileManager;
  56 import javax.tools.ToolProvider;
  57 import javax.xml.bind.annotation.XmlSeeAlso;
  58 import javax.xml.namespace.QName;
  59 import javax.xml.transform.Result;
  60 import javax.xml.transform.stream.StreamResult;
  61 import javax.xml.ws.EndpointReference;
  62 import javax.xml.ws.Holder;
  63 import java.io.BufferedOutputStream;
  64 import java.io.File;
  65 import java.io.FileNotFoundException;
  66 import java.io.FileOutputStream;
  67 import java.io.IOException;
  68 import java.io.OutputStream;
  69 import java.io.PrintStream;
  70 import java.net.URLClassLoader;
  71 import java.util.ArrayList;
  72 import java.util.Collections;
  73 import java.util.HashMap;
  74 import java.util.List;
  75 import java.util.Map;
  76 
  77 /**
  78  * @author Vivek Pandey
  79  */
  80 
  81 /*


 120             usage(done.getOptions());
 121         } catch (BadCommandLineException e) {
 122             if (e.getMessage() != null) {
 123                 System.out.println(e.getMessage());
 124                 System.out.println();
 125             }
 126             usage(e.getOptions());
 127             return false;
 128         } catch (AbortException e) {
 129             //error might have been reported
 130         } finally {
 131             if (!options.keep) {
 132                 options.removeGeneratedFiles();
 133             }
 134         }
 135         return true;
 136     }
 137 
 138     private final Container container;
 139 
 140     /*
 141      * To take care of JDK6-JDK6u3, where 2.1 API classes are not there
 142      */
 143     private static boolean useBootClasspath(Class clazz) {
 144         try {
 145             ParallelWorldClassLoader.toJarUrl(clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class"));
 146             return true;
 147         } catch (Exception e) {
 148             return false;
 149         }
 150     }
 151 
 152     /**
 153      *
 154      * @param endpoint
 155      * @param listener
 156      * @return
 157      * @throws BadCommandLineException
 158      */
 159     public boolean buildModel(String endpoint, Listener listener) throws BadCommandLineException {
 160         final ErrorReceiverFilter errReceiver = new ErrorReceiverFilter(listener);
 161 
 162         boolean bootCP = useBootClasspath(EndpointReference.class) || useBootClasspath(XmlSeeAlso.class);
 163         List<String> args = new ArrayList<String>(6 + (bootCP ? 1 : 0) + (options.nocompile ? 1 : 0)
 164                 + (options.encoding != null ? 2 : 0));

 165         args.add("--add-modules");
 166         args.add("java.xml.ws");

 167         args.add("-d");
 168         args.add(options.destDir.getAbsolutePath());
 169         args.add("-classpath");
 170         args.add(options.classpath);
 171         args.add("-s");
 172         args.add(options.sourceDir.getAbsolutePath());
 173         if (options.nocompile) {
 174             args.add("-proc:only");
 175         }
 176         if (options.encoding != null) {
 177             args.add("-encoding");
 178             args.add(options.encoding);
 179         }
 180         if (bootCP) {
 181             args.add(new StringBuilder()
 182                     .append("-Xbootclasspath/p:")
 183                     .append(JavaCompilerHelper.getJarFile(EndpointReference.class))
 184                     .append(File.pathSeparator)
 185                     .append(JavaCompilerHelper.getJarFile(XmlSeeAlso.class)).toString());
 186         }
 187         if (options.javacOptions != null) {
 188             args.addAll(options.getJavacOptions(args, listener));
 189         }
 190 
 191         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 192         if (compiler == null) {
 193             out.println(WscompileMessages.WSCOMPILE_CANT_GET_COMPILER(property("java.home"), property("java.version"), property("java.vendor")));
 194             return false;
 195         }
 196         DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
 197         StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
 198         JavaCompiler.CompilationTask task = compiler.getTask(
 199                 null,
 200                 fileManager,
 201                 diagnostics,
 202                 args,
 203                 Collections.singleton(endpoint.replaceAll("\\$", ".")),
 204                 null);
 205         task.setProcessors(Collections.singleton(new WebServiceAp(options, out)));


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.wscompile;
  27 
  28 import com.oracle.webservices.internal.api.databinding.WSDLResolver;

  29 import com.sun.tools.internal.ws.ToolVersion;
  30 import com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAp;
  31 import com.sun.tools.internal.ws.processor.modeler.wsdl.ConsoleErrorReporter;
  32 import com.sun.tools.internal.ws.resources.WscompileMessages;
  33 import com.sun.tools.internal.xjc.util.NullStream;
  34 import com.sun.xml.internal.txw2.TXW;
  35 import com.sun.xml.internal.txw2.TypedXmlWriter;
  36 import com.sun.xml.internal.txw2.annotation.XmlAttribute;
  37 import com.sun.xml.internal.txw2.annotation.XmlElement;
  38 import com.sun.xml.internal.txw2.output.StreamSerializer;
  39 import com.sun.xml.internal.ws.api.BindingID;
  40 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
  41 import com.sun.xml.internal.ws.api.databinding.DatabindingFactory;
  42 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
  43 import com.sun.xml.internal.ws.api.server.Container;
  44 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension;
  45 import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
  46 import com.sun.xml.internal.ws.model.ExternalMetadataReader;
  47 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
  48 import com.sun.xml.internal.ws.util.ServiceFinder;
  49 import org.xml.sax.SAXParseException;
  50 
  51 import javax.tools.DiagnosticCollector;
  52 import javax.tools.JavaCompiler;
  53 import javax.tools.JavaFileObject;
  54 import javax.tools.StandardJavaFileManager;
  55 import javax.tools.ToolProvider;

  56 import javax.xml.namespace.QName;
  57 import javax.xml.transform.Result;
  58 import javax.xml.transform.stream.StreamResult;

  59 import javax.xml.ws.Holder;
  60 import java.io.BufferedOutputStream;
  61 import java.io.File;
  62 import java.io.FileNotFoundException;
  63 import java.io.FileOutputStream;
  64 import java.io.IOException;
  65 import java.io.OutputStream;
  66 import java.io.PrintStream;
  67 import java.net.URLClassLoader;
  68 import java.util.ArrayList;
  69 import java.util.Collections;
  70 import java.util.HashMap;
  71 import java.util.List;
  72 import java.util.Map;
  73 
  74 /**
  75  * @author Vivek Pandey
  76  */
  77 
  78 /*


 117             usage(done.getOptions());
 118         } catch (BadCommandLineException e) {
 119             if (e.getMessage() != null) {
 120                 System.out.println(e.getMessage());
 121                 System.out.println();
 122             }
 123             usage(e.getOptions());
 124             return false;
 125         } catch (AbortException e) {
 126             //error might have been reported
 127         } finally {
 128             if (!options.keep) {
 129                 options.removeGeneratedFiles();
 130             }
 131         }
 132         return true;
 133     }
 134 
 135     private final Container container;
 136 












 137     /**
 138      *
 139      * @param endpoint
 140      * @param listener
 141      * @return
 142      * @throws BadCommandLineException
 143      */
 144     public boolean buildModel(String endpoint, Listener listener) throws BadCommandLineException {
 145         final ErrorReceiverFilter errReceiver = new ErrorReceiverFilter(listener);
 146 
 147         List<String> args = new ArrayList<String>(6 + (options.nocompile ? 1 : 0)

 148                 + (options.encoding != null ? 2 : 0));
 149 
 150         args.add("--add-modules");
 151         args.add("java.xml.ws");
 152 
 153         args.add("-d");
 154         args.add(options.destDir.getAbsolutePath());
 155         args.add("-classpath");
 156         args.add(options.classpath);
 157         args.add("-s");
 158         args.add(options.sourceDir.getAbsolutePath());
 159         if (options.nocompile) {
 160             args.add("-proc:only");
 161         }
 162         if (options.encoding != null) {
 163             args.add("-encoding");
 164             args.add(options.encoding);







 165         }
 166         if (options.javacOptions != null) {
 167             args.addAll(options.getJavacOptions(args, listener));
 168         }
 169 
 170         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 171         if (compiler == null) {
 172             out.println(WscompileMessages.WSCOMPILE_CANT_GET_COMPILER(property("java.home"), property("java.version"), property("java.vendor")));
 173             return false;
 174         }
 175         DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
 176         StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
 177         JavaCompiler.CompilationTask task = compiler.getTask(
 178                 null,
 179                 fileManager,
 180                 diagnostics,
 181                 args,
 182                 Collections.singleton(endpoint.replaceAll("\\$", ".")),
 183                 null);
 184         task.setProcessors(Collections.singleton(new WebServiceAp(options, out)));


< prev index next >