KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > codegen > JaxRpcRICodegen


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.webservice.codegen;
25
26 import com.sun.appserv.ClassLoaderUtil;
27 import java.net.URLClassLoader JavaDoc;
28 import java.util.Vector JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.List JavaDoc;
32 import java.io.*;
33 import java.net.URL JavaDoc;
34 import java.util.logging.Logger JavaDoc;
35 import java.util.logging.Level JavaDoc;
36
37 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
38
39 import com.sun.enterprise.util.LocalStringManagerImpl;
40
41 import com.sun.ejb.codegen.EjbcContext;
42 import com.sun.ejb.codegen.GeneratorException;
43
44 // DOL imports
45
import com.sun.enterprise.deployment.Application;
46 import com.sun.enterprise.deployment.backend.Deployer;
47 import com.sun.enterprise.deployment.backend.OptionalPkgDependency;
48 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
49 import com.sun.enterprise.deployment.Descriptor;
50 import com.sun.enterprise.deployment.io.JaxrpcMappingDeploymentDescriptorFile;
51 import com.sun.enterprise.deployment.JaxrpcMappingDescriptor;
52 import com.sun.enterprise.deployment.JaxrpcMappingDescriptor.Mapping;
53 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
54 import com.sun.enterprise.deployment.ServiceRefPortInfo;
55 import com.sun.enterprise.deployment.util.ApplicationVisitor;
56 import com.sun.enterprise.deployment.util.DefaultDOLVisitor;
57 import com.sun.enterprise.deployment.util.ModuleContentLinker;
58 import com.sun.enterprise.deployment.util.WebServerInfo;
59 import com.sun.enterprise.deployment.WebService;
60 import com.sun.enterprise.deployment.WebServiceEndpoint;
61 import com.sun.enterprise.deployment.WebServicesDescriptor;
62 import com.sun.enterprise.loader.EJBClassLoader;
63 import com.sun.enterprise.loader.EJBClassPathUtils;
64
65 import com.sun.enterprise.deployment.backend.OptionalPkgDependency;
66 import com.sun.enterprise.deployment.backend.Deployer;
67
68 import javax.xml.namespace.QName JavaDoc;
69 import javax.xml.rpc.Stub JavaDoc;
70
71 // web service impl imports
72
import com.sun.enterprise.webservice.WsUtil;
73 import com.sun.enterprise.webservice.WsCompile;
74
75 //JAX-RPC SPI
76
import com.sun.xml.rpc.spi.JaxRpcObjectFactory;
77 import com.sun.xml.rpc.spi.tools.CompileTool;
78 import com.sun.xml.rpc.spi.tools.GeneratedFileInfo;
79 import com.sun.xml.rpc.spi.tools.GeneratorConstants;
80 import com.sun.xml.rpc.spi.tools.J2EEModelInfo;
81 import com.sun.xml.rpc.spi.tools.ModelFileModelInfo;
82 import com.sun.xml.rpc.spi.tools.ModelInfo;
83 import com.sun.xml.rpc.spi.tools.NamespaceMappingInfo;
84 import com.sun.xml.rpc.spi.tools.NamespaceMappingRegistryInfo;
85 import com.sun.xml.rpc.spi.tools.NoMetadataModelInfo;
86
87 /**
88  * This class is responsible for generating all non portable
89  * jax-rpc artifacts for a single .ear or standalone module.
90  *
91  * @author Jerome Dochez
92  */

93 public class JaxRpcRICodegen extends ModuleContentLinker
94     implements JaxRpcCodegenAdapter
95 {
96     
97     // our code generation context
98
protected EjbcContext context = null;
99     
100     // list of generated files
101
Vector JavaDoc files = new Vector JavaDoc();
102
103     private JaxRpcObjectFactory rpcFactory;
104     
105     private Logger JavaDoc logger = WsUtil.getDefaultLogger();
106
107     // total number of times wscompile is invoked for the .ear or the
108
// standalone module.
109
private int wscompileInvocationCount = 0;
110
111     // resources...
112
private static LocalStringManagerImpl localStrings =
113         new LocalStringManagerImpl(JaxRpcRICodegen.class);
114     
115     private CompileTool wscompileForAccept = null;
116     private CompileTool wscompileForWebServices = null;
117     
118     /** Creates a new instance of JaxRpcRICodegen */
119     public JaxRpcRICodegen() {
120         rpcFactory = JaxRpcObjectFactory.newInstance();
121     }
122     
123     public void run(EjbcContext context) throws Exception JavaDoc {
124         rootLocation_ = new FileArchive();
125         rootLocation_.open(context.getSrcDir().getAbsolutePath());
126         this.context = context;
127         Application application = context.getDescriptor();
128         application.visit((ApplicationVisitor) this);
129     }
130     
131     /**
132      * Visits a webs service reference
133      */

134     public void accept(ServiceReferenceDescriptor serviceRef) {
135         boolean codegenRequired = false;
136
137         URL JavaDoc wsdlOverride = null;
138         boolean wsdlOverriden = false;
139         super.accept(serviceRef);
140         try {
141             // Resolve port component links to target endpoint address.
142
// We can't assume web service client is running in same VM
143
// as endpoint in the intra-app case because of app clients.
144
//
145
// Also set port-qname based on linked port's qname if not
146
// already set.
147
for(Iterator JavaDoc ports = serviceRef.getPortsInfo().iterator(); ports.hasNext();) {
148                 ServiceRefPortInfo portInfo = (ServiceRefPortInfo) ports.next();
149                 
150                 if( portInfo.isLinkedToPortComponent() ) {
151                     WebServiceEndpoint linkedPortComponent = portInfo.getPortComponentLink();
152                     
153                     if (linkedPortComponent==null) {
154                         throw new GeneratorException(localStrings.getLocalString(
155                    "enterprise.webservice.componentlinkunresolved",
156                            "The port-component-link {0} cannot be resolved",
157                            new Object JavaDoc[] {portInfo.getPortComponentLinkName()}));
158                     }
159                     WsUtil wsUtil = new WsUtil();
160                     WebServerInfo wsi = wsUtil.getWebServerInfo(context.getDeploymentRequest());
161                     URL JavaDoc rootURL = wsi.getWebServerRootURL(linkedPortComponent.isSecure());
162                     URL JavaDoc actualAddress = linkedPortComponent.composeEndpointAddress(rootURL);
163                     portInfo.addStubProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, actualAddress.toExternalForm());
164                     if (serviceRef.getBundleDescriptor().getModuleType().equals(ModuleType.CAR)) {
165                         wsdlOverride = serviceRef.getWsdlOverride();
166             if (wsdlOverride!=null) {
167                             wsdlOverriden = true;
168                             serviceRef.setWsdlOverride(linkedPortComponent.getWebService().getWsdlFileUrl());
169             }
170                     }
171                 }
172             }
173
174             // If this is a post JAXRPC-1.1 based web service, then no need for code gen etc etc
175
ClassLoader JavaDoc clr = serviceRef.getBundleDescriptor().getClassLoader();
176             Class JavaDoc serviceInterface = clr.loadClass(serviceRef.getServiceInterface());
177             if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterface)) {
178                 return;
179             }
180             
181             if( serviceRef.hasGeneratedServiceInterface() ) {
182                 
183                 if( serviceRef.hasWsdlFile() && serviceRef.hasMappingFile() ) {
184                     codegenRequired = true;
185                 } else {
186                     throw new GeneratorException
187             ("Deployment error for service-ref " + serviceRef.getName()
188              + ".\nService references with generated service " +
189              "interface must include WSDL and mapping information.");
190                 }
191                 
192             } else {
193                 
194                 if( serviceRef.hasWsdlFile() ) {
195                     if( serviceRef.hasMappingFile() ) {
196                         codegenRequired = true;
197                     } else {
198                         throw new GeneratorException
199                 ("Deployment error for service-ref " + serviceRef.getName()
200                  + ".\nService references with wsdl must also have " +
201                  "mapping information.");
202                     }
203                 }
204             }
205             
206             if( codegenRequired ) {
207                 ModelInfo modelInfo = createModelInfo(serviceRef);
208                 String JavaDoc args[] = createJaxrpcCompileArgs(false);
209
210                 CompileTool wscompile =
211             rpcFactory.createCompileTool(System.out, "wscompile");
212                 wscompileForAccept = wscompile;
213                 WsCompile delegate =
214                     new WsCompile(wscompile, serviceRef);
215                 delegate.setModelInfo(modelInfo);
216                 wscompile.setDelegate(delegate);
217
218                 jaxrpc(args, delegate, serviceRef, files);
219             }
220             if (wsdlOverriden) {
221                 serviceRef.setWsdlOverride(wsdlOverride);
222             }
223         } catch(Exception JavaDoc e) {
224             RuntimeException JavaDoc re = new RuntimeException JavaDoc(e.getMessage());
225             re.initCause(e);
226             throw re;
227         }
228     }
229     
230     /**
231      * visits a web service definition
232      * @param web service
233      */

234     public void accept(WebService webService) {
235         super.accept(webService);
236         try {
237              if("1.1".compareTo(webService.getWebServicesDescriptor().getSpecVersion())<0) {
238                 WsUtil wsUtil = new WsUtil();
239                 Collection JavaDoc<WebServiceEndpoint> endpoints = webService.getEndpoints();
240                 for(WebServiceEndpoint ep : endpoints) {
241                     if( ep.implementedByWebComponent() ) {
242                         wsUtil.updateServletEndpointRuntime(ep);
243                     } else {
244                         wsUtil.validateEjbEndpoint(ep);
245                     }
246                 }
247                 //wsImport(webService, files);
248
} else {
249                 jaxrpcWebService(webService, files);
250             }
251         } catch(Exception JavaDoc e) {
252             RuntimeException JavaDoc ge =new RuntimeException JavaDoc(e.getMessage());
253             ge.initCause(e);
254             throw ge;
255         }
256     }
257     
258     public Iterator JavaDoc getListOfBinaryFiles() {
259         return files.iterator();
260     }
261     
262     public Iterator JavaDoc getListOfSourceFiles() {
263         // for now I do not maintain those
264
return null;
265     }
266     
267     /**
268      *Releases resources used during the code gen and compilation.
269      */

270     public void done() {
271 // done(CompileTool) is now invoked after each compilation is complete
272
// from inside the jaxrpc method. Otherwise, multiple uses of jaxrpc could
273
// cause continued file locking on Windows since only the last one was
274
// recorded in the wscompileForxxx variables.
275
//
276
// done(wscompileForAccept);
277
// done(wscompileForWebServices);
278
}
279     
280     /**
281      *Navigates to the URLClassLoader used by the jaxrpc compilation and
282      *releases it.
283      *@param wscompile the CompileTool whose loader is to be released
284      */

285     private void done(CompileTool wscompile) {
286         /*
287          *Follow the object graph to the loader:
288          *basically CompileTool -> ProcessorEnvironment -> the URLClassLoader.
289          */

290         if (wscompile != null && wscompile instanceof com.sun.xml.rpc.tools.wscompile.CompileTool) {
291             com.sun.xml.rpc.tools.wscompile.CompileTool compileTool = (com.sun.xml.rpc.tools.wscompile.CompileTool) wscompile;
292             com.sun.xml.rpc.spi.tools.ProcessorEnvironment env = compileTool.getEnvironment();
293             if (env != null && env instanceof com.sun.xml.rpc.processor.util.ProcessorEnvironment) {
294                 com.sun.xml.rpc.processor.util.ProcessorEnvironment typedEnv = (com.sun.xml.rpc.processor.util.ProcessorEnvironment) env;
295                 java.net.URLClassLoader JavaDoc urlCL = typedEnv.getClassLoader();
296                 ClassLoaderUtil.releaseLoader(urlCL);
297             }
298         }
299     }
300     
301     private JaxrpcMappingDescriptor getJaxrpcMappingInfo(URL JavaDoc mappingFileUrl,
302                                                          Descriptor desc)
303         throws Exception JavaDoc {
304         JaxrpcMappingDescriptor mappingDesc = null;
305
306         InputStream is = null;
307         try {
308             is = mappingFileUrl.openStream();
309             JaxrpcMappingDeploymentDescriptorFile jaxrpcDD =
310                 new JaxrpcMappingDeploymentDescriptorFile();
311             
312             // useful for validation errors...
313
if (desc instanceof ServiceReferenceDescriptor) {
314                 ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor) desc;
315                 jaxrpcDD.setDeploymentDescriptorPath(srd.getMappingFileUri());
316                 jaxrpcDD.setErrorReportingString(srd.getBundleDescriptor().getModuleDescriptor().getArchiveUri());
317             }
318             if (desc instanceof WebService) {
319                 WebService ws = (WebService) desc;
320                 jaxrpcDD.setDeploymentDescriptorPath(ws.getMappingFileUri());
321                 jaxrpcDD.setErrorReportingString(ws.getBundleDescriptor().getModuleDescriptor().getArchiveUri());
322             }
323             jaxrpcDD.setXMLValidationLevel(Deployer.getValidationLevel());
324             mappingDesc = (JaxrpcMappingDescriptor) jaxrpcDD.read(desc, is);
325         } finally {
326             if( is != null ) {
327                 is.close();
328             }
329         }
330
331         return mappingDesc;
332     }
333     
334     private boolean isJaxrpcRIModelFile(URL JavaDoc mappingFileUrl) {
335         boolean isModel = false;
336         InputStream is = null;
337         try {
338             is = mappingFileUrl.openStream();
339             isModel = rpcFactory.createXMLModelFileFilter().isModelFile(is);
340         } catch(Throwable JavaDoc t) {
341         } finally {
342             if( is != null ) {
343                 try {
344                     is.close();
345                 } catch(Exception JavaDoc e) {}
346             }
347         }
348         return isModel;
349     }
350     
351     private ModelInfo createModelInfo(WebService webService)
352         throws Exception JavaDoc {
353
354         ModelInfo modelInfo = null;
355         URL JavaDoc mappingFileUrl = webService.getMappingFile().toURL();
356         modelInfo = createModelFileModelInfo(mappingFileUrl);
357         if( isJaxrpcRIModelFile(mappingFileUrl) ) {
358             debug("000. JaxrpcRIModelFile.");
359             modelInfo = createModelFileModelInfo(mappingFileUrl);
360         } else {
361             JaxrpcMappingDescriptor mappingDesc =
362                 getJaxrpcMappingInfo(mappingFileUrl, webService);
363             if( mappingDesc.isSimpleMapping() ) {
364                 debug("111. SimpleMapping.");
365                 modelInfo = createNoMetadataModelInfo(webService, mappingDesc);
366             } else {
367                 debug("222. FullMapping .");
368                 modelInfo = createFullMappingModelInfo(webService);
369             }
370         }
371
372         return modelInfo;
373     }
374
375     private ModelInfo createModelInfo(ServiceReferenceDescriptor serviceRef)
376         throws Exception JavaDoc {
377
378         ModelInfo modelInfo = null;
379         URL JavaDoc mappingFileUrl = serviceRef.getMappingFile().toURL();
380         if( isJaxrpcRIModelFile(mappingFileUrl) ) {
381             modelInfo = createModelFileModelInfo(mappingFileUrl);
382         } else {
383             JaxrpcMappingDescriptor mappingDesc =
384                 getJaxrpcMappingInfo(mappingFileUrl, serviceRef);
385             if( mappingDesc.isSimpleMapping() &&
386                 serviceRef.hasGeneratedServiceInterface() ) {
387                 // model info for this modeler requires generated service
388
// interface name.
389
modelInfo = createNoMetadataModelInfo(serviceRef, mappingDesc);
390             } else {
391                 modelInfo = createFullMappingModelInfo(serviceRef);
392             }
393         }
394
395         return modelInfo;
396     }
397
398     private ModelFileModelInfo createModelFileModelInfo(URL JavaDoc modelFileUrl)
399         throws Exception JavaDoc {
400         
401         ModelFileModelInfo modelInfo = rpcFactory.createModelFileModelInfo();
402         modelInfo.setLocation(modelFileUrl.toExternalForm());
403
404         return modelInfo;
405     }
406
407     private J2EEModelInfo createFullMappingModelInfo(WebService webService)
408         throws Exception JavaDoc {
409
410         URL JavaDoc mappingFileUrl = webService.getMappingFile().toURL();
411         URL JavaDoc wsdlFileUrl = webService.getWsdlFileUrl();
412
413         return createFullMappingModelInfo(mappingFileUrl, wsdlFileUrl);
414     }
415
416     private J2EEModelInfo createFullMappingModelInfo
417         (ServiceReferenceDescriptor serviceRef) throws Exception JavaDoc {
418
419         URL JavaDoc mappingFileUrl = serviceRef.getMappingFile().toURL();
420         URL JavaDoc wsdlFileUrl = serviceRef.hasWsdlOverride() ?
421             serviceRef.getWsdlOverride() : serviceRef.getWsdlFileUrl();
422         return createFullMappingModelInfo(mappingFileUrl, wsdlFileUrl);
423     }
424
425     private J2EEModelInfo createFullMappingModelInfo
426         (URL JavaDoc mappingFile, URL JavaDoc wsdlFile) throws Exception JavaDoc {
427
428         J2EEModelInfo modelInfo = rpcFactory.createJ2EEModelInfo(mappingFile);
429         modelInfo.setLocation(wsdlFile.toExternalForm());
430         // java package name not used
431
modelInfo.setJavaPackageName("package_ignored");
432         return modelInfo;
433         
434     }
435
436     private NoMetadataModelInfo createNoMetadataModelInfo
437         (WebService webService, JaxrpcMappingDescriptor mappingDesc)
438         throws Exception JavaDoc {
439
440         NoMetadataModelInfo modelInfo = rpcFactory.createNoMetadataModelInfo();
441         URL JavaDoc wsdlFileUrl = webService.getWsdlFileUrl();
442
443         Collection JavaDoc endpoints = webService.getEndpoints();
444         if( endpoints.size() != 1 ) {
445             throw new GeneratorException
446                 ("Deployment code generation error for webservice " +
447                  webService.getName() + ". " +
448                  " jaxrpc-mapping-file is required if web service has " +
449                  "multiple endpoints");
450         }
451
452         WebServiceEndpoint endpoint = (WebServiceEndpoint)
453             endpoints.iterator().next();
454
455         modelInfo.setLocation(wsdlFileUrl.toExternalForm());
456         modelInfo.setInterfaceName(endpoint.getServiceEndpointInterface());
457         modelInfo.setPortName(endpoint.getWsdlPort());
458
459         addNamespaceMappingRegistry(modelInfo, mappingDesc);
460
461         return modelInfo;
462     }
463
464     private void addNamespaceMappingRegistry
465         (NoMetadataModelInfo modelInfo, JaxrpcMappingDescriptor mappingDesc) {
466                                              
467         NamespaceMappingRegistryInfo namespaceRegistry =
468             rpcFactory.createNamespaceMappingRegistryInfo();
469         
470         modelInfo.setNamespaceMappingRegistry(namespaceRegistry);
471
472         Collection JavaDoc mappings = mappingDesc.getMappings();
473         for(Iterator JavaDoc iter = mappings.iterator(); iter.hasNext();) {
474             Mapping next = (Mapping) iter.next();
475             NamespaceMappingInfo namespaceInfo =
476                 rpcFactory.createNamespaceMappingInfo(next.getNamespaceUri(),
477                                                       next.getPackage());
478             namespaceRegistry.addMapping(namespaceInfo);
479         }
480     }
481
482     private NoMetadataModelInfo createNoMetadataModelInfo
483         (ServiceReferenceDescriptor serviceRef,
484          JaxrpcMappingDescriptor mappingDesc) throws Exception JavaDoc {
485
486         NoMetadataModelInfo modelInfo = rpcFactory.createNoMetadataModelInfo();
487         URL JavaDoc wsdlFile = serviceRef.hasWsdlOverride() ?
488             serviceRef.getWsdlOverride() : serviceRef.getWsdlFileUrl();
489         modelInfo.setLocation(wsdlFile.toExternalForm());
490
491         // Service endpoint interface is required. Parse generated
492
// service interface for it since we can't count on SEI
493
// having been listed in standard deployment information.
494
WsUtil wsUtil = new WsUtil();
495         String JavaDoc serviceInterfaceName = serviceRef.getServiceInterface();
496         
497         ClassLoader JavaDoc cl = context.getDescriptor().getClassLoader();
498         if (cl instanceof EJBClassLoader) {
499             List JavaDoc moduleList = EJBClassPathUtils.getApplicationClassPath((Application) context.getDescriptor(), context.getSrcDir().getAbsolutePath());
500             for (Iterator JavaDoc itr=moduleList.iterator();itr.hasNext();) {
501                 ((EJBClassLoader) cl).appendURL((new File((String JavaDoc) itr.next())));
502             }
503         }
504         
505         Class JavaDoc serviceInterface = cl.loadClass(serviceInterfaceName);
506         Collection JavaDoc seis = wsUtil.getSEIsFromGeneratedService(serviceInterface);
507
508         if( seis.size() == 0 ) {
509             throw new GeneratorException("Invalid Generated Service Interface "
510                                          + serviceInterfaceName + " . ");
511         } else if( seis.size() > 1 ) {
512             throw new GeneratorException("Deployment error : If no " +
513                                          "jaxrpc-mapping file is provided, " +
514                                          "Generated Service Interface must have"
515                                          +" only 1 Service Endpoint Interface");
516         }
517
518         String JavaDoc serviceEndpointInterface = (String JavaDoc) seis.iterator().next();
519         modelInfo.setInterfaceName(serviceEndpointInterface);
520
521         addNamespaceMappingRegistry(modelInfo, mappingDesc);
522
523         return modelInfo;
524     }
525     
526     private boolean keepJaxrpcGeneratedFile(String JavaDoc fileType, Descriptor desc) {
527         boolean keep = true;
528         if( (fileType.equals(GeneratorConstants.FILE_TYPE_WSDL) ||
529              fileType.equals(GeneratorConstants.FILE_TYPE_REMOTE_INTERFACE)) ) {
530             keep = false;
531         } else if( fileType.equals(GeneratorConstants.FILE_TYPE_SERVICE ) ) {
532             // Only keep the service interface if this is a service reference
533
// with generic service interface. In this case, the interface
534
// is generated during deployment instead of being packaged in
535
// the module.
536
keep = (desc instanceof ServiceReferenceDescriptor) &&
537                 ((ServiceReferenceDescriptor)desc).hasGenericServiceInterface();
538         }
539
540         return keep;
541     }
542     
543     // dummy file for jax-rpc wscompile bug
544
File dummyConfigFile=null;
545     
546     private String JavaDoc[] createJaxrpcCompileArgs(boolean generateTies)
547         throws IOException
548     {
549         int numJaxrpcArgs = 0;
550         if (logger.isLoggable(Level.FINE) ) {
551         numJaxrpcArgs = 16;
552     } else {
553         numJaxrpcArgs = 11;
554     }
555
556         // If we need to run wscompile more than once per .ear or
557
// standalone module, use the -infix option to reduce the
558
// chances that generated non-portable jaxrpc artifacts will clash
559
// with generated artifacts from other service-refs and endpoints
560
// loaded by the same classloader at runtime.
561
wscompileInvocationCount++;
562         String JavaDoc infix = null;
563
564         if( wscompileInvocationCount > 1 ) {
565             numJaxrpcArgs++;
566             infix = wscompileInvocationCount + "";
567         }
568
569     String JavaDoc[] jaxrpcArgs = new String JavaDoc[numJaxrpcArgs];
570     int jaxrpcCnt = 0;
571
572         if( dummyConfigFile == null ) {
573             dummyConfigFile = File.createTempFile("dummy_wscompile_config",
574                                                   "config");
575             dummyConfigFile.deleteOnExit();
576         }
577
578         String JavaDoc classPath=null;
579         String JavaDoc[] urls = context.getClasspathUrls();
580         
581         // we need to add all web and appclient classpath
582
Application app = (Application) context.getDescriptor();
583         List JavaDoc moduleList = EJBClassPathUtils.getApplicationClassPath(app, context.getSrcDir().getAbsolutePath());
584         
585         moduleList.addAll(java.util.Arrays.asList(urls));
586         for (int i=0;i<moduleList.size();i++) {
587             if (classPath==null) {
588                 classPath = (String JavaDoc) moduleList.get(i);
589             } else {
590                 classPath = classPath + File.pathSeparatorChar + (String JavaDoc) moduleList.get(i);
591             }
592         }
593         
594         // wscompile doesn't support the -extdirs option, so the best we
595
// can do is prepend the ext dir jar files to the classpath.
596
String JavaDoc optionalDependencyClassPath =
597             OptionalPkgDependency.getExtDirFilesAsClasspath();
598         if(optionalDependencyClassPath.length() > 0) {
599             classPath = optionalDependencyClassPath +
600                 File.pathSeparatorChar + classPath;
601         }
602
603     jaxrpcArgs[jaxrpcCnt++] = generateTies ? "-gen:server" : "-gen:client";
604
605         // Prevent wscompile from regenerating portable classes that are
606
// already packaged within the deployed application.
607
jaxrpcArgs[jaxrpcCnt++] = "-f:donotoverride";
608
609         if( infix != null ) {
610             jaxrpcArgs[jaxrpcCnt++] = "-f:infix:" + infix;
611         }
612
613     jaxrpcArgs[jaxrpcCnt++] = "-classpath";
614     jaxrpcArgs[jaxrpcCnt++] = classPath;
615
616     if (logger.isLoggable(Level.FINE)) {
617             long timeStamp = System.currentTimeMillis();
618         jaxrpcArgs[jaxrpcCnt++] = "-Xdebugmodel:" +
619                 context.getStubsDir() + File.separator + "debugModel.txt." +
620                 timeStamp;
621         jaxrpcArgs[jaxrpcCnt++] = "-Xprintstacktrace";
622         jaxrpcArgs[jaxrpcCnt++] = "-model";
623         jaxrpcArgs[jaxrpcCnt++] =
624                 context.getStubsDir() + File.separator + "debugModel.model" +
625                 timeStamp;
626             jaxrpcArgs[jaxrpcCnt++] = "-verbose";
627     }
628
629         jaxrpcArgs[jaxrpcCnt++] = "-s";
630         jaxrpcArgs[jaxrpcCnt++] = context.getStubsDir().toString();
631         jaxrpcArgs[jaxrpcCnt++] = "-d";
632         jaxrpcArgs[jaxrpcCnt++] = context.getStubsDir().toString();
633         jaxrpcArgs[jaxrpcCnt++] = "-keep";
634         jaxrpcArgs[jaxrpcCnt++] = "-g";
635
636         // config file is not used, but it must be an existing file or it
637
// will not pass CompileTool argument validation.
638
jaxrpcArgs[jaxrpcCnt++] = dummyConfigFile.getPath();
639
640     if ( logger.isLoggable(Level.FINE)) {
641         for ( int i = 0; i < jaxrpcArgs.length; i++ ) {
642         logger.fine(jaxrpcArgs[i]);
643         }
644     }
645         
646         return jaxrpcArgs;
647     }
648     
649     private void jaxrpc(String JavaDoc[] args, WsCompile wsCompile, Descriptor desc,
650                         Vector JavaDoc files)
651         throws Exception JavaDoc {
652
653     try {
654         if (logger.isLoggable(Level.FINE)) {
655         debug("---> ARGS = ");
656         for (int i = 0; i < args.length; i++) {
657             System.err.print(args[i] + "; ");
658         }
659         }
660             boolean compiled = wsCompile.getCompileTool().run(args);
661             done(wsCompile.getCompileTool());
662             if( compiled ) {
663                 Iterator JavaDoc generatedFiles =
664                     wsCompile.getGeneratedFiles().iterator();
665
666                 while(generatedFiles.hasNext()) {
667                     GeneratedFileInfo next = (GeneratedFileInfo)
668                         generatedFiles.next();
669                     String JavaDoc fileType = next.getType();
670                     File file = next.getFile();
671                     String JavaDoc origPath = file.getPath();
672                     if( origPath.endsWith(".java") ) {
673                         int javaIndex = origPath.lastIndexOf(".java");
674                         String JavaDoc newPath = origPath.substring(0, javaIndex) +
675                             ".class";
676                         if( keepJaxrpcGeneratedFile(fileType, desc) ) {
677                             files.add(newPath);
678                         }
679                     }
680                 }
681             } else {
682                 throw new GeneratorException("jaxrpc compilation exception");
683             }
684         } catch (Throwable JavaDoc t) {
685             GeneratorException ge =
686                 new GeneratorException(t.getMessage());
687             ge.initCause(t);
688             throw ge;
689     }
690     }
691     
692     private void jaxrpcWebService(WebService webService, Vector JavaDoc files)
693         throws Exception JavaDoc {
694
695         ModelInfo modelInfo = createModelInfo(webService);
696         String JavaDoc args[] = createJaxrpcCompileArgs(true);
697
698         CompileTool wscompile =
699             rpcFactory.createCompileTool(System.out, "wscompile");
700         wscompileForWebServices = wscompile;
701         WsCompile delegate = new WsCompile(wscompile, webService);
702         delegate.setModelInfo(modelInfo);
703         wscompile.setDelegate(delegate);
704
705         jaxrpc(args, delegate, webService, files);
706     }
707
708     private void debug(String JavaDoc msg) {
709         if (logger.isLoggable(Level.FINE) ) {
710         System.out.println("[JaxRpcRICodegen] --> " + msg);
711         }
712     }
713     
714 }
715
Popular Tags