KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > generator > ews > wsdltoj2ee > writer > J2EEClientDeployWriter


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 /**
17  * JOnAS : Java(TM) OpenSource Application Server
18  * Copyright (C) 2004 Bull S.A.
19  * Contact: jonas-team@objectweb.org
20  *
21  * This library is free software; you can redistribute it and/or
22  * modify it under the terms of the GNU Lesser General Public
23  * License as published by the Free Software Foundation; either
24  * version 2.1 of the License, or any later version.
25  *
26  * This library is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29  * Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU Lesser General Public
32  * License along with this library; if not, write to the Free Software
33  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34  * USA
35  *
36  * --------------------------------------------------------------------------
37  * $Id: J2EEClientDeployWriter.java,v 1.4 2005/05/27 15:01:22 sauthieg Exp $
38  * --------------------------------------------------------------------------
39  */

40 package org.objectweb.jonas_ws.wsgen.generator.ews.wsdltoj2ee.writer;
41
42 import java.io.IOException JavaDoc;
43 import java.io.PrintWriter JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.List JavaDoc;
46
47 import javax.wsdl.Definition;
48 import javax.wsdl.Port;
49 import javax.wsdl.Service;
50 import javax.wsdl.extensions.UnknownExtensibilityElement;
51 import javax.wsdl.extensions.soap.SOAPBinding;
52 import javax.xml.namespace.QName JavaDoc;
53
54 import org.apache.axis.Constants;
55 import org.apache.axis.constants.Style;
56 import org.apache.axis.constants.Use;
57 import org.apache.axis.utils.Messages;
58 import org.apache.axis.wsdl.symbolTable.BindingEntry;
59 import org.apache.axis.wsdl.symbolTable.SymbolTable;
60 import org.apache.axis.wsdl.toJava.Emitter;
61 import org.apache.axis.wsdl.toJava.Utils;
62 import org.apache.geronimo.ews.ws4j2ee.context.webservices.client.interfaces.ServiceReferanceContext;
63 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFHandler;
64 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFInitParam;
65 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFSOAPHeader;
66
67 import org.objectweb.jonas_ws.wsgen.generator.ews.wsdltoj2ee.wscf.JOnASWSCFHandler;
68
69 /**
70  * This is Wsdl2java's deploy Writer. It writes the deploy.wsdd file.
71  * Based on J2eeDeployWriter from Ias
72  * (http://cvs.apache.org/viewcvs.cgi/ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/toWs/ws/J2eeDeployWriter.java?rev=1.13&view=markup)
73  */

74 public class J2EEClientDeployWriter extends JOnASDeployWriter {
75
76     /**
77      * WSDD Extension prefix
78      */

79     private static final String JavaDoc WSDD_PREFIX = "deploy-client-";
80
81     /**
82      * Constructor.
83      * @param emitter J2eeEmitter
84      * @param definition wsdl:definition
85      * @param symbolTable SymbolTable
86      */

87     public J2EEClientDeployWriter(Emitter emitter, Definition definition, SymbolTable symbolTable) {
88         super(emitter, definition, symbolTable);
89     }
90
91     /**
92      * Generate deploy.wsdd. Only generate it if the emitter is generating
93      * server-side mappings.
94      * @throws IOException When generation fails
95      */

96     public void generate() throws IOException JavaDoc {
97
98         if (!emitter.isServerSide()) {
99             super.generate();
100         }
101     }
102
103     /**
104      * Write out deployment and undeployment instructions for each WSDL service
105      * @param pw PrintWriter
106      * @throws IOException IOException
107      */

108     protected void writeDeployServices(PrintWriter JavaDoc pw) throws IOException JavaDoc {
109
110         int sRefIndex = getJonasWSContext().getServiceReferanceContextCount();
111         // should only have 1 service-ref
112
if (sRefIndex == 1) {
113
114             ServiceReferanceContext ctx = getJonasWSContext().getServiceReferanceContext(0);
115             QName JavaDoc desiredServiceQName = ctx.getServcieQName();
116
117             Service myService = getDefinition().getService(desiredServiceQName);
118
119             // Generate only if there is a Service
120
if (myService != null) {
121                 pw.println();
122                 pw.println(" <!-- " + Messages.getMessage("wsdlService00", myService.getQName().getLocalPart()) + " -->");
123                 pw.println();
124
125                 for (Iterator JavaDoc portIterator = myService.getPorts().values().iterator(); portIterator.hasNext();) {
126                     Port myPort = (Port) portIterator.next();
127                     BindingEntry bEntry = getSymbolTable().getBindingEntry(myPort.getBinding().getQName());
128
129                     // If this isn't an SOAP binding, skip it
130
if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
131                         continue;
132                     }
133
134                     writeDeployPort(pw, myPort, bEntry, ctx);
135                 }
136             }
137         }
138     }
139
140     /**
141      * Write out deployment and undeployment instructions for given WSDL port
142      * @param pw PrintWriter
143      * @param port wsdl:port
144      * @param bEntry Axis BindingEntry
145      * @param ctx ServiceReferanceContext
146      */

147     protected void writeDeployPort(PrintWriter JavaDoc pw, Port port, BindingEntry bEntry, ServiceReferanceContext ctx) {
148
149         String JavaDoc serviceName = port.getName();
150         boolean hasLiteral = bEntry.hasLiteral();
151         boolean hasMIME = Utils.hasMIME(bEntry);
152
153
154         Use use = Use.DEFAULT;
155         String JavaDoc styleStr = "";
156         Iterator JavaDoc iterator = bEntry.getBinding().getExtensibilityElements().iterator();
157
158         // iterate throught extensibilityElements of given Port's Binding
159
while (iterator.hasNext()) {
160             Object JavaDoc obj = iterator.next();
161
162             if (obj instanceof SOAPBinding) {
163                 use = Use.ENCODED;
164             } else if (obj instanceof UnknownExtensibilityElement) {
165
166                 // TODO After WSDL4J supports soap12, change this code
167
UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
168                 QName JavaDoc name = unkElement.getElementType();
169
170                 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("binding")) {
171                     use = Use.ENCODED;
172                 }
173             }
174         }
175
176         if (getSymbolTable().isWrapped()) {
177             styleStr = " style=\"" + Style.WRAPPED + "\"";
178             use = Use.LITERAL;
179         } else {
180             styleStr = " style=\"" + bEntry.getBindingStyle().getName() + "\"";
181             if (hasLiteral) {
182                 use = Use.LITERAL;
183             }
184         }
185
186         String JavaDoc useStr = " use=\"" + use + "\"";
187
188         pw.println(" <service name=\"" + serviceName + "\" " + styleStr + useStr + " provider=\"java:Noop\">");
189
190         // MIME attachments don't work with multiref, so turn it off.
191
if (hasMIME) {
192             pw.println(" <parameter name=\"sendMultiRefs\" value=\"false\"/>");
193         }
194         // force JAXRPC 1.1 Type Mapping
195
pw.println(" <parameter name=\"typeMappingVersion\" value=\"" + emitter.getTypeMappingVersion() + "\"/>");
196
197         //writeDeployBinding(pw, bEntry);
198
//writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME, use);
199

200         WSCFHandler[] handlers = ctx.getHandlers();
201         if (handlers != null && handlers.length != 0) {
202             pw.println(" <handlerInfoChain>");
203             for (int i = 0; i < handlers.length; i++) {
204                 writeHandlerForPort(pw, (JOnASWSCFHandler) handlers[i], port);
205             }
206             pw.println(" </handlerInfoChain>");
207         }
208         pw.println(" </service>");
209     }
210
211     /**
212      * Writes out a client-side handler
213      * @param pw PrintWriter
214      * @param handler EWS Handler description
215      * @param port wsdl:port
216      */

217     private void writeHandlerForPort(PrintWriter JavaDoc pw, JOnASWSCFHandler handler, Port port) {
218
219         /**
220          * If handler contains no port-names, add the handler
221          * else, check if the handler is applied to the current port
222          */

223         List JavaDoc ports = handler.getPortNames();
224         if (ports.isEmpty()) {
225             // handler applied for all ports
226
writeHandler(pw, handler);
227         } else if (ports.contains(port.getName())) {
228             // handler applied for current port
229
writeHandler(pw, handler);
230         }
231     }
232     /**
233      * Writes out a client-side handler
234      * @param pw PrintWriter
235      * @param handler EWS Handler description
236      */

237     private void writeHandler(PrintWriter JavaDoc pw, JOnASWSCFHandler handler) {
238
239         pw.println(" <handlerInfo classname=\"" + handler.getHandlerClass() + "\">");
240         WSCFInitParam[] param = handler.getInitParam();
241         for (int i = 0; i < param.length; i++) {
242             pw.println(" <parameter name=\"" + param[i].getParamName() + "\" value=\"" + param[i].getParamValue()
243                     + "\"/>");
244         }
245         WSCFSOAPHeader[] headers = handler.getSoapHeader();
246         for (int i = 0; i < headers.length; i++) {
247             pw.println(" <header xmlns:ns=\"" + headers[i].getNamespaceURI() + "\" qname=\"ns:" + headers[i].getLocalpart()
248                     + "\"/>");
249         }
250         pw.println(" </handlerInfo>");
251         String JavaDoc[] roles = handler.getSoapRole();
252         for (int i = 0; i < roles.length; i++) {
253             pw.println(" <role soapActorName=\"" + roles[i] + "\"/>");
254         }
255     }
256
257     /**
258      * @return Returns the filename prefix
259      */

260     protected String JavaDoc getPrefix() {
261         return WSDD_PREFIX;
262     }
263 }
264
Popular Tags