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.utils.JavaUtils;
19  import org.apache.axis.utils.Messages;
20  import org.apache.axis.wsdl.symbolTable.BindingEntry;
21  import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
22  import org.apache.axis.wsdl.symbolTable.ServiceEntry;
23  import org.apache.axis.wsdl.symbolTable.SymbolTable;
24  import org.apache.axis.wsdl.toJava.Utils;
25  
26  import javax.wsdl.Binding;
27  import javax.wsdl.Port;
28  import javax.wsdl.Service;
29  import java.io.IOException;
30  import java.io.PrintWriter;
31  import java.util.Iterator;
32  import java.util.Map;
33  
34  /***
35   * This is Wsdl2java's service writer.  It writes the <serviceName>.java file.
36   *
37   * @author Ias (iasandcb@tmax.co.kr)
38   * @deprecated no more used by J2eeGeneratorFactory
39   */
40  public class J2eeServiceIfaceWriter extends J2eeClassWriter {
41      private Service service;
42      private SymbolTable symbolTable;
43  
44      /***
45       * Constructor.
46       */
47      protected J2eeServiceIfaceWriter(J2eeEmitter emitter,
48                                       ServiceEntry sEntry,
49                                       SymbolTable symbolTable) {
50          super(emitter, emitter.getJaxRpcMapper().getServiceInterfaceName(sEntry), "service");
51          this.service = sEntry.getService();
52          this.symbolTable = symbolTable;
53      } // ctor
54  
55      /***
56       * Returns "interface ".
57       */
58      protected String getClassText() {
59          return "interface ";
60      } // getClassString
61  
62      /***
63       * Returns "extends javax.xml.rpc.Service ".
64       */
65      protected String getExtendsText() {
66          return "extends javax.xml.rpc.Service ";
67      } // getExtendsText
68  
69      /***
70       * Write the body of the service file.
71       */
72      protected void writeFileBody(PrintWriter pw) throws IOException {
73          // output comments
74          writeComment(pw, service.getDocumentationElement(), false);
75  
76          // get ports
77          Map portMap = service.getPorts();
78          Iterator portIterator = portMap.values().iterator();
79  
80          // write a get method for each of the ports with a SOAP binding
81          while (portIterator.hasNext()) {
82              Port p = (Port) portIterator.next();
83              Binding binding = p.getBinding();
84              if (binding == null) {
85                  throw new IOException(Messages.getMessage("emitFailNoBinding01",
86                          new String[]{p.getName()}));
87              }
88              BindingEntry bEntry =
89                      symbolTable.getBindingEntry(binding.getQName());
90              if (bEntry == null) {
91                  throw new IOException(Messages.getMessage("emitFailNoBindingEntry01",
92                          new String[]{binding.getQName().toString()}));
93              }
94              PortTypeEntry ptEntry = symbolTable.getPortTypeEntry(binding.getPortType().getQName());
95              if (ptEntry == null) {
96                  throw new IOException(Messages.getMessage("emitFailNoPortType01",
97                          new String[]
98                          {binding.getPortType().getQName().toString()}));
99              }
100 
101             // If this isn't an SOAP binding, skip it
102             if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
103                 continue;
104             }
105 
106             // JSR 101 indicates that the name of the port used
107             // in the java code is the name of the wsdl:port.  It
108             // does not indicate what should occur if the 
109             // wsdl:port name is not a java identifier.  The
110             // TCK depends on the case-sensitivity being preserved,
111             // and the interop tests have port names that are not
112             // valid java identifiers.  Thus the following code.
113             //String portName = p.getName();
114             String portName = jaxRpcMapper.getPortName(p);
115             if (!JavaUtils.isJavaId(portName)) {
116                 portName = Utils.xmlNameToJavaClass(portName);
117             }
118 
119             // If there is not literal use, the interface name is the portType name.
120             // Otherwise it is the binding name.
121             //String bindingType = (String) bEntry.getDynamicVar(J2eeBindingWriter.INTERFACE_NAME);
122             String bindingType = jaxRpcMapper.getServiceEndpointInterfaceName(ptEntry, bEntry);
123             // Write out the get<PortName> methods
124             pw.println("    public java.lang.String get" + portName + "Address();");
125             pw.println();
126             pw.println("    public " + bindingType + " get" + portName
127                     + "() throws " + javax.xml.rpc.ServiceException.class.getName() + ";");
128             pw.println();
129             pw.println("    public " + bindingType + " get" + portName
130                     + "(java.net.URL portAddress) throws " + javax.xml.rpc.ServiceException.class.getName() + ";");
131         }
132     } // writeFileBody
133 
134 }