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.java;
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 Owen Burroughs <owenb@apache.org>
076: * @author Ant Elder <antelder@apache.org>
077: * @author Jeremy Hughes <hughesj@apache.org>
078: * @author Mark Whitlock <whitlock@apache.org>
079: */
080: public class JavaBindingSerializer implements ExtensionSerializer,
081: ExtensionDeserializer, Serializable {
082:
083: private static final long serialVersionUID = 1L;
084:
085: public void marshall(Class parentType, QName elementType,
086: javax.wsdl.extensions.ExtensibilityElement extension,
087: java.io.PrintWriter pw, javax.wsdl.Definition def,
088: javax.wsdl.extensions.ExtensionRegistry extReg)
089: throws javax.wsdl.WSDLException {
090: Trc.entry(this , parentType, elementType, extension, pw, def,
091: extReg);
092:
093: // CHANGE HERE: Adjust with unmarshall() !!!
094:
095: if (extension == null) {
096: Trc.exit();
097: return;
098: }
099:
100: if (extension instanceof JavaBinding) {
101: JavaBinding javaBinding = (JavaBinding) extension;
102: pw.print(" <java:binding");
103:
104: Boolean required = extension.getRequired();
105: if (required != null) {
106: DOMUtils.printQualifiedAttribute(
107: Constants.Q_ATTR_REQUIRED, required.toString(),
108: def, pw);
109: }
110:
111: pw.println("/>");
112: } else if (extension instanceof JavaOperation) {
113: JavaOperation javaOperation = (JavaOperation) extension;
114: pw.print(" <java:operation");
115:
116: if (javaOperation.getMethodName() != null) {
117: DOMUtils.printAttribute("methodName", javaOperation
118: .getMethodName(), pw);
119: }
120:
121: if (javaOperation.getMethodType() != null) {
122: DOMUtils.printAttribute("methodType", javaOperation
123: .getMethodType(), pw);
124: }
125:
126: if (javaOperation.getParameterOrder() != null) {
127: DOMUtils.printAttribute("parameterOrder",
128: StringUtils.getNMTokens(javaOperation
129: .getParameterOrder()), pw);
130: }
131:
132: if (javaOperation.getReturnPart() != null) {
133: DOMUtils.printAttribute("returnPart", javaOperation
134: .getReturnPart(), pw);
135: }
136:
137: Boolean required = extension.getRequired();
138: if (required != null) {
139: DOMUtils.printQualifiedAttribute(
140: Constants.Q_ATTR_REQUIRED, required.toString(),
141: def, pw);
142: }
143:
144: pw.println("/>");
145: } else if (extension instanceof JavaAddress) {
146: JavaAddress javaAddress = (JavaAddress) extension;
147: pw.print(" <java:address");
148:
149: if (javaAddress.getClassName() != null) {
150: DOMUtils.printAttribute("className", javaAddress
151: .getClassName(), pw);
152: }
153:
154: if (javaAddress.getClassPath() != null) {
155: DOMUtils.printAttribute("classPath", javaAddress
156: .getClassPath(), pw);
157: }
158:
159: if (javaAddress.getClassLoader() != null) {
160: DOMUtils.printAttribute("classLoader", javaAddress
161: .getClassLoader(), pw);
162: }
163:
164: Boolean required = extension.getRequired();
165: if (required != null) {
166: DOMUtils.printQualifiedAttribute(
167: Constants.Q_ATTR_REQUIRED, required.toString(),
168: def, pw);
169: }
170:
171: pw.println("/>");
172: }
173: Trc.exit();
174: }
175:
176: /**
177: * Registers the serializer.
178: */
179: public void registerSerializer(ExtensionRegistry registry) {
180: Trc.entry(this , registry);
181: // binding
182: registry.registerSerializer(javax.wsdl.Binding.class,
183: JavaBindingConstants.Q_ELEM_JAVA_BINDING, this );
184: registry.registerDeserializer(javax.wsdl.Binding.class,
185: JavaBindingConstants.Q_ELEM_JAVA_BINDING, this );
186: registry.mapExtensionTypes(javax.wsdl.Binding.class,
187: JavaBindingConstants.Q_ELEM_JAVA_BINDING,
188: JavaBinding.class);
189:
190: // operation
191: registry.registerSerializer(javax.wsdl.BindingOperation.class,
192: JavaBindingConstants.Q_ELEM_JAVA_OPERATION, this );
193: registry.registerDeserializer(
194: javax.wsdl.BindingOperation.class,
195: JavaBindingConstants.Q_ELEM_JAVA_OPERATION, this );
196: registry.mapExtensionTypes(javax.wsdl.BindingOperation.class,
197: JavaBindingConstants.Q_ELEM_JAVA_OPERATION,
198: JavaOperation.class);
199: // address
200: registry.registerSerializer(javax.wsdl.Port.class,
201: JavaBindingConstants.Q_ELEM_JAVA_ADDRESS, this );
202: registry.registerDeserializer(javax.wsdl.Port.class,
203: JavaBindingConstants.Q_ELEM_JAVA_ADDRESS, this );
204: registry.mapExtensionTypes(javax.wsdl.Port.class,
205: JavaBindingConstants.Q_ELEM_JAVA_ADDRESS,
206: JavaAddress.class);
207: Trc.exit();
208: }
209:
210: public javax.wsdl.extensions.ExtensibilityElement unmarshall(
211: Class parentType, javax.xml.namespace.QName elementType,
212: org.w3c.dom.Element el, javax.wsdl.Definition def,
213: javax.wsdl.extensions.ExtensionRegistry extReg)
214: throws javax.wsdl.WSDLException {
215: Trc.entry(this , parentType, elementType, el, def, extReg);
216:
217: // CHANGE HERE: Use only one temp string ...
218:
219: javax.wsdl.extensions.ExtensibilityElement returnValue = null;
220:
221: if (JavaBindingConstants.Q_ELEM_JAVA_BINDING
222: .equals(elementType)) {
223: JavaBinding javaBinding = new JavaBinding();
224: Trc.exit(javaBinding);
225: return javaBinding;
226: } else if (JavaBindingConstants.Q_ELEM_JAVA_OPERATION
227: .equals(elementType)) {
228: JavaOperation javaOperation = new JavaOperation();
229:
230: String methodName = DOMUtils.getAttribute(el, "methodName");
231: //String requiredStr = DOMUtils.getAttributeNS(el, Constants.NS_URI_WSDL, Constants.ATTR_REQUIRED);
232: if (methodName != null) {
233: javaOperation.setMethodName(methodName);
234: }
235:
236: String methodType = DOMUtils.getAttribute(el, "methodType");
237: if (methodType != null) {
238: javaOperation.setMethodType(methodType);
239: }
240:
241: String parameterOrder = DOMUtils.getAttribute(el,
242: "parameterOrder");
243: if (parameterOrder != null) {
244: javaOperation.setParameterOrder(parameterOrder);
245: }
246:
247: String returnPart = DOMUtils.getAttribute(el, "returnPart");
248: if (returnPart != null) {
249: javaOperation.setReturnPart(returnPart);
250: }
251: Trc.exit(javaOperation);
252: return javaOperation;
253: } else if (JavaBindingConstants.Q_ELEM_JAVA_ADDRESS
254: .equals(elementType)) {
255: JavaAddress javaAddress = new JavaAddress();
256:
257: String className = DOMUtils.getAttribute(el, "className");
258: if (className != null) {
259: javaAddress.setClassName(className);
260: }
261:
262: String classPath = DOMUtils.getAttribute(el, "classPath");
263: if (classPath != null) {
264: javaAddress.setClassPath(classPath);
265: }
266:
267: String classLoader = DOMUtils.getAttribute(el,
268: "classLoader");
269: if (classLoader != null) {
270: javaAddress.setClassLoader(classLoader);
271: }
272: Trc.exit(javaAddress);
273: return javaAddress;
274: }
275: Trc.exit(returnValue);
276: return returnValue;
277: }
278: }
|