View Javadoc

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