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.jms;
059:
060: import java.io.Serializable;
061: import java.util.Iterator;
062:
063: import javax.wsdl.Definition;
064: import javax.wsdl.WSDLException;
065: import javax.wsdl.extensions.ExtensibilityElement;
066: import javax.wsdl.extensions.ExtensionDeserializer;
067: import javax.wsdl.extensions.ExtensionRegistry;
068: import javax.wsdl.extensions.ExtensionSerializer;
069: import javax.xml.namespace.QName;
070:
071: import org.apache.wsif.logging.Trc;
072: import org.w3c.dom.Element;
073:
074: import com.ibm.wsdl.Constants;
075: import com.ibm.wsdl.util.xml.DOMUtils;
076: import com.ibm.wsdl.util.xml.QNameUtils;
077:
078: /**
079: * WSDL Jms extension
080: *
081: * @author Mark Whitlock <whitlock@apache.org>
082: */
083: public class JMSFaultIndicatorSerializer implements
084: ExtensionSerializer, ExtensionDeserializer, Serializable {
085:
086: private static final long serialVersionUID = 1L;
087:
088: JMSFaultPropertySerializer jmsFaultPropertySerializer;
089:
090: /**
091: * @see ExtensionSerializer#marshall(Class, QName, ExtensibilityElement,
092: * PrintWriter, Definition, ExtensionRegistry)
093: */
094: public void marshall(Class parentType, QName elementType,
095: javax.wsdl.extensions.ExtensibilityElement extension,
096: java.io.PrintWriter pw, javax.wsdl.Definition def,
097: javax.wsdl.extensions.ExtensionRegistry extReg)
098: throws javax.wsdl.WSDLException {
099: Trc.entry(parentType, elementType, extension, pw, def, extReg);
100:
101: if (extension == null) {
102: Trc.exit();
103: return;
104: }
105:
106: JMSFaultIndicator jmsFaultIndicator = (JMSFaultIndicator) extension;
107: String tagName = DOMUtils.getQualifiedValue(
108: JMSConstants.NS_URI_JMS, "faultIndicator", def);
109: pw.print(" <" + tagName);
110:
111: /**
112: * handle attributes
113: */
114: if (jmsFaultIndicator.getType() != null) {
115: DOMUtils.printAttribute(JMSConstants.ATTR_TYPE,
116: jmsFaultIndicator.getType(), pw);
117: }
118: pw.println(">");
119:
120: // Handle JMSFaultProperties
121: Iterator i = jmsFaultIndicator.getJMSFaultProperties()
122: .iterator();
123:
124: while (i.hasNext()) {
125: JMSFaultProperty ee = (JMSFaultProperty) i.next();
126: getJMSFaultPropertySerializer().marshall(
127: JMSFaultIndicator.class,
128: JMSConstants.Q_ELEM_JMS_FAULT_PROPERTY, ee, pw,
129: def, extReg);
130: }
131:
132: Boolean required = extension.getRequired();
133: if (required != null) {
134: DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED,
135: required.toString(), def, pw);
136: }
137:
138: pw.println("</" + tagName + ">");
139:
140: Trc.exit();
141: }
142:
143: /**
144: * Registers the serializer.
145: */
146: public void registerSerializer(ExtensionRegistry registry) {
147: Trc.entry(this , registry);
148:
149: // input
150: registry.registerSerializer(javax.wsdl.BindingFault.class,
151: JMSConstants.Q_ELEM_JMS_FAULT_INDICATOR, this );
152: registry.registerDeserializer(javax.wsdl.BindingFault.class,
153: JMSConstants.Q_ELEM_JMS_FAULT_INDICATOR, this );
154: registry.mapExtensionTypes(javax.wsdl.BindingFault.class,
155: JMSConstants.Q_ELEM_JMS_FAULT_INDICATOR,
156: JMSFaultIndicator.class);
157:
158: Trc.exit();
159: }
160:
161: /**
162: * @see ExtensionDeserializer#unmarshall(Class, QName, Element, Definition,
163: * ExtensionRegistry)
164: */
165: public ExtensibilityElement unmarshall(Class parentType,
166: QName elementType, Element el, Definition def,
167: ExtensionRegistry extReg) throws WSDLException {
168: Trc.entry(this , parentType, elementType, el, def, extReg);
169:
170: JMSFaultIndicator jmsFaultIndicator = (JMSFaultIndicator) extReg
171: .createExtension(parentType, elementType);
172:
173: String type = DOMUtils.getAttribute(el, JMSConstants.ATTR_TYPE);
174: if (type != null) {
175: jmsFaultIndicator.setType(type);
176: }
177:
178: // Handle JMSFaultProperty's
179: Element tempEl = DOMUtils.getFirstChildElement(el);
180:
181: while (tempEl != null) {
182: if (QNameUtils.matches(
183: JMSConstants.Q_ELEM_JMS_FAULT_PROPERTY, tempEl)) {
184:
185: jmsFaultIndicator
186: .addJMSFaultProperty((JMSFaultProperty) getJMSFaultPropertySerializer()
187: .unmarshall(
188: JMSFaultIndicator.class,
189: JMSConstants.Q_ELEM_JMS_FAULT_PROPERTY,
190: tempEl, def, extReg));
191: }
192:
193: tempEl = DOMUtils.getNextSiblingElement(tempEl);
194: }
195:
196: Trc.exit(jmsFaultIndicator);
197: return jmsFaultIndicator;
198: }
199:
200: private JMSFaultPropertySerializer getJMSFaultPropertySerializer() {
201: if (jmsFaultPropertySerializer == null)
202: jmsFaultPropertySerializer = new JMSFaultPropertySerializer();
203: return jmsFaultPropertySerializer;
204: }
205: }
|