001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.wsif.wsdl.extensions.ejb;
059:
060: import java.io.Serializable;
061:
062: import javax.wsdl.extensions.ExtensionDeserializer;
063: import javax.wsdl.extensions.ExtensionRegistry;
064: import javax.wsdl.extensions.ExtensionSerializer;
065: import javax.xml.namespace.QName;
066:
067: import org.apache.wsif.logging.Trc;
068:
069: import com.ibm.wsdl.Constants;
070: import com.ibm.wsdl.util.StringUtils;
071: import com.ibm.wsdl.util.xml.DOMUtils;
072:
073: /**
074: * @author Gerhard Pfau <gpfau@de.ibm.com>
075: * @author Ant Elder <antelder@apache.org>
076: * @author Owen Burroughs <owenb@pache.org>
077: * @author Mark Whitlock <whitlock@apache.org>
078: */
079: public class EJBBindingSerializer implements ExtensionSerializer,
080: ExtensionDeserializer, Serializable {
081:
082: private static final long serialVersionUID = 1L;
083:
084: public void marshall(Class parentType, QName elementType,
085: javax.wsdl.extensions.ExtensibilityElement extension,
086: java.io.PrintWriter pw, javax.wsdl.Definition def,
087: javax.wsdl.extensions.ExtensionRegistry extReg)
088: throws javax.wsdl.WSDLException {
089: Trc.entry(this , parentType, elementType, extension, pw, def,
090: extReg);
091: if (extension == null) {
092: Trc.exit();
093: return;
094: }
095:
096: if (extension instanceof EJBBinding) {
097: EJBBinding ejbBinding = (EJBBinding) extension;
098: pw.print(" <ejb:binding");
099:
100: Boolean required = extension.getRequired();
101: if (required != null) {
102: DOMUtils.printQualifiedAttribute(
103: Constants.Q_ATTR_REQUIRED, required.toString(),
104: def, pw);
105: }
106:
107: pw.println("/>");
108: } else if (extension instanceof EJBOperation) {
109: EJBOperation ejbOperation = (EJBOperation) extension;
110: pw.print(" <ejb:operation");
111:
112: if (ejbOperation.getMethodName() != null) {
113: DOMUtils.printAttribute("methodName", ejbOperation
114: .getMethodName(), pw);
115: }
116:
117: if (ejbOperation.getEjbInterface() != null) {
118: DOMUtils.printAttribute("interface", ejbOperation
119: .getEjbInterface(), pw);
120: }
121:
122: if (ejbOperation.getParameterOrder() != null) {
123: DOMUtils.printAttribute("parameterOrder", StringUtils
124: .getNMTokens(ejbOperation.getParameterOrder()),
125: pw);
126: }
127:
128: if (ejbOperation.getReturnPart() != null) {
129: DOMUtils.printAttribute("returnPart", ejbOperation
130: .getReturnPart(), pw);
131: }
132:
133: Boolean required = extension.getRequired();
134: if (required != null) {
135: DOMUtils.printQualifiedAttribute(
136: Constants.Q_ATTR_REQUIRED, required.toString(),
137: def, pw);
138: }
139:
140: pw.println("/>");
141: } else if (extension instanceof EJBAddress) {
142: EJBAddress ejbAddress = (EJBAddress) extension;
143: pw.print(" <ejb:address");
144:
145: if (ejbAddress.getClassName() != null) {
146: DOMUtils.printAttribute("className", ejbAddress
147: .getClassName(), pw);
148: }
149:
150: if (ejbAddress.getArchive() != null) {
151: DOMUtils.printAttribute("archive", ejbAddress
152: .getArchive(), pw);
153: }
154:
155: if (ejbAddress.getClassLoader() != null) {
156: DOMUtils.printAttribute("classLoader", ejbAddress
157: .getClassLoader(), pw);
158: }
159:
160: if (ejbAddress.getJndiName() != null) {
161: DOMUtils.printAttribute("jndiName", ejbAddress
162: .getJndiName(), pw);
163: }
164:
165: if (ejbAddress.getJndiProviderURL() != null) {
166: DOMUtils.printAttribute("jndiProviderURL", ejbAddress
167: .getJndiProviderURL(), pw);
168: }
169:
170: if (ejbAddress.getInitialContextFactory() != null) {
171: DOMUtils.printAttribute("initialContextFactory",
172: ejbAddress.getInitialContextFactory(), pw);
173: }
174:
175: Boolean required = extension.getRequired();
176: if (required != null) {
177: DOMUtils.printQualifiedAttribute(
178: Constants.Q_ATTR_REQUIRED, required.toString(),
179: def, pw);
180: }
181:
182: pw.println("/>");
183: }
184: Trc.exit();
185: }
186:
187: /**
188: * Registers the serializer.
189: */
190: public void registerSerializer(ExtensionRegistry registry) {
191: Trc.entry(this , registry);
192: // binding
193: registry.registerSerializer(javax.wsdl.Binding.class,
194: EJBBindingConstants.Q_ELEM_EJB_BINDING, this );
195: registry.registerDeserializer(javax.wsdl.Binding.class,
196: EJBBindingConstants.Q_ELEM_EJB_BINDING, this );
197: registry.mapExtensionTypes(javax.wsdl.Binding.class,
198: EJBBindingConstants.Q_ELEM_EJB_BINDING,
199: EJBBinding.class);
200:
201: // operation
202: registry.registerSerializer(javax.wsdl.BindingOperation.class,
203: EJBBindingConstants.Q_ELEM_EJB_OPERATION, this );
204: registry.registerDeserializer(
205: javax.wsdl.BindingOperation.class,
206: EJBBindingConstants.Q_ELEM_EJB_OPERATION, this );
207: registry.mapExtensionTypes(javax.wsdl.BindingOperation.class,
208: EJBBindingConstants.Q_ELEM_EJB_OPERATION,
209: EJBOperation.class);
210:
211: // address
212: registry.registerSerializer(javax.wsdl.Port.class,
213: EJBBindingConstants.Q_ELEM_EJB_ADDRESS, this );
214: registry.registerDeserializer(javax.wsdl.Port.class,
215: EJBBindingConstants.Q_ELEM_EJB_ADDRESS, this );
216: registry.mapExtensionTypes(javax.wsdl.Port.class,
217: EJBBindingConstants.Q_ELEM_EJB_ADDRESS,
218: EJBAddress.class);
219: Trc.exit();
220: }
221:
222: public javax.wsdl.extensions.ExtensibilityElement unmarshall(
223: Class parentType, javax.xml.namespace.QName elementType,
224: org.w3c.dom.Element el, javax.wsdl.Definition def,
225: javax.wsdl.extensions.ExtensionRegistry extReg)
226: throws javax.wsdl.WSDLException {
227: Trc.entry(this , parentType, elementType, el, def, extReg);
228:
229: javax.wsdl.extensions.ExtensibilityElement returnValue = null;
230:
231: if (EJBBindingConstants.Q_ELEM_EJB_BINDING.equals(elementType)) {
232: EJBBinding ejbBinding = new EJBBinding();
233: Trc.exit(ejbBinding);
234: return ejbBinding;
235: } else if (EJBBindingConstants.Q_ELEM_EJB_OPERATION
236: .equals(elementType)) {
237: EJBOperation ejbOperation = new EJBOperation();
238:
239: String methodName = DOMUtils.getAttribute(el, "methodName");
240:
241: if (methodName != null) {
242: ejbOperation.setMethodName(methodName);
243: }
244:
245: String ejbInterface = DOMUtils
246: .getAttribute(el, "interface");
247: if (ejbInterface != null) {
248: ejbOperation.setEjbInterface(ejbInterface);
249: }
250:
251: String parameterOrder = DOMUtils.getAttribute(el,
252: "parameterOrder");
253: if (parameterOrder != null) {
254: ejbOperation.setParameterOrder(parameterOrder);
255: }
256:
257: String returnPart = DOMUtils.getAttribute(el, "returnPart");
258: if (returnPart != null) {
259: ejbOperation.setReturnPart(returnPart);
260: }
261: Trc.exit(ejbOperation);
262: return ejbOperation;
263: } else if (EJBBindingConstants.Q_ELEM_EJB_ADDRESS
264: .equals(elementType)) {
265: EJBAddress ejbAddress = new EJBAddress();
266:
267: String className = DOMUtils.getAttribute(el, "className");
268: if (className != null) {
269: ejbAddress.setClassName(className);
270: }
271:
272: String archive = DOMUtils.getAttribute(el, "archive");
273: if (archive != null) {
274: ejbAddress.setArchive(archive);
275: }
276:
277: String classLoader = DOMUtils.getAttribute(el,
278: "classLoader");
279: if (classLoader != null) {
280: ejbAddress.setClassLoader(classLoader);
281: }
282:
283: String jndiName = DOMUtils.getAttribute(el, "jndiName");
284: if (jndiName != null) {
285: ejbAddress.setJndiName(jndiName);
286: }
287:
288: String jndiProviderURL = DOMUtils.getAttribute(el,
289: "jndiProviderURL");
290: if (jndiProviderURL != null) {
291: ejbAddress.setJndiProviderURL(jndiProviderURL);
292: }
293:
294: String icf = DOMUtils.getAttribute(el,
295: "initialContextFactory");
296: if (icf != null) {
297: ejbAddress.setInitialContextFactory(icf);
298: }
299: Trc.exit(ejbAddress);
300: return ejbAddress;
301: }
302: Trc.exit(returnValue);
303: return returnValue;
304: }
305: }
|