src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/parser/FoolProofParserExtension.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

     1 /*
     2  * Copyright (c) 1997, 2013, 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  */
    26 package com.sun.xml.internal.ws.wsdl.parser;
    29 import com.sun.xml.internal.ws.api.model.wsdl.editable.*;
    30 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension;
    32 import javax.xml.namespace.QName;
    33 import javax.xml.stream.XMLStreamConstants;
    34 import javax.xml.stream.XMLStreamReader;
    36 /**
    37  * {@link WSDLParserExtension} filter that checks if
    38  * another {@link WSDLParserExtension} is following the contract.
    39  *
    40  * <p>
    41  * This code protects the JAX-WS RI from broken extensions.
    42  *
    43  * <p>
    44  * For now it just checks if {@link XMLStreamReader} is placed
    45  * at the expected start/end element.
    46  *
    47  * @author Kohsuke Kawaguchi
    48  */
    49 final class FoolProofParserExtension extends DelegatingParserExtension {
    51     public FoolProofParserExtension(WSDLParserExtension core) {
    52         super(core);
    53     }
    55     private QName pre(XMLStreamReader xsr) {
    56         return xsr.getName();
    57     }
    59     private boolean post(QName tagName, XMLStreamReader xsr, boolean result) {
    60         if(!tagName.equals(xsr.getName()))
    61             return foundFool();
    62         if(result) {
    63             if(xsr.getEventType()!=XMLStreamConstants.END_ELEMENT)
    64                 foundFool();
    65         } else {
    66             if(xsr.getEventType()!=XMLStreamConstants.START_ELEMENT)
    67                 foundFool();
    68         }
    69         return result;
    70     }
    72     private boolean foundFool() {
    73         throw new AssertionError("XMLStreamReader is placed at the wrong place after invoking "+core);
    74     }
    76     public boolean serviceElements(EditableWSDLService service, XMLStreamReader reader) {
    77         return post(pre(reader),reader,super.serviceElements(service, reader));
    78     }
    80     public boolean portElements(EditableWSDLPort port, XMLStreamReader reader) {
    81         return post(pre(reader),reader,super.portElements(port, reader));
    82     }
    84     public boolean definitionsElements(XMLStreamReader reader) {
    85         return post(pre(reader),reader,super.definitionsElements(reader));
    86     }
    88     public boolean bindingElements(EditableWSDLBoundPortType binding, XMLStreamReader reader) {
    89         return post(pre(reader),reader,super.bindingElements(binding, reader));
    90     }
    92     public boolean portTypeElements(EditableWSDLPortType portType, XMLStreamReader reader) {
    93         return post(pre(reader),reader,super.portTypeElements(portType, reader));
    94     }
    96     public boolean portTypeOperationElements(EditableWSDLOperation operation, XMLStreamReader reader) {
    97         return post(pre(reader),reader,super.portTypeOperationElements(operation, reader));
    98     }
   100     public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   101         return post(pre(reader),reader,super.bindingOperationElements(operation, reader));
   102     }
   104     public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
   105         return post(pre(reader),reader,super.messageElements(msg, reader));
   106     }
   108     public boolean portTypeOperationInputElements(EditableWSDLInput input, XMLStreamReader reader) {
   109         return post(pre(reader),reader,super.portTypeOperationInputElements(input, reader));
   110     }
   112     public boolean portTypeOperationOutputElements(EditableWSDLOutput output, XMLStreamReader reader) {
   113         return post(pre(reader),reader,super.portTypeOperationOutputElements(output, reader));
   114     }
   116     public boolean portTypeOperationFaultElements(EditableWSDLFault fault, XMLStreamReader reader) {
   117         return post(pre(reader),reader,super.portTypeOperationFaultElements(fault, reader));
   118     }
   120     public boolean bindingOperationInputElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   121         return super.bindingOperationInputElements(operation, reader);
   122     }
   124     public boolean bindingOperationOutputElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
   125         return post(pre(reader),reader,super.bindingOperationOutputElements(operation, reader));
   126     }
   128     public boolean bindingOperationFaultElements(EditableWSDLBoundFault fault, XMLStreamReader reader) {
   129         return post(pre(reader),reader,super.bindingOperationFaultElements(fault, reader));
   130     }
   131 }

mercurial