001: package com.sun.xml.ws.wsdl.parser;
002:
003: /*
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
005: *
006: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: import com.sun.xml.ws.api.model.wsdl.*;
040: import com.sun.xml.ws.api.wsdl.parser.WSDLParserExtension;
041:
042: import javax.xml.namespace.QName;
043: import javax.xml.stream.XMLStreamConstants;
044: import javax.xml.stream.XMLStreamReader;
045:
046: /**
047: * {@link WSDLParserExtension} filter that checks if
048: * another {@link WSDLParserExtension} is following the contract.
049: *
050: * <p>
051: * This code protects the JAX-WS RI from broken extensions.
052: *
053: * <p>
054: * For now it just checks if {@link XMLStreamReader} is placed
055: * at the expected start/end element.
056: *
057: * @author Kohsuke Kawaguchi
058: */
059: final class FoolProofParserExtension extends DelegatingParserExtension {
060:
061: public FoolProofParserExtension(WSDLParserExtension core) {
062: super (core);
063: }
064:
065: private QName pre(XMLStreamReader xsr) {
066: return xsr.getName();
067: }
068:
069: private boolean post(QName tagName, XMLStreamReader xsr,
070: boolean result) {
071: if (!tagName.equals(xsr.getName()))
072: return foundFool();
073: if (result) {
074: if (xsr.getEventType() != XMLStreamConstants.END_ELEMENT)
075: foundFool();
076: } else {
077: if (xsr.getEventType() != XMLStreamConstants.START_ELEMENT)
078: foundFool();
079: }
080: return result;
081: }
082:
083: private boolean foundFool() {
084: throw new AssertionError(
085: "XMLStreamReader is placed at the wrong place after invoking "
086: + core);
087: }
088:
089: public boolean serviceElements(WSDLService service,
090: XMLStreamReader reader) {
091: return post(pre(reader), reader, super .serviceElements(service,
092: reader));
093: }
094:
095: public boolean portElements(WSDLPort port, XMLStreamReader reader) {
096: return post(pre(reader), reader, super .portElements(port,
097: reader));
098: }
099:
100: public boolean definitionsElements(XMLStreamReader reader) {
101: return post(pre(reader), reader, super
102: .definitionsElements(reader));
103: }
104:
105: public boolean bindingElements(WSDLBoundPortType binding,
106: XMLStreamReader reader) {
107: return post(pre(reader), reader, super .bindingElements(binding,
108: reader));
109: }
110:
111: public boolean portTypeElements(WSDLPortType portType,
112: XMLStreamReader reader) {
113: return post(pre(reader), reader, super .portTypeElements(
114: portType, reader));
115: }
116:
117: public boolean portTypeOperationElements(WSDLOperation operation,
118: XMLStreamReader reader) {
119: return post(pre(reader), reader, super
120: .portTypeOperationElements(operation, reader));
121: }
122:
123: public boolean bindingOperationElements(
124: WSDLBoundOperation operation, XMLStreamReader reader) {
125: return post(pre(reader), reader, super
126: .bindingOperationElements(operation, reader));
127: }
128:
129: public boolean messageElements(WSDLMessage msg,
130: XMLStreamReader reader) {
131: return post(pre(reader), reader, super .messageElements(msg,
132: reader));
133: }
134:
135: public boolean portTypeOperationInputElements(WSDLInput input,
136: XMLStreamReader reader) {
137: return post(pre(reader), reader, super
138: .portTypeOperationInputElements(input, reader));
139: }
140:
141: public boolean portTypeOperationOutputElements(WSDLOutput output,
142: XMLStreamReader reader) {
143: return post(pre(reader), reader, super
144: .portTypeOperationOutputElements(output, reader));
145: }
146:
147: public boolean portTypeOperationFaultElements(WSDLFault fault,
148: XMLStreamReader reader) {
149: return post(pre(reader), reader, super
150: .portTypeOperationFaultElements(fault, reader));
151: }
152:
153: public boolean bindingOperationInputElements(
154: WSDLBoundOperation operation, XMLStreamReader reader) {
155: return super .bindingOperationInputElements(operation, reader);
156: }
157:
158: public boolean bindingOperationOutputElements(
159: WSDLBoundOperation operation, XMLStreamReader reader) {
160: return post(pre(reader), reader, super
161: .bindingOperationOutputElements(operation, reader));
162: }
163:
164: public boolean bindingOperationFaultElements(WSDLBoundFault fault,
165: XMLStreamReader reader) {
166: return post(pre(reader), reader, super
167: .bindingOperationFaultElements(fault, reader));
168: }
169: }
|