1 23 24 33 34 package com.sun.enterprise.webservice.apt; 35 36 import javax.xml.ws.WebServiceRef; 37 import java.io.File ; 38 import java.lang.Runtime ; 39 import java.lang.Process ; 40 import java.util.logging.Logger ; 41 import java.util.logging.Level ; 42 43 import com.sun.mirror.declaration.TypeDeclaration; 44 import com.sun.mirror.declaration.ClassDeclaration; 45 import com.sun.mirror.declaration.FieldDeclaration; 46 import com.sun.mirror.apt.AnnotationProcessorEnvironment; 47 import com.sun.mirror.apt.AnnotationProcessor; 48 import com.sun.mirror.util.SimpleDeclarationVisitor; 49 50 import static com.sun.mirror.util.DeclarationVisitors.*; 51 52 import com.sun.enterprise.deployment.backend.ProcessWatcher; 53 import com.sun.enterprise.deployment.backend.DeploymentLogger; 54 55 59 public class WebServiceRefAp implements AnnotationProcessor { 60 61 private final AnnotationProcessorEnvironment env; 62 public static Logger logger = null; 65 66 public WebServiceRefAp(AnnotationProcessorEnvironment env) { 67 this.env = env; 68 } 69 70 public void process() { 71 for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) 72 typeDecl.accept(getDeclarationScanner(new ServiceRefVisitor(), 73 NO_OP)); 74 } 75 76 private class ServiceRefVisitor extends SimpleDeclarationVisitor { 77 public void visitClassDeclaration(ClassDeclaration d) { 78 if (logger!=null) { 79 logger.fine("Processing " + d.getQualifiedName()); 80 } 81 } 82 83 public void visitFieldDeclaration(FieldDeclaration f) { 84 85 WebServiceRef ref = f.getAnnotation(WebServiceRef.class); 86 if (ref==null) { 87 return; 88 } else { 89 if (logger!=null && logger.isLoggable(Level.FINE)) { 90 logger.fine("Found " + f.getSimpleName() + " annotated with WebServiceRef"); 91 logger.fine("Name is " + ref.name()); 92 logger.fine("WSDL is " + ref.wsdlLocation()); 93 logger.fine("of type " + f.getType().toString()); 94 } 95 } 96 97 if (ref.wsdlLocation()==null || ref.wsdlLocation().length()==0) 99 return; 100 101 File server = new File (System.getProperty("com.sun.aas.installRoot")); 102 server = new File (server, "bin"); 103 File wsimport = new File (server, "wsimport"); 104 105 if (wsimport.exists()) { 106 107 File classesDir = new File (System.getProperty("user.dir")); 108 String outputDir = env.getOptions().get("-d"); 109 if (outputDir!=null) { 110 if (!(new File (outputDir).isAbsolute())) { 111 classesDir = new File (classesDir, outputDir); 112 } 113 classesDir.mkdirs(); 114 } 115 116 String wsc = wsimport.getAbsolutePath(); 117 String wscompileArgs = 118 " -keep -d " + classesDir.getAbsolutePath() + 119 " " + ref.wsdlLocation(); 120 if (logger!=null) { 121 logger.log(Level.INFO, "Invoking wsimport with " + ref.wsdlLocation()); 122 } else { 123 System.out.println("Invoking " + wsimport.getAbsolutePath() + " with " + ref.wsdlLocation() + "in " + classesDir.getAbsolutePath()); 124 } 125 String command = wsc + " " + wscompileArgs; 126 if (logger!=null && logger.isLoggable(Level.FINE)) 127 logger.fine("Command " + command); 128 129 int exitValue=-1; 130 try { 131 Process p = Runtime.getRuntime().exec(command); 132 ProcessWatcher pw = new ProcessWatcher(p); 133 exitValue = pw.watch(); 134 } catch(Exception e) { 135 e.printStackTrace(); 136 } 137 if (exitValue==0) { 138 if (logger!=null) 139 logger.log(Level.INFO, "wsimport successful"); 140 } else { 141 if (logger!=null) 142 logger.log(Level.SEVERE, "wsimport failed"); 143 return; 144 } 145 146 } else { 147 if (logger!=null) { 148 logger.log(Level.SEVERE, "Cannot find wsimport tool"); 149 } else { 150 System.out.println("Cannot find wsimport"); 151 } 152 return; 153 } 154 } 155 156 } 157 } 158 | Popular Tags |