001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.ws.wsdl.parser;
027:
028: import java.io.IOException;
029:
030: import org.w3c.dom.Element;
031:
032: import com.sun.tools.internal.ws.wsdl.document.http.HTTPAddress;
033: import com.sun.tools.internal.ws.wsdl.document.http.HTTPBinding;
034: import com.sun.tools.internal.ws.wsdl.document.http.HTTPConstants;
035: import com.sun.tools.internal.ws.wsdl.document.http.HTTPOperation;
036: import com.sun.tools.internal.ws.wsdl.document.http.HTTPUrlEncoded;
037: import com.sun.tools.internal.ws.wsdl.document.http.HTTPUrlReplacement;
038: import com.sun.tools.internal.ws.wsdl.framework.Extensible;
039: import com.sun.tools.internal.ws.wsdl.framework.Extension;
040: import com.sun.tools.internal.ws.wsdl.framework.ParserContext;
041: import com.sun.tools.internal.ws.wsdl.framework.WriterContext;
042: import com.sun.tools.internal.ws.util.xml.XmlUtil;
043:
044: /**
045: * The HTTP extension handler for WSDL.
046: *
047: * @author WS Development Team
048: */
049: public class HTTPExtensionHandler extends ExtensionHandlerBase {
050:
051: public HTTPExtensionHandler() {
052: }
053:
054: public String getNamespaceURI() {
055: return Constants.NS_WSDL_HTTP;
056: }
057:
058: protected boolean handleDefinitionsExtension(ParserContext context,
059: Extensible parent, Element e) {
060: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
061: .getNamespaceURI());
062: return false; // keep compiler happy
063: }
064:
065: protected boolean handleTypesExtension(ParserContext context,
066: Extensible parent, Element e) {
067: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
068: .getNamespaceURI());
069: return false; // keep compiler happy
070: }
071:
072: protected boolean handleBindingExtension(ParserContext context,
073: Extensible parent, Element e) {
074: if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_BINDING)) {
075: context.push();
076: context.registerNamespaces(e);
077:
078: HTTPBinding binding = new HTTPBinding();
079:
080: String verb = Util.getRequiredAttribute(e,
081: Constants.ATTR_VERB);
082: binding.setVerb(verb);
083:
084: parent.addExtension(binding);
085: context.pop();
086: context.fireDoneParsingEntity(HTTPConstants.QNAME_BINDING,
087: binding);
088: return true;
089: } else {
090: Util.fail("parsing.invalidExtensionElement",
091: e.getTagName(), e.getNamespaceURI());
092: return false; // keep compiler happy
093: }
094: }
095:
096: protected boolean handleOperationExtension(ParserContext context,
097: Extensible parent, Element e) {
098: if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_OPERATION)) {
099: context.push();
100: context.registerNamespaces(e);
101:
102: HTTPOperation operation = new HTTPOperation();
103:
104: String location = Util.getRequiredAttribute(e,
105: Constants.ATTR_LOCATION);
106: operation.setLocation(location);
107:
108: parent.addExtension(operation);
109: context.pop();
110: context.fireDoneParsingEntity(
111: HTTPConstants.QNAME_OPERATION, operation);
112: return true;
113: } else {
114: Util.fail("parsing.invalidExtensionElement",
115: e.getTagName(), e.getNamespaceURI());
116: return false; // keep compiler happy
117: }
118: }
119:
120: protected boolean handleInputExtension(ParserContext context,
121: Extensible parent, Element e) {
122: if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_URL_ENCODED)) {
123: parent.addExtension(new HTTPUrlEncoded());
124: return true;
125: } else if (XmlUtil.matchesTagNS(e,
126: HTTPConstants.QNAME_URL_REPLACEMENT)) {
127: parent.addExtension(new HTTPUrlReplacement());
128: return true;
129: } else {
130: Util.fail("parsing.invalidExtensionElement",
131: e.getTagName(), e.getNamespaceURI());
132: return false; // keep compiler happy
133: }
134: }
135:
136: protected boolean handleOutputExtension(ParserContext context,
137: Extensible parent, Element e) {
138: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
139: .getNamespaceURI());
140: return false; // keep compiler happy
141: }
142:
143: protected boolean handleFaultExtension(ParserContext context,
144: Extensible parent, Element e) {
145: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
146: .getNamespaceURI());
147: return false; // keep compiler happy
148: }
149:
150: protected boolean handleServiceExtension(ParserContext context,
151: Extensible parent, Element e) {
152: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
153: .getNamespaceURI());
154: return false; // keep compiler happy
155: }
156:
157: protected boolean handlePortExtension(ParserContext context,
158: Extensible parent, Element e) {
159: if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_ADDRESS)) {
160: context.push();
161: context.registerNamespaces(e);
162:
163: HTTPAddress address = new HTTPAddress();
164:
165: String location = Util.getRequiredAttribute(e,
166: Constants.ATTR_LOCATION);
167: address.setLocation(location);
168:
169: parent.addExtension(address);
170: context.pop();
171: context.fireDoneParsingEntity(HTTPConstants.QNAME_ADDRESS,
172: address);
173: return true;
174: } else {
175: Util.fail("parsing.invalidExtensionElement",
176: e.getTagName(), e.getNamespaceURI());
177: return false; // keep compiler happy
178: }
179: }
180:
181: protected boolean handleMIMEPartExtension(ParserContext context,
182: Extensible parent, Element e) {
183: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
184: .getNamespaceURI());
185: return false; // keep compiler happy
186: }
187:
188: public void doHandleExtension(WriterContext context,
189: Extension extension) throws IOException {
190: if (extension instanceof HTTPAddress) {
191: HTTPAddress address = (HTTPAddress) extension;
192: context.writeStartTag(address.getElementName());
193: context.writeAttribute(Constants.ATTR_LOCATION, address
194: .getLocation());
195: context.writeEndTag(address.getElementName());
196: } else if (extension instanceof HTTPBinding) {
197: HTTPBinding binding = (HTTPBinding) extension;
198: context.writeStartTag(binding.getElementName());
199: context.writeAttribute(Constants.ATTR_VERB, binding
200: .getVerb());
201: context.writeEndTag(binding.getElementName());
202: } else if (extension instanceof HTTPOperation) {
203: HTTPOperation operation = (HTTPOperation) extension;
204: context.writeStartTag(operation.getElementName());
205: context.writeAttribute(Constants.ATTR_LOCATION, operation
206: .getLocation());
207: context.writeEndTag(operation.getElementName());
208: } else if (extension instanceof HTTPUrlEncoded) {
209: context.writeStartTag(extension.getElementName());
210: context.writeEndTag(extension.getElementName());
211: } else if (extension instanceof HTTPUrlReplacement) {
212: context.writeStartTag(extension.getElementName());
213: context.writeEndTag(extension.getElementName());
214: } else {
215: throw new IllegalArgumentException();
216: }
217: }
218:
219: /* (non-Javadoc)
220: * @see ExtensionHandlerBase#handlePortTypeExtension(ParserContext, Extensible, org.w3c.dom.Element)
221: */
222: protected boolean handlePortTypeExtension(ParserContext context,
223: Extensible parent, Element e) {
224: Util.fail("parsing.invalidExtensionElement", e.getTagName(), e
225: .getNamespaceURI());
226: return false; // keep compiler happy
227: }
228: }
|