src/share/jaxws_classes/com/sun/tools/internal/jxc/gen/config/NGCCInterleaveFilter.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/jxc/gen/config/NGCCInterleaveFilter.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,353 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.jxc.gen.config;
    1.30 +
    1.31 +import org.xml.sax.Attributes;
    1.32 +import org.xml.sax.SAXException;
    1.33 +
    1.34 +/**
    1.35 + * Dispatches incoming events into sub handlers appropriately
    1.36 + * so that the interleaving semantics will be correctly realized.
    1.37 + *
    1.38 + * <p><b>
    1.39 + *     Auto-generated, do not edit.
    1.40 + * </b></p>
    1.41 + * @author Kohsuke Kawaguchi (kk@kohsuke.org)
    1.42 + */
    1.43 +public abstract class NGCCInterleaveFilter implements NGCCEventSource, NGCCEventReceiver {
    1.44 +    protected NGCCInterleaveFilter( NGCCHandler parent, int cookie ) {
    1.45 +        this._parent = parent;
    1.46 +        this._cookie = cookie;
    1.47 +    }
    1.48 +
    1.49 +    protected void setHandlers( NGCCEventReceiver[] receivers ) {
    1.50 +        this._receivers = receivers;
    1.51 +    }
    1.52 +
    1.53 +    /** event receiverse. */
    1.54 +    protected NGCCEventReceiver[] _receivers;
    1.55 +
    1.56 +    public int replace(NGCCEventReceiver oldHandler, NGCCEventReceiver newHandler) {
    1.57 +        for( int i=0; i<_receivers.length; i++ )
    1.58 +            if( _receivers[i]==oldHandler ) {
    1.59 +                _receivers[i]=newHandler;
    1.60 +                return i;
    1.61 +            }
    1.62 +        throw new InternalError(); // a bug in RelaxNGCC.
    1.63 +    }
    1.64 +
    1.65 +
    1.66 +    /** Parent handler. */
    1.67 +    private final NGCCHandler _parent;
    1.68 +    /** Cookie given by the parent. */
    1.69 +    private final int _cookie;
    1.70 +
    1.71 +
    1.72 +
    1.73 +//
    1.74 +//
    1.75 +// event handler
    1.76 +//
    1.77 +//
    1.78 +    /**
    1.79 +     * Receiver that is being locked and therefore receives all the events.
    1.80 +     * <pre><xmp>
    1.81 +     * <interleave>
    1.82 +     *   <element name="foo"/>
    1.83 +     *   <element name="bar">
    1.84 +     *     <element name="foo"/>
    1.85 +     *   </element>
    1.86 +     * </interlaeve>
    1.87 +     * </xmp></pre>
    1.88 +     * When processing inside the bar element, this receiver is
    1.89 +     * "locked" so that it can correctly receive its child foo element.
    1.90 +     */
    1.91 +    private int lockedReceiver;
    1.92 +    /**
    1.93 +     * Nest level. Lock will be release when the lockCount becomes 0.
    1.94 +     */
    1.95 +    private int lockCount=0;
    1.96 +
    1.97 +    public void enterElement(
    1.98 +        String uri, String localName, String qname,Attributes atts) throws SAXException {
    1.99 +
   1.100 +        if(isJoining)   return; // ignore any token if we are joining. See joinByXXXX.
   1.101 +
   1.102 +        if(lockCount++==0) {
   1.103 +            lockedReceiver = findReceiverOfElement(uri,localName);
   1.104 +            if(lockedReceiver==-1) {
   1.105 +                // we can't process this token. join.
   1.106 +                joinByEnterElement(null,uri,localName,qname,atts);
   1.107 +                return;
   1.108 +            }
   1.109 +        }
   1.110 +
   1.111 +        _receivers[lockedReceiver].enterElement(uri,localName,qname,atts);
   1.112 +    }
   1.113 +    public void leaveElement(String uri, String localName, String qname) throws SAXException {
   1.114 +        if(isJoining)   return; // ignore any token if we are joining. See joinByXXXX.
   1.115 +
   1.116 +        if( lockCount-- == 0 )
   1.117 +            joinByLeaveElement(null,uri,localName,qname);
   1.118 +        else
   1.119 +            _receivers[lockedReceiver].leaveElement(uri,localName,qname);
   1.120 +    }
   1.121 +    public void enterAttribute(String uri, String localName, String qname) throws SAXException {
   1.122 +        if(isJoining)   return; // ignore any token if we are joining. See joinByXXXX.
   1.123 +
   1.124 +        if(lockCount++==0) {
   1.125 +            lockedReceiver = findReceiverOfAttribute(uri,localName);
   1.126 +            if(lockedReceiver==-1) {
   1.127 +                // we can't process this token. join.
   1.128 +                joinByEnterAttribute(null,uri,localName,qname);
   1.129 +                return;
   1.130 +            }
   1.131 +        }
   1.132 +
   1.133 +        _receivers[lockedReceiver].enterAttribute(uri,localName,qname);
   1.134 +    }
   1.135 +    public void leaveAttribute(String uri, String localName, String qname) throws SAXException {
   1.136 +        if(isJoining)   return; // ignore any token if we are joining. See joinByXXXX.
   1.137 +
   1.138 +        if( lockCount-- == 0 )
   1.139 +            joinByLeaveAttribute(null,uri,localName,qname);
   1.140 +        else
   1.141 +            _receivers[lockedReceiver].leaveAttribute(uri,localName,qname);
   1.142 +    }
   1.143 +    public void text(String value) throws SAXException {
   1.144 +        if(isJoining)   return; // ignore any token if we are joining. See joinByXXXX.
   1.145 +
   1.146 +        if(lockCount!=0)
   1.147 +            _receivers[lockedReceiver].text(value);
   1.148 +        else {
   1.149 +            int receiver = findReceiverOfText();
   1.150 +            if(receiver!=-1)    _receivers[receiver].text(value);
   1.151 +            else                joinByText(null,value);
   1.152 +        }
   1.153 +    }
   1.154 +
   1.155 +
   1.156 +
   1.157 +    /**
   1.158 +     * Implemented by the generated code to determine the handler
   1.159 +     * that can receive the given element.
   1.160 +     *
   1.161 +     * @return
   1.162 +     *      Thread ID of the receiver that can handle this event,
   1.163 +     *      or -1 if none.
   1.164 +     */
   1.165 +    protected abstract int findReceiverOfElement( String uri, String local );
   1.166 +
   1.167 +    /**
   1.168 +     * Returns the handler that can receive the given attribute, or null.
   1.169 +     */
   1.170 +    protected abstract int findReceiverOfAttribute( String uri, String local );
   1.171 +
   1.172 +    /**
   1.173 +     * Returns the handler that can receive text events, or null.
   1.174 +     */
   1.175 +    protected abstract int findReceiverOfText();
   1.176 +
   1.177 +
   1.178 +
   1.179 +
   1.180 +//
   1.181 +//
   1.182 +// join method
   1.183 +//
   1.184 +//
   1.185 +
   1.186 +
   1.187 +    /**
   1.188 +     * Set to true when this handler is in the process of
   1.189 +     * joining all branches.
   1.190 +     */
   1.191 +    private boolean isJoining = false;
   1.192 +
   1.193 +    /**
   1.194 +     * Joins all the child receivers.
   1.195 +     *
   1.196 +     * <p>
   1.197 +     * This method is called by a child receiver when it sees
   1.198 +     * something that it cannot handle, or by this object itself
   1.199 +     * when it sees an event that it can't process.
   1.200 +     *
   1.201 +     * <p>
   1.202 +     * This method forces children to move to its final state,
   1.203 +     * then revert to the parent.
   1.204 +     *
   1.205 +     * @param source
   1.206 +     *      If this method is called by one of the child receivers,
   1.207 +     *      the receiver object. If this method is called by itself,
   1.208 +     *      null.
   1.209 +     */
   1.210 +    public void joinByEnterElement( NGCCEventReceiver source,
   1.211 +        String uri, String local, String qname, Attributes atts ) throws SAXException {
   1.212 +
   1.213 +        if(isJoining)   return; // we are already in the process of joining. ignore.
   1.214 +        isJoining = true;
   1.215 +
   1.216 +        // send special token to the rest of the branches.
   1.217 +        // these branches don't understand this token, so they will
   1.218 +        // try to move to a final state and send the token back to us,
   1.219 +        // which this object will ignore (because isJoining==true)
   1.220 +        // Otherwise branches will find an error.
   1.221 +        for( int i=0; i<_receivers.length; i++ )
   1.222 +            if( _receivers[i]!=source )
   1.223 +                _receivers[i].enterElement(uri,local,qname,atts);
   1.224 +
   1.225 +        // revert to the parent
   1.226 +        _parent._source.replace(this,_parent);
   1.227 +        _parent.onChildCompleted(null,_cookie,true);
   1.228 +        // send this event to the parent
   1.229 +        _parent.enterElement(uri,local,qname,atts);
   1.230 +    }
   1.231 +
   1.232 +    public void joinByLeaveElement( NGCCEventReceiver source,
   1.233 +        String uri, String local, String qname ) throws SAXException {
   1.234 +
   1.235 +        if(isJoining)   return; // we are already in the process of joining. ignore.
   1.236 +        isJoining = true;
   1.237 +
   1.238 +        // send special token to the rest of the branches.
   1.239 +        // these branches don't understand this token, so they will
   1.240 +        // try to move to a final state and send the token back to us,
   1.241 +        // which this object will ignore (because isJoining==true)
   1.242 +        // Otherwise branches will find an error.
   1.243 +        for( int i=0; i<_receivers.length; i++ )
   1.244 +            if( _receivers[i]!=source )
   1.245 +                _receivers[i].leaveElement(uri,local,qname);
   1.246 +
   1.247 +        // revert to the parent
   1.248 +        _parent._source.replace(this,_parent);
   1.249 +        _parent.onChildCompleted(null,_cookie,true);
   1.250 +        // send this event to the parent
   1.251 +        _parent.leaveElement(uri,local,qname);
   1.252 +    }
   1.253 +
   1.254 +    public void joinByEnterAttribute( NGCCEventReceiver source,
   1.255 +        String uri, String local, String qname ) throws SAXException {
   1.256 +
   1.257 +        if(isJoining)   return; // we are already in the process of joining. ignore.
   1.258 +        isJoining = true;
   1.259 +
   1.260 +        // send special token to the rest of the branches.
   1.261 +        // these branches don't understand this token, so they will
   1.262 +        // try to move to a final state and send the token back to us,
   1.263 +        // which this object will ignore (because isJoining==true)
   1.264 +        // Otherwise branches will find an error.
   1.265 +        for( int i=0; i<_receivers.length; i++ )
   1.266 +            if( _receivers[i]!=source )
   1.267 +                _receivers[i].enterAttribute(uri,local,qname);
   1.268 +
   1.269 +        // revert to the parent
   1.270 +        _parent._source.replace(this,_parent);
   1.271 +        _parent.onChildCompleted(null,_cookie,true);
   1.272 +        // send this event to the parent
   1.273 +        _parent.enterAttribute(uri,local,qname);
   1.274 +    }
   1.275 +
   1.276 +    public void joinByLeaveAttribute( NGCCEventReceiver source,
   1.277 +        String uri, String local, String qname ) throws SAXException {
   1.278 +
   1.279 +        if(isJoining)   return; // we are already in the process of joining. ignore.
   1.280 +        isJoining = true;
   1.281 +
   1.282 +        // send special token to the rest of the branches.
   1.283 +        // these branches don't understand this token, so they will
   1.284 +        // try to move to a final state and send the token back to us,
   1.285 +        // which this object will ignore (because isJoining==true)
   1.286 +        // Otherwise branches will find an error.
   1.287 +        for( int i=0; i<_receivers.length; i++ )
   1.288 +            if( _receivers[i]!=source )
   1.289 +                _receivers[i].leaveAttribute(uri,local,qname);
   1.290 +
   1.291 +        // revert to the parent
   1.292 +        _parent._source.replace(this,_parent);
   1.293 +        _parent.onChildCompleted(null,_cookie,true);
   1.294 +        // send this event to the parent
   1.295 +        _parent.leaveAttribute(uri,local,qname);
   1.296 +    }
   1.297 +
   1.298 +    public void joinByText( NGCCEventReceiver source,
   1.299 +        String value ) throws SAXException {
   1.300 +
   1.301 +        if(isJoining)   return; // we are already in the process of joining. ignore.
   1.302 +        isJoining = true;
   1.303 +
   1.304 +        // send special token to the rest of the branches.
   1.305 +        // these branches don't understand this token, so they will
   1.306 +        // try to move to a final state and send the token back to us,
   1.307 +        // which this object will ignore (because isJoining==true)
   1.308 +        // Otherwise branches will find an error.
   1.309 +        for( int i=0; i<_receivers.length; i++ )
   1.310 +            if( _receivers[i]!=source )
   1.311 +                _receivers[i].text(value);
   1.312 +
   1.313 +        // revert to the parent
   1.314 +        _parent._source.replace(this,_parent);
   1.315 +        _parent.onChildCompleted(null,_cookie,true);
   1.316 +        // send this event to the parent
   1.317 +        _parent.text(value);
   1.318 +    }
   1.319 +
   1.320 +
   1.321 +
   1.322 +//
   1.323 +//
   1.324 +// event dispatching methods
   1.325 +//
   1.326 +//
   1.327 +
   1.328 +    public void sendEnterAttribute( int threadId,
   1.329 +        String uri, String local, String qname) throws SAXException {
   1.330 +
   1.331 +        _receivers[threadId].enterAttribute(uri,local,qname);
   1.332 +    }
   1.333 +
   1.334 +    public void sendEnterElement( int threadId,
   1.335 +        String uri, String local, String qname, Attributes atts) throws SAXException {
   1.336 +
   1.337 +        _receivers[threadId].enterElement(uri,local,qname,atts);
   1.338 +    }
   1.339 +
   1.340 +    public void sendLeaveAttribute( int threadId,
   1.341 +        String uri, String local, String qname) throws SAXException {
   1.342 +
   1.343 +        _receivers[threadId].leaveAttribute(uri,local,qname);
   1.344 +    }
   1.345 +
   1.346 +    public void sendLeaveElement( int threadId,
   1.347 +        String uri, String local, String qname) throws SAXException {
   1.348 +
   1.349 +        _receivers[threadId].leaveElement(uri,local,qname);
   1.350 +    }
   1.351 +
   1.352 +    public void sendText(int threadId, String value) throws SAXException {
   1.353 +        _receivers[threadId].text(value);
   1.354 +    }
   1.355 +
   1.356 +}

mercurial