KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > wsdl > toJava > JavaServiceIfaceWriter


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.wsdl.toJava;
56
57 import org.jboss.axis.utils.JavaUtils;
58 import org.jboss.axis.utils.Messages;
59 import org.jboss.axis.wsdl.symbolTable.BindingEntry;
60 import org.jboss.axis.wsdl.symbolTable.PortTypeEntry;
61 import org.jboss.axis.wsdl.symbolTable.ServiceEntry;
62 import org.jboss.axis.wsdl.symbolTable.SymbolTable;
63
64 import javax.wsdl.Binding;
65 import javax.wsdl.Port;
66 import javax.wsdl.Service;
67 import java.io.IOException JavaDoc;
68 import java.io.PrintWriter JavaDoc;
69 import java.util.Iterator JavaDoc;
70 import java.util.Map JavaDoc;
71
72 /**
73  * This is Wsdl2java's service writer. It writes the <serviceName>.java file.
74  */

75 public class JavaServiceIfaceWriter extends JavaClassWriter
76 {
77    private Service service;
78    private SymbolTable symbolTable;
79
80    /**
81     * Constructor.
82     */

83    protected JavaServiceIfaceWriter(Emitter emitter,
84                                     ServiceEntry sEntry,
85                                     SymbolTable symbolTable)
86    {
87       super(emitter, sEntry.getName(), "service");
88       this.service = sEntry.getService();
89       this.symbolTable = symbolTable;
90    } // ctor
91

92    /**
93     * Returns "interface ".
94     */

95    protected String JavaDoc getClassText()
96    {
97       return "interface ";
98    } // getClassString
99

100    /**
101     * Returns "extends javax.xml.rpc.Service ".
102     */

103    protected String JavaDoc getExtendsText()
104    {
105       return "extends javax.xml.rpc.Service ";
106    } // getExtendsText
107

108    /**
109     * Write the body of the service file.
110     */

111    protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc
112    {
113       // output comments
114
writeComment(pw, service.getDocumentationElement());
115
116       // get ports
117
Map JavaDoc portMap = service.getPorts();
118       Iterator JavaDoc portIterator = portMap.values().iterator();
119
120       // write a get method for each of the ports with a SOAP binding
121
while (portIterator.hasNext())
122       {
123          Port p = (Port)portIterator.next();
124          Binding binding = p.getBinding();
125          if (binding == null)
126          {
127             throw new IOException JavaDoc(Messages.getMessage("emitFailNoBinding01",
128                     new String JavaDoc[]{p.getName()}));
129          }
130
131          BindingEntry bEntry =
132                  symbolTable.getBindingEntry(binding.getQName());
133          if (bEntry == null)
134          {
135             throw new IOException JavaDoc(Messages.getMessage("emitFailNoBindingEntry01",
136                     new String JavaDoc[]{binding.getQName().toString()}));
137          }
138
139          PortTypeEntry ptEntry = symbolTable.getPortTypeEntry(binding.getPortType().getQName());
140          if (ptEntry == null)
141          {
142             throw new IOException JavaDoc(Messages.getMessage("emitFailNoPortType01",
143                     new String JavaDoc[]
144                     {binding.getPortType().getQName().toString()}));
145          }
146
147          // If this isn't an SOAP binding, skip it
148
if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP)
149          {
150             continue;
151          }
152
153          // JSR 101 indicates that the name of the port used
154
// in the java code is the name of the wsdl:port. It
155
// does not indicate what should occur if the
156
// wsdl:port name is not a java identifier. The
157
// TCK depends on the case-sensitivity being preserved,
158
// and the interop tests have port names that are not
159
// valid java identifiers. Thus the following code.
160
String JavaDoc portName = p.getName();
161          if (!JavaUtils.isJavaId(portName))
162          {
163             portName = Utils.xmlNameToJavaClass(portName);
164          }
165
166          // If there is not literal use, the interface name is the portType name.
167
// Otherwise it is the binding name.
168
String JavaDoc bindingType = (String JavaDoc)bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME);
169
170          // Write out the get<PortName> methods
171
pw.println(" public java.lang.String get" + portName + "Address();");
172          pw.println();
173          pw.println(" public " + bindingType + " get" + portName
174                  + "() throws " + javax.xml.rpc.ServiceException JavaDoc.class.getName() + ";");
175          pw.println();
176          pw.println(" public " + bindingType + " get" + portName
177                  + "(java.net.URL portAddress) throws " + javax.xml.rpc.ServiceException JavaDoc.class.getName() + ";");
178       }
179    } // writeFileBody
180

181 } // class JavaServiceIfaceWriter
182
Popular Tags