View Javadoc

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.geronimo.ews.jaxrpcmapping;
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  import org.apache.axis.wsdl.toJava.JavaBindingWriter;
23  
24  import javax.wsdl.Operation;
25  import javax.wsdl.PortType;
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import java.util.Iterator;
29  
30  /***
31   * This is Wsdl2java's PortType Writer.  It writes the <portTypeName>.java file
32   * which contains the <portTypeName> interface.
33   *
34   * @author Ias (iasandcb@tmax.co.kr)
35   */
36  public class J2eeInterfaceWriter extends J2eeClassWriter {
37      protected PortType portType;
38      protected BindingEntry bEntry;
39  
40      /***
41       * Constructor.
42       */
43      protected J2eeInterfaceWriter(J2eeEmitter emitter,
44                                    PortTypeEntry ptEntry, BindingEntry bEntry, SymbolTable symbolTable) {
45          super(emitter,
46                  (String) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME), "interface");
47          this.portType = ptEntry.getPortType();
48          this.bEntry = bEntry;
49      } // ctor
50  
51      /***
52       * Override generate method to prevent duplicate interfaces because
53       * of two bindings referencing the same portType
54       */
55      public void generate() throws IOException {
56          String fqClass = getPackage() + "." + getClassName();
57  
58          // Do not emit the same portType/interface twice
59          if (!emitter.getGeneratedFileInfo().getClassNames().contains(fqClass)) {
60              super.generate();
61          }
62      } // generate
63  
64      /***
65       * Returns "interface ".
66       */
67      protected String getClassText() {
68          return "interface ";
69      } // getClassString
70  
71      /***
72       * Returns "extends java.rmi.Remote ".
73       */
74      protected String getExtendsText() {
75          return "extends java.rmi.Remote ";
76      } // getExtendsText
77  
78      /***
79       * Write the body of the portType interface file.
80       */
81      protected void writeFileBody(PrintWriter pw) throws IOException {
82          Iterator operations = portType.getOperations().iterator();
83          while (operations.hasNext()) {
84              Operation operation = (Operation) operations.next();
85              writeOperation(pw, operation);
86          }
87      } // writeFileBody
88  
89      /***
90       * This method generates the interface signatures for the given operation.
91       */
92      protected void writeOperation(PrintWriter pw, Operation operation) throws IOException {
93          writeComment(pw, operation.getDocumentationElement(), true);
94          Parameters parms = bEntry.getParameters(operation);
95          pw.println(parms.signature + ";");
96      } // writeOperation
97  
98  }