1 /*
   2  * Copyright (c) 1997, 2011, 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  */
  25 
  26 /* this file is generated by RelaxNGCC */
  27 package com.sun.xml.internal.xsom.impl.parser.state;
  28 import org.xml.sax.SAXException;
  29 import org.xml.sax.XMLReader;
  30 import org.xml.sax.Attributes;
  31 import com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx;
  32 
  33     import com.sun.xml.internal.xsom.*;
  34     import com.sun.xml.internal.xsom.parser.*;
  35     import com.sun.xml.internal.xsom.impl.*;
  36     import com.sun.xml.internal.xsom.impl.parser.*;
  37     import org.xml.sax.Locator;
  38     import org.xml.sax.ContentHandler;
  39     import org.xml.sax.helpers.*;
  40     import java.util.*;
  41     import java.math.BigInteger;
  42 
  43 
  44 
  45 class simpleType extends NGCCHandler {
  46     private AnnotationImpl annotation;
  47     private String name;
  48     private ForeignAttributesImpl fa;
  49     private String finalValue;
  50     protected final NGCCRuntimeEx $runtime;
  51     private int $_ngcc_current_state;
  52     protected String $uri;
  53     protected String $localName;
  54     protected String $qname;
  55 
  56     public final NGCCRuntime getRuntime() {
  57         return($runtime);
  58     }
  59 
  60     public simpleType(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie) {
  61         super(source, parent, cookie);
  62         $runtime = runtime;
  63         $_ngcc_current_state = 19;
  64     }
  65 
  66     public simpleType(NGCCRuntimeEx runtime) {
  67         this(null, runtime, runtime, -1);
  68     }
  69 
  70     private void action0()throws SAXException {
  71         finalSet = makeFinalSet(finalValue);
  72 }
  73 
  74     private void action1()throws SAXException {
  75         locator=$runtime.copyLocator();
  76 }
  77 
  78     public void enterElement(String $__uri, String $__local, String $__qname, Attributes $attrs) throws SAXException {
  79         int $ai;
  80         $uri = $__uri;
  81         $localName = $__local;
  82         $qname = $__qname;
  83         switch($_ngcc_current_state) {
  84         case 2:
  85             {
  86                 if(($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("restriction"))) {
  87                     NGCCHandler h = new SimpleType_Restriction(this, super._source, $runtime, 182, annotation,locator,fa,name,finalSet);
  88                     spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
  89                 }
  90                 else {
  91                     if(($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("list"))) {
  92                         NGCCHandler h = new SimpleType_List(this, super._source, $runtime, 183, annotation,locator,fa,name,finalSet);
  93                         spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
  94                     }
  95                     else {
  96                         if(($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("union"))) {
  97                             NGCCHandler h = new SimpleType_Union(this, super._source, $runtime, 177, annotation,locator,fa,name,finalSet);
  98                             spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
  99                         }
 100                         else {
 101                             unexpectedEnterElement($__qname);
 102                         }
 103                     }
 104                 }
 105             }
 106             break;
 107         case 7:
 108             {
 109                 action0();
 110                 $_ngcc_current_state = 2;
 111                 $runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
 112             }
 113             break;
 114         case 15:
 115             {
 116                 if(($ai = $runtime.getAttributeIndex("","final"))>=0) {
 117                     $runtime.consumeAttribute($ai);
 118                     $runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
 119                 }
 120                 else {
 121                     $_ngcc_current_state = 11;
 122                     $runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
 123                 }
 124             }
 125             break;
 126         case 0:
 127             {
 128                 revertToParentFromEnterElement(result, super._cookie, $__uri, $__local, $__qname, $attrs);
 129             }
 130             break;
 131         case 11:
 132             {
 133                 if(($ai = $runtime.getAttributeIndex("","name"))>=0) {
 134                     $runtime.consumeAttribute($ai);
 135                     $runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
 136                 }
 137                 else {
 138                     $_ngcc_current_state = 10;
 139                     $runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
 140                 }
 141             }
 142             break;
 143         case 19:
 144             {
 145                 if(($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("simpleType"))) {
 146                     $runtime.onEnterElementConsumed($__uri, $__local, $__qname, $attrs);
 147                     action1();
 148                     $_ngcc_current_state = 15;
 149                 }
 150                 else {
 151                     unexpectedEnterElement($__qname);
 152                 }
 153             }
 154             break;
 155         case 10:
 156             {
 157                 if((($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("annotation")) || (($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("union")) || (($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("restriction")) || ($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("list")))))) {
 158                     NGCCHandler h = new foreignAttributes(this, super._source, $runtime, 188, fa);
 159                     spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
 160                 }
 161                 else {
 162                     unexpectedEnterElement($__qname);
 163                 }
 164             }
 165             break;
 166         case 8:
 167             {
 168                 if(($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("annotation"))) {
 169                     NGCCHandler h = new annotation(this, super._source, $runtime, 186, null,AnnotationContext.SIMPLETYPE_DECL);
 170                     spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
 171                 }
 172                 else {
 173                     $_ngcc_current_state = 7;
 174                     $runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
 175                 }
 176             }
 177             break;
 178         default:
 179             {
 180                 unexpectedEnterElement($__qname);
 181             }
 182             break;
 183         }
 184     }
 185 
 186     public void leaveElement(String $__uri, String $__local, String $__qname) throws SAXException {
 187         int $ai;
 188         $uri = $__uri;
 189         $localName = $__local;
 190         $qname = $__qname;
 191         switch($_ngcc_current_state) {
 192         case 7:
 193             {
 194                 action0();
 195                 $_ngcc_current_state = 2;
 196                 $runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
 197             }
 198             break;
 199         case 15:
 200             {
 201                 if(($ai = $runtime.getAttributeIndex("","final"))>=0) {
 202                     $runtime.consumeAttribute($ai);
 203                     $runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
 204                 }
 205                 else {
 206                     $_ngcc_current_state = 11;
 207                     $runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
 208                 }
 209             }
 210             break;
 211         case 0:
 212             {
 213                 revertToParentFromLeaveElement(result, super._cookie, $__uri, $__local, $__qname);
 214             }
 215             break;
 216         case 11:
 217             {
 218                 if(($ai = $runtime.getAttributeIndex("","name"))>=0) {
 219                     $runtime.consumeAttribute($ai);
 220                     $runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
 221                 }
 222                 else {
 223                     $_ngcc_current_state = 10;
 224                     $runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
 225                 }
 226             }
 227             break;
 228         case 8:
 229             {
 230                 $_ngcc_current_state = 7;
 231                 $runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
 232             }
 233             break;
 234         case 1:
 235             {
 236                 if(($__uri.equals("http://www.w3.org/2001/XMLSchema") && $__local.equals("simpleType"))) {
 237                     $runtime.onLeaveElementConsumed($__uri, $__local, $__qname);
 238                     $_ngcc_current_state = 0;
 239                 }
 240                 else {
 241                     unexpectedLeaveElement($__qname);
 242                 }
 243             }
 244             break;
 245         default:
 246             {
 247                 unexpectedLeaveElement($__qname);
 248             }
 249             break;
 250         }
 251     }
 252 
 253     public void enterAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
 254         int $ai;
 255         $uri = $__uri;
 256         $localName = $__local;
 257         $qname = $__qname;
 258         switch($_ngcc_current_state) {
 259         case 7:
 260             {
 261                 action0();
 262                 $_ngcc_current_state = 2;
 263                 $runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
 264             }
 265             break;
 266         case 15:
 267             {
 268                 if(($__uri.equals("") && $__local.equals("final"))) {
 269                     $_ngcc_current_state = 17;
 270                 }
 271                 else {
 272                     $_ngcc_current_state = 11;
 273                     $runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
 274                 }
 275             }
 276             break;
 277         case 0:
 278             {
 279                 revertToParentFromEnterAttribute(result, super._cookie, $__uri, $__local, $__qname);
 280             }
 281             break;
 282         case 11:
 283             {
 284                 if(($__uri.equals("") && $__local.equals("name"))) {
 285                     $_ngcc_current_state = 13;
 286                 }
 287                 else {
 288                     $_ngcc_current_state = 10;
 289                     $runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
 290                 }
 291             }
 292             break;
 293         case 8:
 294             {
 295                 $_ngcc_current_state = 7;
 296                 $runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
 297             }
 298             break;
 299         default:
 300             {
 301                 unexpectedEnterAttribute($__qname);
 302             }
 303             break;
 304         }
 305     }
 306 
 307     public void leaveAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
 308         int $ai;
 309         $uri = $__uri;
 310         $localName = $__local;
 311         $qname = $__qname;
 312         switch($_ngcc_current_state) {
 313         case 7:
 314             {
 315                 action0();
 316                 $_ngcc_current_state = 2;
 317                 $runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
 318             }
 319             break;
 320         case 15:
 321             {
 322                 $_ngcc_current_state = 11;
 323                 $runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
 324             }
 325             break;
 326         case 16:
 327             {
 328                 if(($__uri.equals("") && $__local.equals("final"))) {
 329                     $_ngcc_current_state = 11;
 330                 }
 331                 else {
 332                     unexpectedLeaveAttribute($__qname);
 333                 }
 334             }
 335             break;
 336         case 12:
 337             {
 338                 if(($__uri.equals("") && $__local.equals("name"))) {
 339                     $_ngcc_current_state = 10;
 340                 }
 341                 else {
 342                     unexpectedLeaveAttribute($__qname);
 343                 }
 344             }
 345             break;
 346         case 0:
 347             {
 348                 revertToParentFromLeaveAttribute(result, super._cookie, $__uri, $__local, $__qname);
 349             }
 350             break;
 351         case 11:
 352             {
 353                 $_ngcc_current_state = 10;
 354                 $runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
 355             }
 356             break;
 357         case 8:
 358             {
 359                 $_ngcc_current_state = 7;
 360                 $runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
 361             }
 362             break;
 363         default:
 364             {
 365                 unexpectedLeaveAttribute($__qname);
 366             }
 367             break;
 368         }
 369     }
 370 
 371     public void text(String $value) throws SAXException {
 372         int $ai;
 373         switch($_ngcc_current_state) {
 374         case 7:
 375             {
 376                 action0();
 377                 $_ngcc_current_state = 2;
 378                 $runtime.sendText(super._cookie, $value);
 379             }
 380             break;
 381         case 15:
 382             {
 383                 if(($ai = $runtime.getAttributeIndex("","final"))>=0) {
 384                     $runtime.consumeAttribute($ai);
 385                     $runtime.sendText(super._cookie, $value);
 386                 }
 387                 else {
 388                     $_ngcc_current_state = 11;
 389                     $runtime.sendText(super._cookie, $value);
 390                 }
 391             }
 392             break;
 393         case 13:
 394             {
 395                 name = $value;
 396                 $_ngcc_current_state = 12;
 397             }
 398             break;
 399         case 0:
 400             {
 401                 revertToParentFromText(result, super._cookie, $value);
 402             }
 403             break;
 404         case 11:
 405             {
 406                 if(($ai = $runtime.getAttributeIndex("","name"))>=0) {
 407                     $runtime.consumeAttribute($ai);
 408                     $runtime.sendText(super._cookie, $value);
 409                 }
 410                 else {
 411                     $_ngcc_current_state = 10;
 412                     $runtime.sendText(super._cookie, $value);
 413                 }
 414             }
 415             break;
 416         case 17:
 417             {
 418                 finalValue = $value;
 419                 $_ngcc_current_state = 16;
 420             }
 421             break;
 422         case 8:
 423             {
 424                 $_ngcc_current_state = 7;
 425                 $runtime.sendText(super._cookie, $value);
 426             }
 427             break;
 428         }
 429     }
 430 
 431     public void onChildCompleted(Object $__result__, int $__cookie__, boolean $__needAttCheck__)throws SAXException {
 432         switch($__cookie__) {
 433         case 186:
 434             {
 435                 annotation = ((AnnotationImpl)$__result__);
 436                 $_ngcc_current_state = 7;
 437             }
 438             break;
 439         case 188:
 440             {
 441                 fa = ((ForeignAttributesImpl)$__result__);
 442                 $_ngcc_current_state = 8;
 443             }
 444             break;
 445         case 182:
 446             {
 447                 result = ((RestrictionSimpleTypeImpl)$__result__);
 448                 $_ngcc_current_state = 1;
 449             }
 450             break;
 451         case 183:
 452             {
 453                 result = ((ListSimpleTypeImpl)$__result__);
 454                 $_ngcc_current_state = 1;
 455             }
 456             break;
 457         case 177:
 458             {
 459                 result = ((UnionSimpleTypeImpl)$__result__);
 460                 $_ngcc_current_state = 1;
 461             }
 462             break;
 463         }
 464     }
 465 
 466     public boolean accepted() {
 467         return(($_ngcc_current_state == 0));
 468     }
 469 
 470 
 471                 /** computed simple type object */
 472                 private SimpleTypeImpl result;
 473 
 474                 private Locator locator;
 475 
 476       private Set finalSet;
 477 
 478       private Set makeFinalSet(String finalValue) {
 479         if(finalValue==null)
 480           return Collections.EMPTY_SET;
 481 
 482         Set s = new HashSet();
 483         StringTokenizer tokens = new StringTokenizer(finalValue);
 484         while(tokens.hasMoreTokens()) {
 485           String token = tokens.nextToken();
 486           if(token.equals("#all")) {
 487             s.add(XSVariety.ATOMIC);
 488             s.add(XSVariety.UNION);
 489             s.add(XSVariety.LIST);
 490           }
 491           if(token.equals("list")) {
 492             s.add(XSVariety.LIST);
 493           }
 494           if(token.equals("union")) {
 495             s.add(XSVariety.UNION);
 496           }
 497           if(token.equals("restriction")) {
 498             s.add(XSVariety.ATOMIC);
 499           }
 500         }
 501         return s;
 502       }
 503 
 504 }