KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > toJava > JavaServiceWriter


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.wsdl.toJava;
17
18 import org.apache.axis.wsdl.gen.Generator;
19 import org.apache.axis.wsdl.symbolTable.ServiceEntry;
20 import org.apache.axis.wsdl.symbolTable.SymbolTable;
21
22 import javax.wsdl.Service;
23 import java.io.IOException JavaDoc;
24
25 /**
26  * This is Wsdl2java's Service Writer. It writes the following files, as appropriate:
27  * <serviceName>.java, <serviceName>TestCase.java.
28  */

29 public class JavaServiceWriter implements Generator {
30
31     /** Field serviceIfaceWriter */
32     protected Generator serviceIfaceWriter = null;
33
34     /** Field serviceImplWriter */
35     protected Generator serviceImplWriter = null;
36
37     /** Field testCaseWriter */
38     protected Generator testCaseWriter = null;
39
40     /** Field PORT_NAME */
41     public static final String JavaDoc PORT_NAME = "port name";
42     
43     /** Field emitter */
44     protected Emitter emitter;
45     
46     /** Field WSDL service */
47     protected Service service;
48     
49     /** Field symbolTable */
50     protected SymbolTable symbolTable;
51
52     /**
53      * Constructor.
54      *
55      * @param emitter
56      * @param service
57      * @param symbolTable
58      */

59     public JavaServiceWriter(Emitter emitter, Service service,
60                              SymbolTable symbolTable) {
61         this.emitter = emitter;
62         this.service = service;
63         this.symbolTable = symbolTable;
64     } // ctor
65

66     /**
67      * setGenerators
68      * Logic to set the generators that are based on the Service.
69      * This logic was moved from the constructor so extended interfaces
70      * can more effectively use the hooks.
71      */

72     protected void setGenerators() {
73         ServiceEntry sEntry = symbolTable.getServiceEntry(service.getQName());
74
75         if (sEntry.isReferenced()) {
76             serviceIfaceWriter = new JavaServiceIfaceWriter(emitter, sEntry,
77                     symbolTable);
78             serviceImplWriter = new JavaServiceImplWriter(emitter, sEntry,
79                     symbolTable);
80
81             if (emitter.isTestCaseWanted()) {
82                 testCaseWriter = new JavaTestCaseWriter(emitter, sEntry,
83                         symbolTable);
84             }
85         }
86     }
87     
88     /**
89      * Set the writer based on the other condition after generate() is called.
90      */

91     protected void postSetGenerators() {
92         if (emitter.isDeploy()) {
93             serviceIfaceWriter = null;
94             serviceImplWriter = null;
95         }
96     }
97
98     /**
99      * Write all the service bindnigs: service and testcase.
100      *
101      * @throws IOException
102      */

103     public void generate() throws IOException JavaDoc {
104         setGenerators();
105         postSetGenerators();
106
107         if (serviceIfaceWriter != null) {
108             serviceIfaceWriter.generate();
109         }
110
111         if (serviceImplWriter != null) {
112             serviceImplWriter.generate();
113         }
114
115         if (testCaseWriter != null) {
116             testCaseWriter.generate();
117         }
118     } // generate
119
} // class JavaServiceWriter
120
Popular Tags