Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.tools.internal.jxc.gen.config; |
ohair@286 | 27 | |
ohair@286 | 28 | import org.xml.sax.Attributes; |
ohair@286 | 29 | import org.xml.sax.SAXException; |
ohair@286 | 30 | |
ohair@286 | 31 | /** |
ohair@286 | 32 | * Dispatches incoming events into sub handlers appropriately |
ohair@286 | 33 | * so that the interleaving semantics will be correctly realized. |
ohair@286 | 34 | * |
ohair@286 | 35 | * @author Kohsuke Kawaguchi (kk@kohsuke.org) |
ohair@286 | 36 | */ |
ohair@286 | 37 | public abstract class NGCCInterleaveFilter implements NGCCEventSource, NGCCEventReceiver { |
ohair@286 | 38 | protected NGCCInterleaveFilter( NGCCHandler parent, int cookie ) { |
ohair@286 | 39 | this._parent = parent; |
ohair@286 | 40 | this._cookie = cookie; |
ohair@286 | 41 | } |
ohair@286 | 42 | |
ohair@286 | 43 | protected void setHandlers( NGCCEventReceiver[] receivers ) { |
ohair@286 | 44 | this._receivers = receivers; |
ohair@286 | 45 | } |
ohair@286 | 46 | |
ohair@286 | 47 | /** event receiverse. */ |
ohair@286 | 48 | protected NGCCEventReceiver[] _receivers; |
ohair@286 | 49 | |
ohair@286 | 50 | public int replace(NGCCEventReceiver oldHandler, NGCCEventReceiver newHandler) { |
ohair@286 | 51 | for( int i=0; i<_receivers.length; i++ ) |
ohair@286 | 52 | if( _receivers[i]==oldHandler ) { |
ohair@286 | 53 | _receivers[i]=newHandler; |
ohair@286 | 54 | return i; |
ohair@286 | 55 | } |
ohair@286 | 56 | throw new InternalError(); // a bug in RelaxNGCC. |
ohair@286 | 57 | } |
ohair@286 | 58 | |
ohair@286 | 59 | |
ohair@286 | 60 | /** Parent handler. */ |
ohair@286 | 61 | private final NGCCHandler _parent; |
ohair@286 | 62 | /** Cookie given by the parent. */ |
ohair@286 | 63 | private final int _cookie; |
ohair@286 | 64 | |
ohair@286 | 65 | |
ohair@286 | 66 | |
ohair@286 | 67 | // |
ohair@286 | 68 | // |
ohair@286 | 69 | // event handler |
ohair@286 | 70 | // |
ohair@286 | 71 | // |
ohair@286 | 72 | /** |
ohair@286 | 73 | * Receiver that is being locked and therefore receives all the events. |
ohair@286 | 74 | * <pre><xmp> |
ohair@286 | 75 | * <interleave> |
ohair@286 | 76 | * <element name="foo"/> |
ohair@286 | 77 | * <element name="bar"> |
ohair@286 | 78 | * <element name="foo"/> |
ohair@286 | 79 | * </element> |
ohair@286 | 80 | * </interlaeve> |
ohair@286 | 81 | * </xmp></pre> |
ohair@286 | 82 | * When processing inside the bar element, this receiver is |
ohair@286 | 83 | * "locked" so that it can correctly receive its child foo element. |
ohair@286 | 84 | */ |
ohair@286 | 85 | private int lockedReceiver; |
ohair@286 | 86 | /** |
ohair@286 | 87 | * Nest level. Lock will be release when the lockCount becomes 0. |
ohair@286 | 88 | */ |
ohair@286 | 89 | private int lockCount=0; |
ohair@286 | 90 | |
ohair@286 | 91 | public void enterElement( |
ohair@286 | 92 | String uri, String localName, String qname,Attributes atts) throws SAXException { |
ohair@286 | 93 | |
ohair@286 | 94 | if(isJoining) return; // ignore any token if we are joining. See joinByXXXX. |
ohair@286 | 95 | |
ohair@286 | 96 | if(lockCount++==0) { |
ohair@286 | 97 | lockedReceiver = findReceiverOfElement(uri,localName); |
ohair@286 | 98 | if(lockedReceiver==-1) { |
ohair@286 | 99 | // we can't process this token. join. |
ohair@286 | 100 | joinByEnterElement(null,uri,localName,qname,atts); |
ohair@286 | 101 | return; |
ohair@286 | 102 | } |
ohair@286 | 103 | } |
ohair@286 | 104 | |
ohair@286 | 105 | _receivers[lockedReceiver].enterElement(uri,localName,qname,atts); |
ohair@286 | 106 | } |
ohair@286 | 107 | public void leaveElement(String uri, String localName, String qname) throws SAXException { |
ohair@286 | 108 | if(isJoining) return; // ignore any token if we are joining. See joinByXXXX. |
ohair@286 | 109 | |
ohair@286 | 110 | if( lockCount-- == 0 ) |
ohair@286 | 111 | joinByLeaveElement(null,uri,localName,qname); |
ohair@286 | 112 | else |
ohair@286 | 113 | _receivers[lockedReceiver].leaveElement(uri,localName,qname); |
ohair@286 | 114 | } |
ohair@286 | 115 | public void enterAttribute(String uri, String localName, String qname) throws SAXException { |
ohair@286 | 116 | if(isJoining) return; // ignore any token if we are joining. See joinByXXXX. |
ohair@286 | 117 | |
ohair@286 | 118 | if(lockCount++==0) { |
ohair@286 | 119 | lockedReceiver = findReceiverOfAttribute(uri,localName); |
ohair@286 | 120 | if(lockedReceiver==-1) { |
ohair@286 | 121 | // we can't process this token. join. |
ohair@286 | 122 | joinByEnterAttribute(null,uri,localName,qname); |
ohair@286 | 123 | return; |
ohair@286 | 124 | } |
ohair@286 | 125 | } |
ohair@286 | 126 | |
ohair@286 | 127 | _receivers[lockedReceiver].enterAttribute(uri,localName,qname); |
ohair@286 | 128 | } |
ohair@286 | 129 | public void leaveAttribute(String uri, String localName, String qname) throws SAXException { |
ohair@286 | 130 | if(isJoining) return; // ignore any token if we are joining. See joinByXXXX. |
ohair@286 | 131 | |
ohair@286 | 132 | if( lockCount-- == 0 ) |
ohair@286 | 133 | joinByLeaveAttribute(null,uri,localName,qname); |
ohair@286 | 134 | else |
ohair@286 | 135 | _receivers[lockedReceiver].leaveAttribute(uri,localName,qname); |
ohair@286 | 136 | } |
ohair@286 | 137 | public void text(String value) throws SAXException { |
ohair@286 | 138 | if(isJoining) return; // ignore any token if we are joining. See joinByXXXX. |
ohair@286 | 139 | |
ohair@286 | 140 | if(lockCount!=0) |
ohair@286 | 141 | _receivers[lockedReceiver].text(value); |
ohair@286 | 142 | else { |
ohair@286 | 143 | int receiver = findReceiverOfText(); |
ohair@286 | 144 | if(receiver!=-1) _receivers[receiver].text(value); |
ohair@286 | 145 | else joinByText(null,value); |
ohair@286 | 146 | } |
ohair@286 | 147 | } |
ohair@286 | 148 | |
ohair@286 | 149 | |
ohair@286 | 150 | |
ohair@286 | 151 | /** |
ohair@286 | 152 | * Implemented by the generated code to determine the handler |
ohair@286 | 153 | * that can receive the given element. |
ohair@286 | 154 | * |
ohair@286 | 155 | * @return |
ohair@286 | 156 | * Thread ID of the receiver that can handle this event, |
ohair@286 | 157 | * or -1 if none. |
ohair@286 | 158 | */ |
ohair@286 | 159 | protected abstract int findReceiverOfElement( String uri, String local ); |
ohair@286 | 160 | |
ohair@286 | 161 | /** |
ohair@286 | 162 | * Returns the handler that can receive the given attribute, or null. |
ohair@286 | 163 | */ |
ohair@286 | 164 | protected abstract int findReceiverOfAttribute( String uri, String local ); |
ohair@286 | 165 | |
ohair@286 | 166 | /** |
ohair@286 | 167 | * Returns the handler that can receive text events, or null. |
ohair@286 | 168 | */ |
ohair@286 | 169 | protected abstract int findReceiverOfText(); |
ohair@286 | 170 | |
ohair@286 | 171 | |
ohair@286 | 172 | |
ohair@286 | 173 | |
ohair@286 | 174 | // |
ohair@286 | 175 | // |
ohair@286 | 176 | // join method |
ohair@286 | 177 | // |
ohair@286 | 178 | // |
ohair@286 | 179 | |
ohair@286 | 180 | |
ohair@286 | 181 | /** |
ohair@286 | 182 | * Set to true when this handler is in the process of |
ohair@286 | 183 | * joining all branches. |
ohair@286 | 184 | */ |
ohair@286 | 185 | private boolean isJoining = false; |
ohair@286 | 186 | |
ohair@286 | 187 | /** |
ohair@286 | 188 | * Joins all the child receivers. |
ohair@286 | 189 | * |
ohair@286 | 190 | * <p> |
ohair@286 | 191 | * This method is called by a child receiver when it sees |
ohair@286 | 192 | * something that it cannot handle, or by this object itself |
ohair@286 | 193 | * when it sees an event that it can't process. |
ohair@286 | 194 | * |
ohair@286 | 195 | * <p> |
ohair@286 | 196 | * This method forces children to move to its final state, |
ohair@286 | 197 | * then revert to the parent. |
ohair@286 | 198 | * |
ohair@286 | 199 | * @param source |
ohair@286 | 200 | * If this method is called by one of the child receivers, |
ohair@286 | 201 | * the receiver object. If this method is called by itself, |
ohair@286 | 202 | * null. |
ohair@286 | 203 | */ |
ohair@286 | 204 | public void joinByEnterElement( NGCCEventReceiver source, |
ohair@286 | 205 | String uri, String local, String qname, Attributes atts ) throws SAXException { |
ohair@286 | 206 | |
ohair@286 | 207 | if(isJoining) return; // we are already in the process of joining. ignore. |
ohair@286 | 208 | isJoining = true; |
ohair@286 | 209 | |
ohair@286 | 210 | // send special token to the rest of the branches. |
ohair@286 | 211 | // these branches don't understand this token, so they will |
ohair@286 | 212 | // try to move to a final state and send the token back to us, |
ohair@286 | 213 | // which this object will ignore (because isJoining==true) |
ohair@286 | 214 | // Otherwise branches will find an error. |
ohair@286 | 215 | for( int i=0; i<_receivers.length; i++ ) |
ohair@286 | 216 | if( _receivers[i]!=source ) |
ohair@286 | 217 | _receivers[i].enterElement(uri,local,qname,atts); |
ohair@286 | 218 | |
ohair@286 | 219 | // revert to the parent |
ohair@286 | 220 | _parent._source.replace(this,_parent); |
ohair@286 | 221 | _parent.onChildCompleted(null,_cookie,true); |
ohair@286 | 222 | // send this event to the parent |
ohair@286 | 223 | _parent.enterElement(uri,local,qname,atts); |
ohair@286 | 224 | } |
ohair@286 | 225 | |
ohair@286 | 226 | public void joinByLeaveElement( NGCCEventReceiver source, |
ohair@286 | 227 | String uri, String local, String qname ) throws SAXException { |
ohair@286 | 228 | |
ohair@286 | 229 | if(isJoining) return; // we are already in the process of joining. ignore. |
ohair@286 | 230 | isJoining = true; |
ohair@286 | 231 | |
ohair@286 | 232 | // send special token to the rest of the branches. |
ohair@286 | 233 | // these branches don't understand this token, so they will |
ohair@286 | 234 | // try to move to a final state and send the token back to us, |
ohair@286 | 235 | // which this object will ignore (because isJoining==true) |
ohair@286 | 236 | // Otherwise branches will find an error. |
ohair@286 | 237 | for( int i=0; i<_receivers.length; i++ ) |
ohair@286 | 238 | if( _receivers[i]!=source ) |
ohair@286 | 239 | _receivers[i].leaveElement(uri,local,qname); |
ohair@286 | 240 | |
ohair@286 | 241 | // revert to the parent |
ohair@286 | 242 | _parent._source.replace(this,_parent); |
ohair@286 | 243 | _parent.onChildCompleted(null,_cookie,true); |
ohair@286 | 244 | // send this event to the parent |
ohair@286 | 245 | _parent.leaveElement(uri,local,qname); |
ohair@286 | 246 | } |
ohair@286 | 247 | |
ohair@286 | 248 | public void joinByEnterAttribute( NGCCEventReceiver source, |
ohair@286 | 249 | String uri, String local, String qname ) throws SAXException { |
ohair@286 | 250 | |
ohair@286 | 251 | if(isJoining) return; // we are already in the process of joining. ignore. |
ohair@286 | 252 | isJoining = true; |
ohair@286 | 253 | |
ohair@286 | 254 | // send special token to the rest of the branches. |
ohair@286 | 255 | // these branches don't understand this token, so they will |
ohair@286 | 256 | // try to move to a final state and send the token back to us, |
ohair@286 | 257 | // which this object will ignore (because isJoining==true) |
ohair@286 | 258 | // Otherwise branches will find an error. |
ohair@286 | 259 | for( int i=0; i<_receivers.length; i++ ) |
ohair@286 | 260 | if( _receivers[i]!=source ) |
ohair@286 | 261 | _receivers[i].enterAttribute(uri,local,qname); |
ohair@286 | 262 | |
ohair@286 | 263 | // revert to the parent |
ohair@286 | 264 | _parent._source.replace(this,_parent); |
ohair@286 | 265 | _parent.onChildCompleted(null,_cookie,true); |
ohair@286 | 266 | // send this event to the parent |
ohair@286 | 267 | _parent.enterAttribute(uri,local,qname); |
ohair@286 | 268 | } |
ohair@286 | 269 | |
ohair@286 | 270 | public void joinByLeaveAttribute( NGCCEventReceiver source, |
ohair@286 | 271 | String uri, String local, String qname ) throws SAXException { |
ohair@286 | 272 | |
ohair@286 | 273 | if(isJoining) return; // we are already in the process of joining. ignore. |
ohair@286 | 274 | isJoining = true; |
ohair@286 | 275 | |
ohair@286 | 276 | // send special token to the rest of the branches. |
ohair@286 | 277 | // these branches don't understand this token, so they will |
ohair@286 | 278 | // try to move to a final state and send the token back to us, |
ohair@286 | 279 | // which this object will ignore (because isJoining==true) |
ohair@286 | 280 | // Otherwise branches will find an error. |
ohair@286 | 281 | for( int i=0; i<_receivers.length; i++ ) |
ohair@286 | 282 | if( _receivers[i]!=source ) |
ohair@286 | 283 | _receivers[i].leaveAttribute(uri,local,qname); |
ohair@286 | 284 | |
ohair@286 | 285 | // revert to the parent |
ohair@286 | 286 | _parent._source.replace(this,_parent); |
ohair@286 | 287 | _parent.onChildCompleted(null,_cookie,true); |
ohair@286 | 288 | // send this event to the parent |
ohair@286 | 289 | _parent.leaveAttribute(uri,local,qname); |
ohair@286 | 290 | } |
ohair@286 | 291 | |
ohair@286 | 292 | public void joinByText( NGCCEventReceiver source, |
ohair@286 | 293 | String value ) throws SAXException { |
ohair@286 | 294 | |
ohair@286 | 295 | if(isJoining) return; // we are already in the process of joining. ignore. |
ohair@286 | 296 | isJoining = true; |
ohair@286 | 297 | |
ohair@286 | 298 | // send special token to the rest of the branches. |
ohair@286 | 299 | // these branches don't understand this token, so they will |
ohair@286 | 300 | // try to move to a final state and send the token back to us, |
ohair@286 | 301 | // which this object will ignore (because isJoining==true) |
ohair@286 | 302 | // Otherwise branches will find an error. |
ohair@286 | 303 | for( int i=0; i<_receivers.length; i++ ) |
ohair@286 | 304 | if( _receivers[i]!=source ) |
ohair@286 | 305 | _receivers[i].text(value); |
ohair@286 | 306 | |
ohair@286 | 307 | // revert to the parent |
ohair@286 | 308 | _parent._source.replace(this,_parent); |
ohair@286 | 309 | _parent.onChildCompleted(null,_cookie,true); |
ohair@286 | 310 | // send this event to the parent |
ohair@286 | 311 | _parent.text(value); |
ohair@286 | 312 | } |
ohair@286 | 313 | |
ohair@286 | 314 | |
ohair@286 | 315 | |
ohair@286 | 316 | // |
ohair@286 | 317 | // |
ohair@286 | 318 | // event dispatching methods |
ohair@286 | 319 | // |
ohair@286 | 320 | // |
ohair@286 | 321 | |
ohair@286 | 322 | public void sendEnterAttribute( int threadId, |
ohair@286 | 323 | String uri, String local, String qname) throws SAXException { |
ohair@286 | 324 | |
ohair@286 | 325 | _receivers[threadId].enterAttribute(uri,local,qname); |
ohair@286 | 326 | } |
ohair@286 | 327 | |
ohair@286 | 328 | public void sendEnterElement( int threadId, |
ohair@286 | 329 | String uri, String local, String qname, Attributes atts) throws SAXException { |
ohair@286 | 330 | |
ohair@286 | 331 | _receivers[threadId].enterElement(uri,local,qname,atts); |
ohair@286 | 332 | } |
ohair@286 | 333 | |
ohair@286 | 334 | public void sendLeaveAttribute( int threadId, |
ohair@286 | 335 | String uri, String local, String qname) throws SAXException { |
ohair@286 | 336 | |
ohair@286 | 337 | _receivers[threadId].leaveAttribute(uri,local,qname); |
ohair@286 | 338 | } |
ohair@286 | 339 | |
ohair@286 | 340 | public void sendLeaveElement( int threadId, |
ohair@286 | 341 | String uri, String local, String qname) throws SAXException { |
ohair@286 | 342 | |
ohair@286 | 343 | _receivers[threadId].leaveElement(uri,local,qname); |
ohair@286 | 344 | } |
ohair@286 | 345 | |
ohair@286 | 346 | public void sendText(int threadId, String value) throws SAXException { |
ohair@286 | 347 | _receivers[threadId].text(value); |
ohair@286 | 348 | } |
ohair@286 | 349 | |
ohair@286 | 350 | } |