src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/MIMEExtensionHandler.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.tools.internal.ws.wsdl.parser;
ohair@286 27
ohair@286 28 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
ohair@286 29 import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
ohair@286 30 import com.sun.tools.internal.ws.util.xml.XmlUtil;
ohair@286 31 import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
ohair@286 32 import com.sun.tools.internal.ws.wsdl.document.mime.*;
ohair@286 33 import org.w3c.dom.Element;
ohair@286 34
ohair@286 35 import java.util.Iterator;
ohair@286 36 import java.util.Map;
ohair@286 37
ohair@286 38 /**
ohair@286 39 * The MIME extension handler for WSDL.
ohair@286 40 *
ohair@286 41 * @author WS Development Team
ohair@286 42 */
ohair@286 43 public class MIMEExtensionHandler extends AbstractExtensionHandler {
ohair@286 44
ohair@286 45 public MIMEExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
ohair@286 46 super(extensionHandlerMap);
ohair@286 47 }
ohair@286 48
ohair@286 49 public String getNamespaceURI() {
ohair@286 50 return Constants.NS_WSDL_MIME;
ohair@286 51 }
ohair@286 52
ohair@286 53 @Override
ohair@286 54 public boolean doHandleExtension(
ohair@286 55 TWSDLParserContext context,
ohair@286 56 TWSDLExtensible parent,
ohair@286 57 Element e) {
ohair@286 58 if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_OUTPUT)) {
ohair@286 59 return handleInputOutputExtension(context, parent, e);
ohair@286 60 } else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_INPUT)) {
ohair@286 61 return handleInputOutputExtension(context, parent, e);
ohair@286 62 } else if (parent.getWSDLElementName().equals(MIMEConstants.QNAME_PART)) {
ohair@286 63 return handleMIMEPartExtension(context, parent, e);
ohair@286 64 } else {
ohair@286 65 // context.fireIgnoringExtension(
ohair@286 66 // new QName(e.getNamespaceURI(), e.getLocalName()),
ohair@286 67 // parent.getWSDLElementName());
ohair@286 68 return false;
ohair@286 69 }
ohair@286 70 }
ohair@286 71
ohair@286 72 protected boolean handleInputOutputExtension(
ohair@286 73 TWSDLParserContext context,
ohair@286 74 TWSDLExtensible parent,
ohair@286 75 Element e) {
ohair@286 76 if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_MULTIPART_RELATED)) {
ohair@286 77 context.push();
ohair@286 78 context.registerNamespaces(e);
ohair@286 79
ohair@286 80 MIMEMultipartRelated mpr = new MIMEMultipartRelated(context.getLocation(e));
ohair@286 81
ohair@286 82 for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
ohair@286 83 Element e2 = Util.nextElement(iter);
ohair@286 84 if (e2 == null)
ohair@286 85 break;
ohair@286 86
ohair@286 87 if (XmlUtil.matchesTagNS(e2, MIMEConstants.QNAME_PART)) {
ohair@286 88 context.push();
ohair@286 89 context.registerNamespaces(e2);
ohair@286 90
ohair@286 91 MIMEPart part = new MIMEPart(context.getLocation(e2));
ohair@286 92
ohair@286 93 String name =
ohair@286 94 XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
ohair@286 95 if (name != null) {
ohair@286 96 part.setName(name);
ohair@286 97 }
ohair@286 98
ohair@286 99 for (Iterator iter2 = XmlUtil.getAllChildren(e2);
ohair@286 100 iter2.hasNext();
ohair@286 101 ) {
ohair@286 102 Element e3 = Util.nextElement(iter2);
ohair@286 103 if (e3 == null)
ohair@286 104 break;
ohair@286 105
ohair@286 106 AbstractExtensionHandler h = getExtensionHandlers().get(e3.getNamespaceURI());
ohair@286 107 boolean handled = false;
ohair@286 108 if (h != null) {
ohair@286 109 handled = h.doHandleExtension(context, part, e3);
ohair@286 110 }
ohair@286 111
ohair@286 112 if (!handled) {
ohair@286 113 String required =
ohair@286 114 XmlUtil.getAttributeNSOrNull(
ohair@286 115 e3,
ohair@286 116 Constants.ATTR_REQUIRED,
ohair@286 117 Constants.NS_WSDL);
ohair@286 118 if (required != null
ohair@286 119 && required.equals(Constants.TRUE)) {
ohair@286 120 Util.fail(
ohair@286 121 "parsing.requiredExtensibilityElement",
ohair@286 122 e3.getTagName(),
ohair@286 123 e3.getNamespaceURI());
ohair@286 124 } else {
ohair@286 125 // context.fireIgnoringExtension(
ohair@286 126 // new QName(
ohair@286 127 // e3.getNamespaceURI(),
ohair@286 128 // e3.getLocalName()),
ohair@286 129 // part.getElementName());
ohair@286 130 }
ohair@286 131 }
ohair@286 132 }
ohair@286 133
ohair@286 134 mpr.add(part);
ohair@286 135 context.pop();
ohair@286 136 // context.fireDoneParsingEntity(
ohair@286 137 // MIMEConstants.QNAME_PART,
ohair@286 138 // part);
ohair@286 139 } else {
ohair@286 140 Util.fail(
ohair@286 141 "parsing.invalidElement",
ohair@286 142 e2.getTagName(),
ohair@286 143 e2.getNamespaceURI());
ohair@286 144 }
ohair@286 145 }
ohair@286 146
ohair@286 147 parent.addExtension(mpr);
ohair@286 148 context.pop();
ohair@286 149 // context.fireDoneParsingEntity(
ohair@286 150 // MIMEConstants.QNAME_MULTIPART_RELATED,
ohair@286 151 // mpr);
ohair@286 152 return true;
ohair@286 153 } else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_CONTENT)) {
ohair@286 154 MIMEContent content = parseMIMEContent(context, e);
ohair@286 155 parent.addExtension(content);
ohair@286 156 return true;
ohair@286 157 } else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_MIME_XML)) {
ohair@286 158 MIMEXml mimeXml = parseMIMEXml(context, e);
ohair@286 159 parent.addExtension(mimeXml);
ohair@286 160 return true;
ohair@286 161 } else {
ohair@286 162 Util.fail(
ohair@286 163 "parsing.invalidExtensionElement",
ohair@286 164 e.getTagName(),
ohair@286 165 e.getNamespaceURI());
ohair@286 166 return false; // keep compiler happy
ohair@286 167 }
ohair@286 168 }
ohair@286 169
ohair@286 170 @Override
ohair@286 171 protected boolean handleMIMEPartExtension(
ohair@286 172 TWSDLParserContext context,
ohair@286 173 TWSDLExtensible parent,
ohair@286 174 Element e) {
ohair@286 175 if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_CONTENT)) {
ohair@286 176 MIMEContent content = parseMIMEContent(context, e);
ohair@286 177 parent.addExtension(content);
ohair@286 178 return true;
ohair@286 179 } else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_MIME_XML)) {
ohair@286 180 MIMEXml mimeXml = parseMIMEXml(context, e);
ohair@286 181 parent.addExtension(mimeXml);
ohair@286 182 return true;
ohair@286 183 } else {
ohair@286 184 Util.fail(
ohair@286 185 "parsing.invalidExtensionElement",
ohair@286 186 e.getTagName(),
ohair@286 187 e.getNamespaceURI());
ohair@286 188 return false; // keep compiler happy
ohair@286 189 }
ohair@286 190 }
ohair@286 191
ohair@286 192 protected MIMEContent parseMIMEContent(TWSDLParserContext context, Element e) {
ohair@286 193 context.push();
ohair@286 194 context.registerNamespaces(e);
ohair@286 195
ohair@286 196 MIMEContent content = new MIMEContent(context.getLocation(e));
ohair@286 197
ohair@286 198 String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
ohair@286 199 if (part != null) {
ohair@286 200 content.setPart(part);
ohair@286 201 }
ohair@286 202
ohair@286 203 String type = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TYPE);
ohair@286 204 if (type != null) {
ohair@286 205 content.setType(type);
ohair@286 206 }
ohair@286 207
ohair@286 208 context.pop();
ohair@286 209 // context.fireDoneParsingEntity(MIMEConstants.QNAME_CONTENT, content);
ohair@286 210 return content;
ohair@286 211 }
ohair@286 212
ohair@286 213 protected MIMEXml parseMIMEXml(TWSDLParserContext context, Element e) {
ohair@286 214 context.push();
ohair@286 215 context.registerNamespaces(e);
ohair@286 216
ohair@286 217 MIMEXml mimeXml = new MIMEXml(context.getLocation(e));
ohair@286 218
ohair@286 219 String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
ohair@286 220 if (part != null) {
ohair@286 221 mimeXml.setPart(part);
ohair@286 222 }
ohair@286 223
ohair@286 224 context.pop();
ohair@286 225 // context.fireDoneParsingEntity(MIMEConstants.QNAME_MIME_XML, mimeXml);
ohair@286 226 return mimeXml;
ohair@286 227 }
ohair@286 228 }

mercurial