001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.ws.wsdl.parser;
038:
039: import com.sun.tools.ws.api.wsdl.TWSDLExtensible;
040: import com.sun.tools.ws.api.wsdl.TWSDLParserContext;
041: import com.sun.tools.ws.util.xml.XmlUtil;
042: import com.sun.tools.ws.wsdl.document.WSDLConstants;
043: import com.sun.tools.ws.wsdl.document.mime.*;
044: import org.w3c.dom.Element;
045:
046: import java.util.Iterator;
047: import java.util.Map;
048:
049: /**
050: * The MIME extension handler for WSDL.
051: *
052: * @author WS Development Team
053: */
054: public class MIMEExtensionHandler extends AbstractExtensionHandler {
055:
056: public MIMEExtensionHandler(
057: Map<String, AbstractExtensionHandler> extensionHandlerMap) {
058: super (extensionHandlerMap);
059: }
060:
061: public String getNamespaceURI() {
062: return Constants.NS_WSDL_MIME;
063: }
064:
065: @Override
066: public boolean doHandleExtension(TWSDLParserContext context,
067: TWSDLExtensible parent, Element e) {
068: if (parent.getWSDLElementName().equals(
069: WSDLConstants.QNAME_OUTPUT)) {
070: return handleInputOutputExtension(context, parent, e);
071: } else if (parent.getWSDLElementName().equals(
072: WSDLConstants.QNAME_INPUT)) {
073: return handleInputOutputExtension(context, parent, e);
074: } else if (parent.getWSDLElementName().equals(
075: MIMEConstants.QNAME_PART)) {
076: return handleMIMEPartExtension(context, parent, e);
077: } else {
078: // context.fireIgnoringExtension(
079: // new QName(e.getNamespaceURI(), e.getLocalName()),
080: // parent.getWSDLElementName());
081: return false;
082: }
083: }
084:
085: protected boolean handleInputOutputExtension(
086: TWSDLParserContext context, TWSDLExtensible parent,
087: Element e) {
088: if (XmlUtil.matchesTagNS(e,
089: MIMEConstants.QNAME_MULTIPART_RELATED)) {
090: context.push();
091: context.registerNamespaces(e);
092:
093: MIMEMultipartRelated mpr = new MIMEMultipartRelated(context
094: .getLocation(e));
095:
096: for (Iterator iter = XmlUtil.getAllChildren(e); iter
097: .hasNext();) {
098: Element e2 = Util.nextElement(iter);
099: if (e2 == null)
100: break;
101:
102: if (XmlUtil.matchesTagNS(e2, MIMEConstants.QNAME_PART)) {
103: context.push();
104: context.registerNamespaces(e2);
105:
106: MIMEPart part = new MIMEPart(context
107: .getLocation(e2));
108:
109: String name = XmlUtil.getAttributeOrNull(e2,
110: Constants.ATTR_NAME);
111: if (name != null) {
112: part.setName(name);
113: }
114:
115: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
116: .hasNext();) {
117: Element e3 = Util.nextElement(iter2);
118: if (e3 == null)
119: break;
120:
121: AbstractExtensionHandler h = getExtensionHandlers()
122: .get(e3.getNamespaceURI());
123: boolean handled = false;
124: if (h != null) {
125: handled = h.doHandleExtension(context,
126: part, e3);
127: }
128:
129: if (!handled) {
130: String required = XmlUtil
131: .getAttributeNSOrNull(e3,
132: Constants.ATTR_REQUIRED,
133: Constants.NS_WSDL);
134: if (required != null
135: && required.equals(Constants.TRUE)) {
136: Util
137: .fail(
138: "parsing.requiredExtensibilityElement",
139: e3.getTagName(),
140: e3.getNamespaceURI());
141: } else {
142: // context.fireIgnoringExtension(
143: // new QName(
144: // e3.getNamespaceURI(),
145: // e3.getLocalName()),
146: // part.getElementName());
147: }
148: }
149: }
150:
151: mpr.add(part);
152: context.pop();
153: // context.fireDoneParsingEntity(
154: // MIMEConstants.QNAME_PART,
155: // part);
156: } else {
157: Util.fail("parsing.invalidElement",
158: e2.getTagName(), e2.getNamespaceURI());
159: }
160: }
161:
162: parent.addExtension(mpr);
163: context.pop();
164: // context.fireDoneParsingEntity(
165: // MIMEConstants.QNAME_MULTIPART_RELATED,
166: // mpr);
167: return true;
168: } else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_CONTENT)) {
169: MIMEContent content = parseMIMEContent(context, e);
170: parent.addExtension(content);
171: return true;
172: } else if (XmlUtil
173: .matchesTagNS(e, MIMEConstants.QNAME_MIME_XML)) {
174: MIMEXml mimeXml = parseMIMEXml(context, e);
175: parent.addExtension(mimeXml);
176: return true;
177: } else {
178: Util.fail("parsing.invalidExtensionElement",
179: e.getTagName(), e.getNamespaceURI());
180: return false; // keep compiler happy
181: }
182: }
183:
184: @Override
185: protected boolean handleMIMEPartExtension(
186: TWSDLParserContext context, TWSDLExtensible parent,
187: Element e) {
188: if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_CONTENT)) {
189: MIMEContent content = parseMIMEContent(context, e);
190: parent.addExtension(content);
191: return true;
192: } else if (XmlUtil
193: .matchesTagNS(e, MIMEConstants.QNAME_MIME_XML)) {
194: MIMEXml mimeXml = parseMIMEXml(context, e);
195: parent.addExtension(mimeXml);
196: return true;
197: } else {
198: Util.fail("parsing.invalidExtensionElement",
199: e.getTagName(), e.getNamespaceURI());
200: return false; // keep compiler happy
201: }
202: }
203:
204: protected MIMEContent parseMIMEContent(TWSDLParserContext context,
205: Element e) {
206: context.push();
207: context.registerNamespaces(e);
208:
209: MIMEContent content = new MIMEContent(context.getLocation(e));
210:
211: String part = XmlUtil
212: .getAttributeOrNull(e, Constants.ATTR_PART);
213: if (part != null) {
214: content.setPart(part);
215: }
216:
217: String type = XmlUtil
218: .getAttributeOrNull(e, Constants.ATTR_TYPE);
219: if (type != null) {
220: content.setType(type);
221: }
222:
223: context.pop();
224: // context.fireDoneParsingEntity(MIMEConstants.QNAME_CONTENT, content);
225: return content;
226: }
227:
228: protected MIMEXml parseMIMEXml(TWSDLParserContext context, Element e) {
229: context.push();
230: context.registerNamespaces(e);
231:
232: MIMEXml mimeXml = new MIMEXml(context.getLocation(e));
233:
234: String part = XmlUtil
235: .getAttributeOrNull(e, Constants.ATTR_PART);
236: if (part != null) {
237: mimeXml.setPart(part);
238: }
239:
240: context.pop();
241: // context.fireDoneParsingEntity(MIMEConstants.QNAME_MIME_XML, mimeXml);
242: return mimeXml;
243: }
244: }
|