View Javadoc

1   /*
2    * Copyright  1999-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   */
17  
18  package org.apache.axis.message.addressing.tools.wsdl;
19  
20  import org.apache.axis.utils.JavaUtils;
21  import org.apache.axis.utils.Messages;
22  import org.apache.axis.utils.WSDLUtils;
23  import org.apache.axis.wsdl.symbolTable.BindingEntry;
24  import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
25  import org.apache.axis.wsdl.symbolTable.ServiceEntry;
26  import org.apache.axis.wsdl.symbolTable.SymbolTable;
27  import org.apache.axis.wsdl.toJava.Emitter;
28  import org.apache.axis.wsdl.toJava.JavaBindingWriter;
29  import org.apache.axis.wsdl.toJava.JavaClassWriter;
30  import org.apache.axis.wsdl.toJava.Utils;
31  
32  import javax.wsdl.Binding;
33  import javax.wsdl.Port;
34  import javax.wsdl.Service;
35  
36  import java.io.IOException;
37  import java.io.PrintWriter;
38  
39  import java.net.MalformedURLException;
40  import java.net.URL;
41  
42  import java.util.Iterator;
43  import java.util.Map;
44  import java.util.Vector;
45  
46  /***
47   *
48   * @author Jarek Gawor (gawor@mcs.anl.gov)
49   */
50  public class JavaAddressingServiceIfaceImplWriter
51      extends JavaClassWriter {
52  
53      private ServiceEntry sEntry;
54      private SymbolTable symbolTable;
55  
56      protected JavaAddressingServiceIfaceImplWriter(
57          Emitter emitter,
58          ServiceEntry sEntry,
59          SymbolTable symbolTable
60      ) {
61          super(emitter, sEntry.getName() + "Addressing", "service");
62          this.sEntry = sEntry;
63          this.symbolTable = symbolTable;
64      }
65  
66      // ctor
67      protected String getExtendsText() {
68  	return "extends " + this.sEntry.getName();
69      }
70  
71      protected String getClassText() {
72          return "interface ";
73      } 
74  
75      /***
76       * Returns "implements <serviceInterface>".
77       */
78      protected String getImplementsText() {
79          return " ";
80      }
81  
82      /***
83       * Write the body of the service file.
84       */
85      protected void writeFileBody(PrintWriter pw) throws IOException {
86          Service service = sEntry.getService();
87  
88          // get ports
89          Map portMap = service.getPorts();
90          Iterator portIterator = portMap.values().iterator();
91  
92          // write a get method for each of the ports with a SOAP binding
93          while (portIterator.hasNext()) {
94              Port p = (Port) portIterator.next();
95              Binding binding = p.getBinding();
96  
97              if (binding == null) {
98                  throw new IOException(
99                      Messages.getMessage(
100                         "emitFailNoBinding01", new String[] { p.getName() }
101                     )
102                 );
103             }
104 
105             BindingEntry bEntry =
106                 symbolTable.getBindingEntry(binding.getQName());
107 
108             if (bEntry == null) {
109                 throw new IOException(
110                     Messages.getMessage(
111                         "emitFailNoBindingEntry01",
112                         new String[] { binding.getQName().toString() }
113                     )
114                 );
115             }
116 
117             PortTypeEntry ptEntry =
118                 symbolTable.getPortTypeEntry(binding.getPortType().getQName());
119 
120             if (ptEntry == null) {
121                 throw new IOException(
122                     Messages.getMessage(
123                         "emitFailNoPortType01",
124                         new String[] { binding.getPortType().getQName()
125                                               .toString() }
126                     )
127                 );
128             }
129 
130             // If this isn't an SOAP binding, skip it
131             if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
132                 continue;
133             }
134 
135             String portName = p.getName();
136 
137             if (!JavaUtils.isJavaId(portName)) {
138                 portName = Utils.xmlNameToJavaClass(portName);
139             }
140 
141             String stubClass = bEntry.getName() + "Stub";
142 
143             String bindingType =
144                 (String) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME);
145 
146             pw.println(
147                 "    public " + bindingType + " get" + portName +
148                 "(org.apache.axis.message.addressing.EndpointReferenceType reference) " +
149                 "throws javax.xml.rpc.ServiceException;"
150             );
151 	    pw.println();
152         }
153 
154         pw.println();
155     }
156     // writeFileBody
157 }
158 
159 
160 // class JavaServiceImplWriter