KickJava   Java API By Example, From Geeks To Geeks.

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


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.utils.Messages;
19 import org.apache.axis.wsdl.gen.Generator;
20 import org.apache.axis.wsdl.symbolTable.BindingEntry;
21 import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
22 import org.apache.axis.wsdl.symbolTable.SymbolTable;
23
24 import javax.wsdl.Binding;
25 import java.io.IOException JavaDoc;
26
27 /**
28  * This is Wsdl2java's Binding Writer. It writes the following files, as appropriate:
29  * <bindingName>Stub.java, <bindingName>Skeleton.java, <bindingName>Impl.java.
30  */

31 public class JavaBindingWriter implements Generator {
32
33     /** Field stubWriter */
34     protected Generator stubWriter = null;
35
36     /** Field skelWriter */
37     protected Generator skelWriter = null;
38
39     /** Field implWriter */
40     protected Generator implWriter = null;
41
42     /** Field interfaceWriter */
43     protected Generator interfaceWriter = null;
44
45     /** Field emitter */
46     protected Emitter emitter;
47
48     /** Field binding */
49     protected Binding binding;
50
51     /** Field symbolTable */
52     protected SymbolTable symbolTable;
53
54     // This is the dynamic var key for the SEI (Service Endpoint
55
// Interface) name. This name could either be derived from
56
// the portType or the binding. The generatorPass fills
57
// this dynamic var in and it is used in the writers that
58
// need this SEI name.
59

60     /** Field INTERFACE_NAME */
61     public static String JavaDoc INTERFACE_NAME = "interface name";
62
63     /**
64      * Constructor.
65      *
66      * @param emitter
67      * @param binding
68      * @param symbolTable
69      */

70     public JavaBindingWriter(Emitter emitter, Binding binding,
71                              SymbolTable symbolTable) {
72
73         this.emitter = emitter;
74         this.binding = binding;
75         this.symbolTable = symbolTable;
76     } // ctor
77

78     /**
79      * getJavaInterfaceWriter
80      *
81      * @param emitter
82      * @param ptEntry
83      * @param bEntry
84      * @param st
85      * @return
86      */

87     protected Generator getJavaInterfaceWriter(Emitter emitter,
88                                                PortTypeEntry ptEntry,
89                                                BindingEntry bEntry,
90                                                SymbolTable st) {
91         return new JavaInterfaceWriter(emitter, ptEntry, bEntry, st);
92     }
93
94     /**
95      * getJavaStubWriter
96      *
97      * @param emitter
98      * @param bEntry
99      * @param st
100      * @return
101      */

102     protected Generator getJavaStubWriter(Emitter emitter, BindingEntry bEntry,
103                                           SymbolTable st) {
104         return new JavaStubWriter(emitter, bEntry, st);
105     }
106
107     /**
108      * getJavaSkelWriter
109      *
110      * @param emitter
111      * @param bEntry
112      * @param st
113      * @return
114      */

115     protected Generator getJavaSkelWriter(Emitter emitter, BindingEntry bEntry,
116                                           SymbolTable st) {
117         return new JavaSkelWriter(emitter, bEntry, st);
118     }
119
120     /**
121      * getJavaImplWriter
122      *
123      * @param emitter
124      * @param bEntry
125      * @param st
126      * @return
127      */

128     protected Generator getJavaImplWriter(Emitter emitter, BindingEntry bEntry,
129                                           SymbolTable st) {
130         return new JavaImplWriter(emitter, bEntry, st);
131     }
132
133     /**
134      * Write all the binding bindings: stub, skeleton, and impl.
135      *
136      * @throws IOException
137      */

138     public void generate() throws IOException JavaDoc {
139
140         setGenerators();
141         postSetGenerators();
142
143         if (interfaceWriter != null) {
144             interfaceWriter.generate();
145         }
146
147         if (stubWriter != null) {
148             stubWriter.generate();
149         }
150
151         if (skelWriter != null) {
152             skelWriter.generate();
153         }
154
155         if (implWriter != null) {
156             implWriter.generate();
157         }
158     } // generate
159

160     /**
161      * setGenerators
162      * Logic to set the generators that are based on the Binding
163      * This logic was moved from the constructor so extended interfaces
164      * can more effectively use the hooks.
165      */

166     protected void setGenerators() {
167
168         BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
169
170         // Interface writer
171
PortTypeEntry ptEntry =
172                 symbolTable.getPortTypeEntry(binding.getPortType().getQName());
173
174         if (ptEntry.isReferenced()) {
175             interfaceWriter = getJavaInterfaceWriter(emitter, ptEntry, bEntry,
176                     symbolTable);
177         }
178
179         if (bEntry.isReferenced()) {
180
181             // Stub writer
182
stubWriter = getJavaStubWriter(emitter, bEntry, symbolTable);
183
184             // Skeleton and Impl writers
185
if (emitter.isServerSide()) {
186                 if (emitter.isSkeletonWanted()) {
187                     skelWriter = getJavaSkelWriter(emitter, bEntry,
188                             symbolTable);
189                 }
190
191                 // Use custom implementation classname if available
192
String JavaDoc fileName = emitter.getImplementationClassName();
193                 if ( fileName == null)
194                     fileName = Utils.getJavaLocalName(bEntry.getName())
195                             + "Impl.java";
196                 else
197                     fileName = Utils.getJavaLocalName(fileName) + ".java";
198
199                 try {
200                     if (Utils.fileExists(fileName,
201                             binding.getQName().getNamespaceURI(),
202                             emitter.getNamespaces())) {
203                         if (!emitter.isQuiet()) {
204                             System.out.println(
205                                  Messages.getMessage("wontOverwrite",
206                                                      fileName));
207                         }
208                     } else {
209                         implWriter = getJavaImplWriter(emitter, bEntry,
210                                 symbolTable);
211                     }
212                 } catch (IOException JavaDoc ioe) {
213                     System.err.println(Messages.getMessage("fileExistError00",
214                             fileName));
215                 }
216             }
217         }
218     }
219     
220     /**
221      * Set the writer based on the other condition after generate() is called.
222      */

223     protected void postSetGenerators() {
224         if (emitter.isDeploy()) {
225             interfaceWriter = null;
226             stubWriter = null;
227             skelWriter = null;
228             implWriter = null;
229         }
230     }
231 } // class JavaBindingWriter
232
Popular Tags