001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /**
017: * JOnAS : Java(TM) OpenSource Application Server
018: * Copyright (C) 2004 Bull S.A.
019: * Contact: jonas-team@objectweb.org
020: *
021: * This library is free software; you can redistribute it and/or
022: * modify it under the terms of the GNU Lesser General Public
023: * License as published by the Free Software Foundation; either
024: * version 2.1 of the License, or any later version.
025: *
026: * This library is distributed in the hope that it will be useful,
027: * but WITHOUT ANY WARRANTY; without even the implied warranty of
028: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
029: * Lesser General Public License for more details.
030: *
031: * You should have received a copy of the GNU Lesser General Public
032: * License along with this library; if not, write to the Free Software
033: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
034: * USA
035: *
036: * --------------------------------------------------------------------------
037: * $Id: J2EEServerDeployWriter.java 6860 2005-05-27 15:01:25Z sauthieg $
038: * --------------------------------------------------------------------------
039: */package org.objectweb.jonas_ws.wsgen.generator.ews.wsdltoj2ee.writer;
040:
041: import java.io.IOException;
042: import java.io.PrintWriter;
043: import java.util.ArrayList;
044: import java.util.HashSet;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Map;
048:
049: import javax.wsdl.Binding;
050: import javax.wsdl.BindingOperation;
051: import javax.wsdl.Definition;
052: import javax.wsdl.Operation;
053: import javax.wsdl.OperationType;
054: import javax.wsdl.Port;
055: import javax.wsdl.Service;
056: import javax.wsdl.extensions.UnknownExtensibilityElement;
057: import javax.wsdl.extensions.soap.SOAPBinding;
058: import javax.xml.namespace.QName;
059:
060: import org.apache.axis.Constants;
061: import org.apache.axis.constants.Scope;
062: import org.apache.axis.constants.Style;
063: import org.apache.axis.constants.Use;
064: import org.apache.axis.deployment.wsdd.WSDDConstants;
065: import org.apache.axis.utils.JavaUtils;
066: import org.apache.axis.utils.Messages;
067: import org.apache.axis.wsdl.symbolTable.BindingEntry;
068: import org.apache.axis.wsdl.symbolTable.Parameters;
069: import org.apache.axis.wsdl.symbolTable.SymbolTable;
070: import org.apache.axis.wsdl.toJava.Emitter;
071: import org.apache.axis.wsdl.toJava.Utils;
072:
073: import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
074:
075: import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
076: import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
077: import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
078:
079: /**
080: * This is Wsdl2java's deploy Writer. It writes the server-deploy-XX.wsdd file.
081: * Based on J2eeDeployWriter from Ias
082: * (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)
083: */
084: public class J2EEServerDeployWriter extends JOnASDeployWriter {
085:
086: /**
087: * WSDD Extension prefix
088: */
089: private static final String WSDD_PREFIX = "deploy-server-";
090:
091: /**
092: * Axis parameter name for SE interface name
093: */
094: private static final String SERVICE_ENDPOINT_INTERFACE_NAME = "serviceEndpointInterfaceName";
095:
096: /**
097: * Axis parameter name for SE jndi name
098: */
099: private static final String SERVICE_ENDPOINT_JNDI_NAME = "serviceEndpointJndiName";
100:
101: /**
102: * Constructor.
103: * @param emitter J2EEEmitter
104: * @param definition Definition
105: * @param symbolTable SymbolTable
106: */
107: public J2EEServerDeployWriter(Emitter emitter,
108: Definition definition, SymbolTable symbolTable) {
109: super (emitter, definition, symbolTable);
110: } // ctor
111:
112: /**
113: * Write out deployment and undeployment instructions for each WSDL service
114: * @param pw PrintWriter
115: * @throws IOException when services cannot be created
116: */
117: protected void writeDeployServices(PrintWriter pw)
118: throws IOException {
119:
120: // deploy the ports on each service
121: Map serviceMap = getDefinition().getServices();
122: ServiceDesc desc = getJonasWSContext().getServiceDesc();
123:
124: for (Iterator mapIterator = serviceMap.values().iterator(); mapIterator
125: .hasNext();) {
126: Service myService = (Service) mapIterator.next();
127:
128: pw.println();
129: pw.println(" <!-- "
130: + Messages.getMessage("wsdlService00", myService
131: .getQName().getLocalPart()) + " -->");
132: pw.println();
133:
134: for (Iterator portIterator = myService.getPorts().values()
135: .iterator(); portIterator.hasNext();) {
136: Port myPort = (Port) portIterator.next();
137: BindingEntry bEntry = getSymbolTable().getBindingEntry(
138: myPort.getBinding().getQName());
139:
140: // If this isn't an SOAP binding, skip it
141: if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
142: continue;
143: }
144:
145: PortComponentDesc portDesc = findPortComponentDesc(
146: desc, myPort);
147:
148: if (portDesc != null) {
149: // write ports described by the current ServiceDesc
150: writeDeployPort(pw, myService, bEntry, portDesc);
151: }
152: }
153: }
154: } // writeDeployServices
155:
156: /**
157: * @param desc JOnAS Service Description
158: * @param myPort wsdl:port
159: * @return Returns the JOnAS PortComponentDesc associated with the given wsdl:port
160: */
161: private static PortComponentDesc findPortComponentDesc(
162: ServiceDesc desc, Port myPort) {
163:
164: PortComponentDesc port = null;
165: List ports = desc.getPortComponents();
166: for (Iterator i = ports.iterator(); i.hasNext() && port == null;) {
167: PortComponentDesc pcd = (PortComponentDesc) i.next();
168: if (pcd.getQName().getLocalPart().equals(myPort.getName())) {
169: port = pcd;
170: }
171: }
172: return port;
173: }
174:
175: /**
176: * Write out deployment and undeployment instructions for given WSDL port
177: * @param pw PrintWriter
178: * @param service wsdl:service
179: * @param bEntry BindingEntry
180: * @param portComponentDesc JOnAS Port representation
181: * @throws IOException IOException
182: */
183: protected void writeDeployPort(PrintWriter pw, Service service,
184: BindingEntry bEntry, PortComponentDesc portComponentDesc)
185: throws IOException {
186:
187: String serviceName = portComponentDesc.getServiceName();
188: boolean hasLiteral = bEntry.hasLiteral();
189: boolean hasMIME = Utils.hasMIME(bEntry);
190: String prefix = WSDDConstants.NS_PREFIX_WSDD_JAVA;
191: String styleStr = "";
192: Iterator iterator = bEntry.getBinding()
193: .getExtensibilityElements().iterator();
194:
195: // iterate throught extensibilityElements of given Port's Binding
196: while (iterator.hasNext()) {
197: Object obj = iterator.next();
198:
199: if (obj instanceof SOAPBinding) {
200: use = Use.ENCODED;
201: } else if (obj instanceof UnknownExtensibilityElement) {
202:
203: // TODO After WSDL4J supports soap12, change this code
204: UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
205: QName name = unkElement.getElementType();
206:
207: if (name.getNamespaceURI().equals(
208: Constants.URI_WSDL12_SOAP)
209: && name.getLocalPart().equals("binding")) {
210: use = Use.ENCODED;
211: }
212: }
213: }
214:
215: if (getSymbolTable().isWrapped()) {
216: styleStr = " style=\"" + Style.WRAPPED + "\"";
217: use = Use.LITERAL;
218: } else {
219: styleStr = " style=\"" + bEntry.getBindingStyle().getName()
220: + "\"";
221:
222: if (hasLiteral) {
223: use = Use.LITERAL;
224: }
225: }
226:
227: String useStr = " use=\"" + use + "\"";
228:
229: if (portComponentDesc.hasBeanImpl()) {
230: pw.println(" <service name=\"" + serviceName
231: + "\" provider=\"" + prefix + ":JOnASEJB\""
232: + styleStr + useStr + ">");
233:
234: SSBPortComponentDesc ssbPCD = (SSBPortComponentDesc) portComponentDesc;
235:
236: pw.println(" <parameter name=\""
237: + SERVICE_ENDPOINT_INTERFACE_NAME + "\" value=\""
238: + ssbPCD.getServiceEndpointInterface().getName()
239: + "\"/>");
240: pw.println(" <parameter name=\""
241: + SERVICE_ENDPOINT_JNDI_NAME
242: + "\" value=\""
243: + ssbPCD.getSessionStatelessDesc()
244: .getJndiServiceEndpointName() + "\"/>");
245:
246: } else {
247: pw.println(" <service name=\"" + serviceName
248: + "\" provider=\"" + prefix + ":RPC\"" + styleStr
249: + useStr + ">");
250: pw.println(" <parameter name=\"className\" value=\""
251: + portComponentDesc.getSIBClassname() + "\"/>");
252:
253: }
254:
255: pw
256: .println(" <parameter name=\"wsdlTargetNamespace\" value=\""
257: + service.getQName().getNamespaceURI() + "\"/>");
258: pw
259: .println(" <parameter name=\"wsdlServiceElement\" value=\""
260: + service.getQName().getLocalPart() + "\"/>");
261: pw.println(" <parameter name=\"wsdlServicePort\" value=\""
262: + serviceName + "\"/>");
263:
264: // MIME attachments don't work with multiref, so turn it off.
265: if (hasMIME) {
266: pw
267: .println(" <parameter name=\"sendMultiRefs\" value=\"false\"/>");
268: }
269:
270: writeDeployBinding(pw, bEntry);
271: writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME,
272: use);
273:
274: List handlers = portComponentDesc.getHandlers();
275: if (!handlers.isEmpty()) {
276: pw.println(" <handlerInfoChain>");
277: for (Iterator i = handlers.iterator(); i.hasNext();) {
278: writeHandler(pw, (HandlerDesc) i.next());
279: }
280: pw.println(" </handlerInfoChain>");
281: }
282: pw.println(" </service>");
283: }
284:
285: /**
286: * Write out deployment instructions for given WSDL binding
287: * @param pw PrintWriter
288: * @param bEntry BindingEntry
289: * @throws IOException IOException
290: */
291: protected void writeDeployBinding(PrintWriter pw,
292: BindingEntry bEntry) throws IOException {
293:
294: Binding binding = bEntry.getBinding();
295:
296: pw.println(" <parameter name=\"wsdlPortType\" value=\""
297: + binding.getPortType().getQName().getLocalPart()
298: + "\"/>");
299: // force JAXRPC 1.1 Type Mapping
300: pw
301: .println(" <parameter name=\"typeMappingVersion\" value=\""
302: + emitter.getTypeMappingVersion() + "\"/>");
303:
304: HashSet allowedMethods = new HashSet();
305:
306: if (!emitter.isSkeletonWanted()) {
307: Iterator operationsIterator = binding
308: .getBindingOperations().iterator();
309:
310: for (; operationsIterator.hasNext();) {
311: BindingOperation bindingOper = (BindingOperation) operationsIterator
312: .next();
313: Operation operation = bindingOper.getOperation();
314: OperationType type = operation.getStyle();
315: String javaOperName = JavaUtils.xmlNameToJava(operation
316: .getName());
317:
318: // These operation types are not supported. The signature
319: // will be a string stating that fact.
320: if ((type == OperationType.NOTIFICATION)
321: || (type == OperationType.SOLICIT_RESPONSE)) {
322: continue;
323: }
324:
325: allowedMethods.add(javaOperName);
326:
327: // We pass "" as the namespace argument because we're just
328: // interested in the return type for now.
329: Parameters params = getSymbolTable()
330: .getOperationParameters(operation, "", bEntry);
331:
332: if (params != null) {
333:
334: // Get the operation QName
335: QName elementQName = Utils.getOperationQName(
336: bindingOper, bEntry, getSymbolTable());
337:
338: // Get the operation's return QName and type
339: QName returnQName = null;
340: QName returnType = null;
341:
342: if (params.returnParam != null) {
343: returnQName = params.returnParam.getQName();
344: returnType = Utils
345: .getXSIType(params.returnParam);
346: }
347:
348: // Get the operations faults
349: Map faultMap = bEntry.getFaults();
350: ArrayList faults = null;
351:
352: if (faultMap != null) {
353: faults = (ArrayList) faultMap.get(bindingOper);
354: }
355:
356: String soapAction = Utils
357: .getOperationSOAPAction(bindingOper);
358:
359: // Write the operation metadata
360: writeOperation(pw, javaOperName, elementQName,
361: returnQName, returnType, params, faults,
362: soapAction);
363: }
364: }
365: }
366:
367: pw.print(" <parameter name=\"allowedMethods\" value=\"");
368:
369: if (allowedMethods.isEmpty()) {
370: pw.println("*\"/>");
371: } else {
372: boolean first = true;
373:
374: for (Iterator i = allowedMethods.iterator(); i.hasNext();) {
375: String method = (String) i.next();
376:
377: if (first) {
378: pw.print(method);
379:
380: first = false;
381: } else {
382: pw.print(" " + method);
383: }
384: }
385:
386: pw.println("\"/>");
387: }
388:
389: Scope scope = emitter.getScope();
390:
391: if (scope != null) {
392: pw.println(" <parameter name=\"scope\" value=\""
393: + scope.getName() + "\"/>");
394: }
395: }
396:
397: /**
398: * @param pw PrintWriter
399: * @param handler the server Handler to write
400: */
401: protected void writeHandler(PrintWriter pw, HandlerDesc handler) {
402: pw.println(" <handlerInfo classname=\""
403: + handler.getHandlerClassName() + "\">");
404: Map params = handler.getInitParams();
405: for (Iterator i = params.keySet().iterator(); i.hasNext();) {
406: String pName = (String) i.next();
407: pw.println(" <parameter name=\"" + pName
408: + "\" value=\"" + params.get(pName) + "\"/>");
409: }
410: List headers = handler.getSOAPHeaders();
411: for (Iterator i = headers.iterator(); i.hasNext();) {
412: QName sh = (QName) i.next();
413: pw.println(" <header xmlns:ns=\""
414: + sh.getNamespaceURI() + "\" qname=\"ns:"
415: + sh.getLocalPart() + "\"/>");
416: }
417: pw.println(" </handlerInfo>");
418: List roles = handler.getSOAPRoles();
419: for (Iterator i = roles.iterator(); i.hasNext();) {
420: String role = (String) i.next();
421: pw.println(" <role soapActorName=\"" + role + "\"/>");
422: }
423: }
424:
425: /**
426: * @return Returns "deploy-server-"
427: */
428: protected String getPrefix() {
429: return WSDD_PREFIX;
430: }
431:
432: }
|