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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

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

mercurial