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.format;
059:
060: import java.io.Serializable;
061: import java.util.Iterator;
062: import java.util.List;
063:
064: import javax.wsdl.extensions.ExtensionRegistry;
065: import javax.wsdl.factory.WSDLFactory;
066: import javax.wsdl.xml.WSDLReader;
067: import javax.xml.namespace.QName;
068:
069: import org.apache.wsif.logging.Trc;
070: import org.w3c.dom.Element;
071:
072: import com.ibm.wsdl.Constants;
073: import com.ibm.wsdl.util.xml.DOMUtils;
074: import com.ibm.wsdl.util.xml.QNameUtils;
075:
076: /**
077: * @author Owen Burroughs <owenb@apache.org>
078: * @author Ant Elder <antelder@apache.org>
079: * @author Jeremy Hughes <hughesj@apache.org>
080: * @author Mark Whitlock <whitlock@apache.org>
081: */
082: public class FormatBindingSerializer implements
083: javax.wsdl.extensions.ExtensionDeserializer,
084: javax.wsdl.extensions.ExtensionSerializer, Serializable {
085: private static final long serialVersionUID = 1L;
086:
087: /**
088: * ConnectorBindingSerializer constructor comment.
089: */
090: public FormatBindingSerializer() {
091: super ();
092: Trc.entry(this );
093: Trc.exit();
094: }
095:
096: /**
097: *
098: */
099: public void marshall(Class parentType, QName elementType,
100: javax.wsdl.extensions.ExtensibilityElement extension,
101: java.io.PrintWriter pw, javax.wsdl.Definition def,
102: javax.wsdl.extensions.ExtensionRegistry extReg)
103: throws javax.wsdl.WSDLException {
104: Trc.entry(this , parentType, elementType, extension, pw, def,
105: extReg);
106:
107: if (extension == null) {
108: Trc.exit();
109: return;
110: }
111:
112: if (extension instanceof TypeMapping) {
113: TypeMapping typeMapping = (TypeMapping) extension;
114: pw.print(" <format:typeMapping");
115:
116: String style = typeMapping.getStyle();
117: if (style != null)
118: DOMUtils.printAttribute("style", style, pw);
119: String encoding = typeMapping.getEncoding();
120: if (encoding != null)
121: DOMUtils.printAttribute("encoding", encoding, pw);
122: pw.println(">");
123:
124: List maps = typeMapping.getMaps();
125: Iterator iterator = maps.iterator();
126: while (iterator.hasNext()) {
127: TypeMap typeMap = (TypeMap) iterator.next();
128: pw.print(" <format:typeMap");
129:
130: // Need definition to resolve namespace to prefix to do it properly
131: QName elementName = typeMap.getElementName();
132: if (elementName != null) {
133: String prefix = def.getPrefix(elementName
134: .getNamespaceURI());
135: DOMUtils.printAttribute("elementName", prefix + ":"
136: + elementName.getLocalPart(), pw);
137: }
138: QName typeName = typeMap.getTypeName();
139: if (typeName != null) {
140: String prefix = def.getPrefix(typeName
141: .getNamespaceURI());
142: DOMUtils.printAttribute("typeName", prefix + ":"
143: + typeName.getLocalPart(), pw);
144: }
145: String formatType = typeMap.getFormatType();
146: if (formatType != null)
147: DOMUtils.printAttribute("formatType", formatType,
148: pw);
149: pw.println("/>");
150: Boolean required = extension.getRequired();
151:
152: if (required != null) {
153: DOMUtils.printQualifiedAttribute(
154: Constants.Q_ATTR_REQUIRED, required
155: .toString(), def, pw);
156: }
157:
158: }
159: pw.println(" </format:typeMapping>");
160:
161: }
162: Trc.exit();
163: }
164:
165: /**
166: * Registers the serializer.
167: */
168: public void registerSerializer(ExtensionRegistry registry) {
169: Trc.entry(this , registry);
170:
171: // Binding
172: registry.registerSerializer(javax.wsdl.Binding.class,
173: FormatBindingConstants.Q_ELEM_FORMAT_BINDING, this );
174:
175: registry.registerDeserializer(javax.wsdl.Binding.class,
176: FormatBindingConstants.Q_ELEM_FORMAT_BINDING, this );
177: Trc.exit();
178: }
179:
180: /**
181: * unmarshall method comment.
182: */
183: public javax.wsdl.extensions.ExtensibilityElement unmarshall(
184: Class parentPart, javax.xml.namespace.QName elementPart,
185: org.w3c.dom.Element el, javax.wsdl.Definition def,
186: javax.wsdl.extensions.ExtensionRegistry extReg)
187: throws javax.wsdl.WSDLException {
188: Trc.entry(this , parentPart, elementPart, el, def, extReg);
189:
190: javax.wsdl.extensions.ExtensibilityElement returnValue = null;
191:
192: if (FormatBindingConstants.Q_ELEM_FORMAT_BINDING
193: .equals(elementPart)) {
194: TypeMapping typeMapping = new TypeMapping();
195:
196: String style = DOMUtils.getAttribute(el, "style");
197: String encoding = DOMUtils.getAttribute(el, "encoding");
198: String requiredStr = DOMUtils.getAttributeNS(el,
199: Constants.NS_URI_WSDL, Constants.ATTR_REQUIRED);
200:
201: if (style != null) {
202: typeMapping.setStyle(style);
203: }
204: if (encoding != null) {
205: typeMapping.setEncoding(encoding);
206: }
207:
208: Element tempEl = DOMUtils.getFirstChildElement(el);
209: while (tempEl != null) {
210: if (QNameUtils
211: .matches(
212: FormatBindingConstants.Q_ELEM_FORMAT_BINDING_MAP,
213: tempEl)) {
214: TypeMap typeMap = new TypeMap();
215:
216: QName qElementName = DOMUtils
217: .getQualifiedAttributeValue(tempEl,
218: "elementName", "typeMap", false);
219: QName qTypeName = DOMUtils
220: .getQualifiedAttributeValue(tempEl,
221: "typeName", "typeMap", false);
222:
223: String formatType = DOMUtils.getAttribute(tempEl,
224: "formatType");
225: if (qElementName != null) {
226: typeMap.setElementName(qElementName);
227: }
228: if (qTypeName != null) {
229: typeMap.setTypeName(qTypeName);
230: }
231: if (formatType != null) {
232: typeMap.setFormatType(formatType);
233: }
234: typeMapping.addMap(typeMap);
235: }
236: tempEl = DOMUtils.getNextSiblingElement(tempEl);
237: }
238: Trc.exit(typeMapping);
239: return typeMapping;
240: }
241: Trc.exit(returnValue);
242: return returnValue;
243: }
244: }
|