1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.toWs;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.geronimo.ews.ws4j2ee.context.ContextValidator;
22 import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
23 import org.apache.geronimo.ews.ws4j2ee.context.MiscInfo;
24 import org.apache.geronimo.ews.ws4j2ee.context.webservices.client.interfaces.ServiceReferanceContext;
25 import org.apache.geronimo.ews.ws4j2ee.toWs.impl.Ws4J2eeFactoryImpl;
26 import org.apache.geronimo.ews.ws4j2ee.utils.MiscFactory;
27 import org.apache.geronimo.ews.ws4j2ee.utils.Utils;
28
29 import java.io.FileInputStream;
30 import java.util.HashMap;
31
32 /***
33 * <p>this class genarate the code when the WSDL presents.</p>
34 */
35 public class Ws4J2EEClientwithWSDL implements Generator {
36 private String wsConfFileLocation;
37 private boolean verbose = false;
38 private Ws4J2eeCLOptionParser clparser;
39 private Ws4J2eeFactory factory;
40 protected static Log log =
41 LogFactory.getLog(Ws4J2EEClientwithWSDL.class.getName());
42
43 private MiscInfo misc;
44
45 public Ws4J2EEClientwithWSDL(String[] args) throws Exception {
46 clparser = new Ws4J2eeCLOptionParser(args);
47 }
48
49 /***
50 * genarate. what is genarated is depend on genarators included.
51 *
52 * @see org.apache.geronimo.ews.ws4j2ee.toWs.Generator#genarate()
53 */
54 public void generate() throws GenerationFault {
55 try {
56 factory = new Ws4J2eeFactoryImpl();
57 J2EEWebServiceContext wscontext = factory.getContextFactory().getJ2EEWsContext(true);
58 wscontext.setFactory(factory);
59
60 misc = factory.getContextFactory().createMiscInfo(new HashMap());
61 wscontext.setMiscInfo(misc);
62 String wscfClientfile = clparser.getWscffile();
63 misc.setWsconffile(MiscFactory.getInputFile(wscfClientfile));
64 misc.setOutputPath(clparser.getOutputDirectory());
65 wsConfFileLocation = Utils.getRootDirOfFile(wscfClientfile);
66 wscontext.getMiscInfo().setImplStyle(clparser.getImplStyle());
67 wscontext.getMiscInfo().setTargetJ2EEContainer(clparser.getContanier());
68
69
70
71 ServiceReferanceContext serviceContext =
72 factory.getParserFactory().parseServiceReferance(wscontext,
73 new FileInputStream(wscfClientfile));
74 if (verbose) {
75 log.info(wscfClientfile + " parsed ..");
76 log.info(serviceContext.getJaxrpcmappingFile());
77 log.info(serviceContext.getWsdlFile());
78 }
79 wscontext.getMiscInfo().setJaxrpcfile(MiscFactory.getInputFile(Utils.getAbsolutePath(serviceContext.getJaxrpcmappingFile(),
80 wsConfFileLocation)));
81 wscontext.getMiscInfo().setWsdlFile(MiscFactory.getInputFile(Utils.getAbsolutePath(serviceContext.getWsdlFile(),
82 wsConfFileLocation)));
83 wscontext.getMiscInfo().setVerbose(verbose);
84 wscontext.getMiscInfo().setHandlers(serviceContext.getHandlers());
85
86
87 if (verbose)
88 log.info("starting client side code genaration .. ");
89 Generator clientStubGen = factory.getGenerationFactory().createClientSideWsGenerator(wscontext);
90 clientStubGen.generate();
91 ContextValidator cvalidator = new ContextValidator(wscontext);
92
93 Generator handlerGen = factory.getGenerationFactory().createHandlerGenerator(wscontext);
94 handlerGen.generate();
95 } catch (Exception e) {
96 e.printStackTrace();
97 throw GenerationFault.createGenerationFault(e);
98 }
99 }
100
101 public static void main(String[] args) throws Exception {
102 Ws4J2EEClientwithWSDL gen = new Ws4J2EEClientwithWSDL(args);
103 gen.generate();
104 }
105 }