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.xml.ws.wsdl.parser;
038:
039: import com.sun.xml.ws.api.wsdl.parser.WSDLParserExtension;
040: import com.sun.xml.ws.api.wsdl.parser.WSDLParserExtensionContext;
041: import com.sun.xml.ws.api.model.wsdl.*;
042: import com.sun.xml.ws.streaming.XMLStreamReaderUtil;
043: import com.sun.xml.ws.model.wsdl.WSDLPortImpl;
044: import com.sun.xml.ws.model.wsdl.WSDLBoundPortTypeImpl;
045:
046: import javax.xml.stream.XMLStreamReader;
047: import javax.xml.stream.Location;
048:
049: import org.xml.sax.Locator;
050: import org.xml.sax.helpers.LocatorImpl;
051:
052: /**
053: * {@link WSDLParserExtension} that delegates to
054: * multiple {@link WSDLParserExtension}s.
055: *
056: * <p>
057: * This simplifies {@link RuntimeWSDLParser} since it now
058: * only needs to work with one {@link WSDLParserExtension}.
059: *
060: * <p>
061: * This class is guaranteed to return true from
062: * all the extension callback methods.
063: *
064: * @author Kohsuke Kawaguchi
065: */
066: final class WSDLParserExtensionFacade extends WSDLParserExtension {
067: private final WSDLParserExtension[] extensions;
068:
069: WSDLParserExtensionFacade(WSDLParserExtension... extensions) {
070: assert extensions != null;
071: this .extensions = extensions;
072: }
073:
074: public void start(WSDLParserExtensionContext context) {
075: for (WSDLParserExtension e : extensions) {
076: e.start(context);
077: }
078: }
079:
080: public boolean serviceElements(WSDLService service,
081: XMLStreamReader reader) {
082: for (WSDLParserExtension e : extensions) {
083: if (e.serviceElements(service, reader))
084: return true;
085: }
086: XMLStreamReaderUtil.skipElement(reader);
087: return true;
088: }
089:
090: public void serviceAttributes(WSDLService service,
091: XMLStreamReader reader) {
092: for (WSDLParserExtension e : extensions)
093: e.serviceAttributes(service, reader);
094: }
095:
096: public boolean portElements(WSDLPort port, XMLStreamReader reader) {
097: for (WSDLParserExtension e : extensions) {
098: if (e.portElements(port, reader))
099: return true;
100: }
101: //extension is not understood by any WSDlParserExtension
102: //Check if it must be understood.
103: if (isRequiredExtension(reader)) {
104: ((WSDLPortImpl) port).addNotUnderstoodExtension(reader
105: .getName(), getLocator(reader));
106: }
107: XMLStreamReaderUtil.skipElement(reader);
108: return true;
109: }
110:
111: public boolean portTypeOperationInput(WSDLOperation op,
112: XMLStreamReader reader) {
113: for (WSDLParserExtension e : extensions)
114: e.portTypeOperationInput(op, reader);
115:
116: return false;
117: }
118:
119: public boolean portTypeOperationOutput(WSDLOperation op,
120: XMLStreamReader reader) {
121: for (WSDLParserExtension e : extensions)
122: e.portTypeOperationOutput(op, reader);
123:
124: return false;
125: }
126:
127: public boolean portTypeOperationFault(WSDLOperation op,
128: XMLStreamReader reader) {
129: for (WSDLParserExtension e : extensions)
130: e.portTypeOperationFault(op, reader);
131:
132: return false;
133: }
134:
135: public void portAttributes(WSDLPort port, XMLStreamReader reader) {
136: for (WSDLParserExtension e : extensions)
137: e.portAttributes(port, reader);
138: }
139:
140: public boolean definitionsElements(XMLStreamReader reader) {
141: for (WSDLParserExtension e : extensions) {
142: if (e.definitionsElements(reader)) {
143: return true;
144: }
145: }
146: XMLStreamReaderUtil.skipElement(reader);
147: return true;
148: }
149:
150: public boolean bindingElements(WSDLBoundPortType binding,
151: XMLStreamReader reader) {
152: for (WSDLParserExtension e : extensions) {
153: if (e.bindingElements(binding, reader)) {
154: return true;
155: }
156: }
157: //extension is not understood by any WSDlParserExtension
158: //Check if it must be understood.
159: if (isRequiredExtension(reader)) {
160: ((WSDLBoundPortTypeImpl) binding)
161: .addNotUnderstoodExtension(reader.getName(),
162: getLocator(reader));
163: }
164: XMLStreamReaderUtil.skipElement(reader);
165: return true;
166: }
167:
168: public void bindingAttributes(WSDLBoundPortType binding,
169: XMLStreamReader reader) {
170: for (WSDLParserExtension e : extensions) {
171: e.bindingAttributes(binding, reader);
172: }
173: }
174:
175: public boolean portTypeElements(WSDLPortType portType,
176: XMLStreamReader reader) {
177: for (WSDLParserExtension e : extensions) {
178: if (e.portTypeElements(portType, reader)) {
179: return true;
180: }
181: }
182: XMLStreamReaderUtil.skipElement(reader);
183: return true;
184: }
185:
186: public void portTypeAttributes(WSDLPortType portType,
187: XMLStreamReader reader) {
188: for (WSDLParserExtension e : extensions) {
189: e.portTypeAttributes(portType, reader);
190: }
191: }
192:
193: public boolean portTypeOperationElements(WSDLOperation operation,
194: XMLStreamReader reader) {
195: for (WSDLParserExtension e : extensions) {
196: if (e.portTypeOperationElements(operation, reader)) {
197: return true;
198: }
199: }
200: XMLStreamReaderUtil.skipElement(reader);
201: return true;
202: }
203:
204: public void portTypeOperationAttributes(WSDLOperation operation,
205: XMLStreamReader reader) {
206: for (WSDLParserExtension e : extensions) {
207: e.portTypeOperationAttributes(operation, reader);
208: }
209: }
210:
211: public boolean bindingOperationElements(
212: WSDLBoundOperation operation, XMLStreamReader reader) {
213: for (WSDLParserExtension e : extensions) {
214: if (e.bindingOperationElements(operation, reader)) {
215: return true;
216: }
217: }
218: XMLStreamReaderUtil.skipElement(reader);
219: return true;
220: }
221:
222: public void bindingOperationAttributes(
223: WSDLBoundOperation operation, XMLStreamReader reader) {
224: for (WSDLParserExtension e : extensions) {
225: e.bindingOperationAttributes(operation, reader);
226: }
227: }
228:
229: public boolean messageElements(WSDLMessage msg,
230: XMLStreamReader reader) {
231: for (WSDLParserExtension e : extensions) {
232: if (e.messageElements(msg, reader)) {
233: return true;
234: }
235: }
236: XMLStreamReaderUtil.skipElement(reader);
237: return true;
238: }
239:
240: public void messageAttributes(WSDLMessage msg,
241: XMLStreamReader reader) {
242: for (WSDLParserExtension e : extensions) {
243: e.messageAttributes(msg, reader);
244: }
245: }
246:
247: public boolean portTypeOperationInputElements(WSDLInput input,
248: XMLStreamReader reader) {
249: for (WSDLParserExtension e : extensions) {
250: if (e.portTypeOperationInputElements(input, reader)) {
251: return true;
252: }
253: }
254: XMLStreamReaderUtil.skipElement(reader);
255: return true;
256: }
257:
258: public void portTypeOperationInputAttributes(WSDLInput input,
259: XMLStreamReader reader) {
260: for (WSDLParserExtension e : extensions) {
261: e.portTypeOperationInputAttributes(input, reader);
262: }
263: }
264:
265: public boolean portTypeOperationOutputElements(WSDLOutput output,
266: XMLStreamReader reader) {
267: for (WSDLParserExtension e : extensions) {
268: if (e.portTypeOperationOutputElements(output, reader)) {
269: return true;
270: }
271: }
272: XMLStreamReaderUtil.skipElement(reader);
273: return true;
274: }
275:
276: public void portTypeOperationOutputAttributes(WSDLOutput output,
277: XMLStreamReader reader) {
278: for (WSDLParserExtension e : extensions) {
279: e.portTypeOperationOutputAttributes(output, reader);
280: }
281: }
282:
283: public boolean portTypeOperationFaultElements(WSDLFault fault,
284: XMLStreamReader reader) {
285: for (WSDLParserExtension e : extensions) {
286: if (e.portTypeOperationFaultElements(fault, reader)) {
287: return true;
288: }
289: }
290: XMLStreamReaderUtil.skipElement(reader);
291: return true;
292: }
293:
294: public void portTypeOperationFaultAttributes(WSDLFault fault,
295: XMLStreamReader reader) {
296: for (WSDLParserExtension e : extensions) {
297: e.portTypeOperationFaultAttributes(fault, reader);
298: }
299: }
300:
301: public boolean bindingOperationInputElements(
302: WSDLBoundOperation operation, XMLStreamReader reader) {
303: for (WSDLParserExtension e : extensions) {
304: if (e.bindingOperationInputElements(operation, reader)) {
305: return true;
306: }
307: }
308: XMLStreamReaderUtil.skipElement(reader);
309: return true;
310: }
311:
312: public void bindingOperationInputAttributes(
313: WSDLBoundOperation operation, XMLStreamReader reader) {
314: for (WSDLParserExtension e : extensions) {
315: e.bindingOperationInputAttributes(operation, reader);
316: }
317: }
318:
319: public boolean bindingOperationOutputElements(
320: WSDLBoundOperation operation, XMLStreamReader reader) {
321: for (WSDLParserExtension e : extensions) {
322: if (e.bindingOperationOutputElements(operation, reader)) {
323: return true;
324: }
325: }
326: XMLStreamReaderUtil.skipElement(reader);
327: return true;
328: }
329:
330: public void bindingOperationOutputAttributes(
331: WSDLBoundOperation operation, XMLStreamReader reader) {
332: for (WSDLParserExtension e : extensions) {
333: e.bindingOperationOutputAttributes(operation, reader);
334: }
335: }
336:
337: public boolean bindingOperationFaultElements(WSDLBoundFault fault,
338: XMLStreamReader reader) {
339: for (WSDLParserExtension e : extensions) {
340: if (e.bindingOperationFaultElements(fault, reader)) {
341: return true;
342: }
343: }
344: XMLStreamReaderUtil.skipElement(reader);
345: return true;
346: }
347:
348: public void bindingOperationFaultAttributes(WSDLBoundFault fault,
349: XMLStreamReader reader) {
350: for (WSDLParserExtension e : extensions) {
351: e.bindingOperationFaultAttributes(fault, reader);
352: }
353: }
354:
355: public void finished(WSDLParserExtensionContext context) {
356: for (WSDLParserExtension e : extensions) {
357: e.finished(context);
358: }
359: }
360:
361: public void postFinished(WSDLParserExtensionContext context) {
362: for (WSDLParserExtension e : extensions) {
363: e.postFinished(context);
364: }
365: }
366:
367: /**
368: *
369: * @param reader
370: * @return If the element has wsdl:required attribute set to true
371: */
372:
373: private boolean isRequiredExtension(XMLStreamReader reader) {
374: String required = reader.getAttributeValue(
375: WSDLConstants.NS_WSDL, "required");
376: if (required != null)
377: return Boolean.parseBoolean(required);
378: return false;
379: }
380:
381: private Locator getLocator(XMLStreamReader reader) {
382: Location location = reader.getLocation();
383: LocatorImpl loc = new LocatorImpl();
384: loc.setSystemId(location.getSystemId());
385: loc.setLineNumber(location.getLineNumber());
386: return loc;
387: }
388:
389: }
|