< prev index next >

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

Print this page




  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.Collection;
  73 import java.util.Collections;
  74 import java.util.HashMap;
  75 import java.util.List;
  76 import java.util.Map;
  77 
  78 /**
  79  * @author Vivek Pandey
  80  */
  81 
  82 /*
  83  * All annotation types are supported.
  84  */
  85 public class WsgenTool {
  86     private final PrintStream out;
  87     private final WsgenOptions options = new WsgenOptions();
  88 
  89 
  90     public WsgenTool(OutputStream out, Container container) {
  91         this.out = (out instanceof PrintStream) ? (PrintStream) out : new PrintStream(out);
  92         this.container = container;


 170         args.add("-s");
 171         args.add(options.sourceDir.getAbsolutePath());
 172         if (options.nocompile) {
 173             args.add("-proc:only");
 174         }
 175         if (options.encoding != null) {
 176             args.add("-encoding");
 177             args.add(options.encoding);
 178         }
 179         if (bootCP) {
 180             args.add(new StringBuilder()
 181                     .append("-Xbootclasspath/p:")
 182                     .append(JavaCompilerHelper.getJarFile(EndpointReference.class))
 183                     .append(File.pathSeparator)
 184                     .append(JavaCompilerHelper.getJarFile(XmlSeeAlso.class)).toString());
 185         }
 186         if (options.javacOptions != null) {
 187             args.addAll(options.getJavacOptions(args, listener));
 188         }
 189 
 190         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();//        compiler = JavacTool.create();




 191         DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
 192         StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
 193         JavaCompiler.CompilationTask task = compiler.getTask(
 194                 null,
 195                 fileManager,
 196                 diagnostics,
 197                 args,
 198                 Collections.singleton(endpoint.replaceAll("\\$", ".")),
 199                 null);
 200         task.setProcessors(Collections.singleton(new WebServiceAp(options, out)));
 201         boolean result = task.call();
 202 
 203         if (!result) {
 204             out.println(WscompileMessages.WSCOMPILE_ERROR(WscompileMessages.WSCOMPILE_COMPILATION_FAILED()));
 205             return false;
 206         }
 207         if (options.genWsdl) {
 208             DatabindingConfig config = new DatabindingConfig();
 209 
 210             List<String> externalMetadataFileNames = options.externalMetadataFiles;


 288 
 289                         @Override
 290                         public Result getSchemaOutput(String namespace, Holder<String> filename) {
 291                             return getSchemaOutput(namespace, filename.value);
 292                         }
 293                         // TODO pass correct impl's class name
 294                     });
 295 
 296             wsdlGenInfo.setContainer(container);
 297             wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
 298             wsdlGenInfo.setInlineSchemas(options.inlineSchemas);
 299             rt.generateWSDL(wsdlGenInfo);
 300 
 301 
 302             if (options.wsgenReport != null)
 303                 generateWsgenReport(endpointClass, (AbstractSEIModelImpl) rt.getModel(), wsdlFileName[0], schemaFiles);
 304         }
 305         return true;
 306     }
 307 









 308     private List<File> getExternalFiles(List<String> exts) {
 309         List<File> files = new ArrayList<File>();
 310         for (String ext : exts) {
 311             // first try absolute path ...
 312             File file = new File(ext);
 313             if (!file.exists()) {
 314                 // then relative path ...
 315                 file = new File(options.sourceDir.getAbsolutePath() + File.separator + ext);
 316             }
 317             files.add(file);
 318         }
 319         return files;
 320     }
 321 
 322     /**
 323      * Generates a small XML file that captures the key activity of wsgen,
 324      * so that test harness can pick up artifacts.
 325      */
 326     private void generateWsgenReport(Class<?> endpointClass, AbstractSEIModelImpl rtModel, File wsdlFile, Map<String, File> schemaFiles) {
 327         try {




  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 /*
  82  * All annotation types are supported.
  83  */
  84 public class WsgenTool {
  85     private final PrintStream out;
  86     private final WsgenOptions options = new WsgenOptions();
  87 
  88 
  89     public WsgenTool(OutputStream out, Container container) {
  90         this.out = (out instanceof PrintStream) ? (PrintStream) out : new PrintStream(out);
  91         this.container = container;


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


 291 
 292                         @Override
 293                         public Result getSchemaOutput(String namespace, Holder<String> filename) {
 294                             return getSchemaOutput(namespace, filename.value);
 295                         }
 296                         // TODO pass correct impl's class name
 297                     });
 298 
 299             wsdlGenInfo.setContainer(container);
 300             wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
 301             wsdlGenInfo.setInlineSchemas(options.inlineSchemas);
 302             rt.generateWSDL(wsdlGenInfo);
 303 
 304 
 305             if (options.wsgenReport != null)
 306                 generateWsgenReport(endpointClass, (AbstractSEIModelImpl) rt.getModel(), wsdlFileName[0], schemaFiles);
 307         }
 308         return true;
 309     }
 310 
 311     private String property(String key) {
 312         try {
 313             String property = System.getProperty(key);
 314             return property != null ? property : "UNKNOWN";
 315         } catch (SecurityException ignored) {
 316             return "UNKNOWN";
 317         }
 318     }
 319 
 320     private List<File> getExternalFiles(List<String> exts) {
 321         List<File> files = new ArrayList<File>();
 322         for (String ext : exts) {
 323             // first try absolute path ...
 324             File file = new File(ext);
 325             if (!file.exists()) {
 326                 // then relative path ...
 327                 file = new File(options.sourceDir.getAbsolutePath() + File.separator + ext);
 328             }
 329             files.add(file);
 330         }
 331         return files;
 332     }
 333 
 334     /**
 335      * Generates a small XML file that captures the key activity of wsgen,
 336      * so that test harness can pick up artifacts.
 337      */
 338     private void generateWsgenReport(Class<?> endpointClass, AbstractSEIModelImpl rtModel, File wsdlFile, Map<String, File> schemaFiles) {
 339         try {


< prev index next >