1 /*
2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.tools.internal.ws.wsdl.parser;
27 
28 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
29 import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
30 import com.sun.tools.internal.ws.util.xml.XmlUtil;
31 import com.sun.tools.internal.ws.wsdl.document.http.*;
32 import org.w3c.dom.Element;
33 
34 import java.util.Map;
35 
36 /**
37  * The HTTP extension handler for WSDL.
38  *
39  * @author WS Development Team
40  */
41 public class HTTPExtensionHandler extends AbstractExtensionHandler {
42 
43 
HTTPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap)44     public HTTPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
45         super(extensionHandlerMap);
46     }
47 
getNamespaceURI()48     public String getNamespaceURI() {
49         return Constants.NS_WSDL_HTTP;
50     }
51 
handleDefinitionsExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)52     public boolean handleDefinitionsExtension(
53         TWSDLParserContext context,
54         TWSDLExtensible parent,
55         Element e) {
56         Util.fail(
57             "parsing.invalidExtensionElement",
58             e.getTagName(),
59             e.getNamespaceURI());
60         return false;
61     }
62 
handleTypesExtension( com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, TWSDLExtensible parent, Element e)63     public boolean handleTypesExtension(
64         com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context,
65         TWSDLExtensible parent,
66         Element e) {
67         Util.fail(
68             "parsing.invalidExtensionElement",
69             e.getTagName(),
70             e.getNamespaceURI());
71         return false;
72     }
73 
handleBindingExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)74     public boolean handleBindingExtension(
75         TWSDLParserContext context,
76         TWSDLExtensible parent,
77         Element e) {
78         if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_BINDING)) {
79             context.push();
80             context.registerNamespaces(e);
81 
82             HTTPBinding binding = new HTTPBinding(context.getLocation(e));
83 
84             String verb = Util.getRequiredAttribute(e, Constants.ATTR_VERB);
85             binding.setVerb(verb);
86 
87             parent.addExtension(binding);
88             context.pop();
89 //            context.fireDoneParsingEntity(HTTPConstants.QNAME_BINDING, binding);
90             return true;
91         } else {
92             Util.fail(
93                 "parsing.invalidExtensionElement",
94                 e.getTagName(),
95                 e.getNamespaceURI());
96             return false;
97         }
98     }
99 
handleOperationExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)100     public boolean handleOperationExtension(
101         TWSDLParserContext context,
102         TWSDLExtensible parent,
103         Element e) {
104         if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_OPERATION)) {
105             context.push();
106             context.registerNamespaces(e);
107 
108             HTTPOperation operation = new HTTPOperation(context.getLocation(e));
109 
110             String location =
111                 Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
112             operation.setLocation(location);
113 
114             parent.addExtension(operation);
115             context.pop();
116 //            context.fireDoneParsingEntity(
117 //                HTTPConstants.QNAME_OPERATION,
118 //                operation);
119             return true;
120         } else {
121             Util.fail(
122                 "parsing.invalidExtensionElement",
123                 e.getTagName(),
124                 e.getNamespaceURI());
125             return false;
126         }
127     }
128 
handleInputExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)129     public boolean handleInputExtension(
130         TWSDLParserContext context,
131         TWSDLExtensible parent,
132         Element e) {
133         if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_URL_ENCODED)) {
134             parent.addExtension(new HTTPUrlEncoded(context.getLocation(e)));
135             return true;
136         } else if (
137             XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_URL_REPLACEMENT)) {
138             parent.addExtension(new HTTPUrlReplacement(context.getLocation(e)));
139             return true;
140         } else {
141             Util.fail(
142                 "parsing.invalidExtensionElement",
143                 e.getTagName(),
144                 e.getNamespaceURI());
145             return false;
146         }
147     }
148 
handleOutputExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)149     public boolean handleOutputExtension(
150         TWSDLParserContext context,
151         TWSDLExtensible parent,
152         Element e) {
153         Util.fail(
154             "parsing.invalidExtensionElement",
155             e.getTagName(),
156             e.getNamespaceURI());
157         return false;
158     }
159 
handleFaultExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)160     public boolean handleFaultExtension(
161         TWSDLParserContext context,
162         TWSDLExtensible parent,
163         Element e) {
164         Util.fail(
165             "parsing.invalidExtensionElement",
166             e.getTagName(),
167             e.getNamespaceURI());
168         return false;
169     }
170 
handleServiceExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)171     public boolean handleServiceExtension(
172         TWSDLParserContext context,
173         TWSDLExtensible parent,
174         Element e) {
175         Util.fail(
176             "parsing.invalidExtensionElement",
177             e.getTagName(),
178             e.getNamespaceURI());
179         return false;
180     }
181 
handlePortExtension( TWSDLParserContext context, TWSDLExtensible parent, Element e)182     public boolean handlePortExtension(
183         TWSDLParserContext context,
184         TWSDLExtensible parent,
185         Element e) {
186         if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_ADDRESS)) {
187             context.push();
188             context.registerNamespaces(e);
189 
190             HTTPAddress address = new HTTPAddress(context.getLocation(e));
191 
192             String location =
193                 Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
194             address.setLocation(location);
195 
196             parent.addExtension(address);
197             context.pop();
198 //            context.fireDoneParsingEntity(HTTPConstants.QNAME_ADDRESS, address);
199             return true;
200         } else {
201             Util.fail(
202                 "parsing.invalidExtensionElement",
203                 e.getTagName(),
204                 e.getNamespaceURI());
205             return false;
206         }
207     }
208 
handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e)209     public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
210         Util.fail(
211             "parsing.invalidExtensionElement",
212             e.getTagName(),
213             e.getNamespaceURI());
214         return false;
215     }
216 }
217