KickJava   Java API By Example, From Geeks To Geeks.

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


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.symbolTable.BindingEntry;
19 import org.apache.axis.wsdl.symbolTable.Parameters;
20 import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
21 import org.apache.axis.wsdl.symbolTable.SymbolTable;
22
23 import javax.wsdl.Operation;
24 import javax.wsdl.PortType;
25 import java.io.IOException JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 /**
30  * This is Wsdl2java's PortType Writer. It writes the <portTypeName>.java file
31  * which contains the <portTypeName> interface.
32  */

33 public class JavaInterfaceWriter extends JavaClassWriter {
34
35     /** Field portType */
36     protected PortType portType;
37
38     /** Field bEntry */
39     protected BindingEntry bEntry;
40
41     /**
42      * Constructor.
43      *
44      * @param emitter
45      * @param ptEntry
46      * @param bEntry
47      * @param symbolTable
48      */

49     protected JavaInterfaceWriter(Emitter emitter, PortTypeEntry ptEntry,
50                                   BindingEntry bEntry,
51                                   SymbolTable symbolTable) {
52
53         super(emitter,
54                 (String JavaDoc) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME),
55                 "interface");
56
57         this.portType = ptEntry.getPortType();
58         this.bEntry = bEntry;
59     } // ctor
60

61     /**
62      * Override generate method to prevent duplicate interfaces because
63      * of two bindings referencing the same portType
64      *
65      * @throws IOException
66      */

67     public void generate() throws IOException JavaDoc {
68
69         String JavaDoc fqClass = getPackage() + "." + getClassName();
70
71         // Do not emit the same portType/interface twice
72
if (!emitter.getGeneratedFileInfo().getClassNames().contains(fqClass)) {
73             super.generate();
74         }
75     } // generate
76

77     /**
78      * Returns "interface ".
79      *
80      * @return
81      */

82     protected String JavaDoc getClassText() {
83         return "interface ";
84     } // getClassString
85

86     /**
87      * Returns "extends java.rmi.Remote ".
88      *
89      * @return
90      */

91     protected String JavaDoc getExtendsText() {
92         return "extends java.rmi.Remote ";
93     } // getExtendsText
94

95     /**
96      * Write the body of the portType interface file.
97      *
98      * @param pw
99      * @throws IOException
100      */

101     protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc {
102
103         Iterator JavaDoc operations = portType.getOperations().iterator();
104
105         while (operations.hasNext()) {
106             Operation operation = (Operation) operations.next();
107
108             writeOperation(pw, operation);
109         }
110     } // writeFileBody
111

112     /**
113      * This method generates the interface signatures for the given operation.
114      *
115      * @param pw
116      * @param operation
117      * @throws IOException
118      */

119     protected void writeOperation(PrintWriter JavaDoc pw, Operation operation)
120             throws IOException JavaDoc {
121
122         writeComment(pw, operation.getDocumentationElement(), true);
123
124         Parameters parms = bEntry.getParameters(operation);
125
126         pw.println(parms.signature + ";");
127     } // writeOperation
128
} // class JavaInterfaceWriter
129
Popular Tags