View Javadoc
1   /*
2    * Copyright (c) 1997, 2010, 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  /* Generated By:JavaCC: Do not edit this line. SCDParser.java */
27  package com.sun.xml.internal.xsom.impl.scd;
28  
29  import java.util.*;
30  import java.io.*;
31  import com.sun.xml.internal.xsom.impl.UName;
32  import javax.xml.namespace.*;
33  
34  public class SCDParser implements SCDParserConstants {
35    private NamespaceContext nsc;
36    public SCDParser(String text,NamespaceContext nsc) {
37      this(new StringReader(text));
38      this.nsc = nsc;
39    }
40    private String trim(String s) {
41      return s.substring(1,s.length()-1);
42    }
43    private String resolvePrefix(String prefix) throws ParseException {
44      try {
45        String r=nsc.getNamespaceURI(prefix);
46        // grrr!!
47        if(prefix.equals(""))
48          return r;
49        if(!r.equals(""))
50          return r;
51      } catch( IllegalArgumentException e ) {
52        ; // report an error
53      }
54      throw new ParseException("Unbound prefix: "+prefix);
55    }
56  
57    // "[^:]+"
58    final public UName QName() throws ParseException {
59                    Token p,l=null;
60      p = jj_consume_token(NCNAME);
61      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
62      case 15:
63        jj_consume_token(15);
64        l = jj_consume_token(NCNAME);
65        break;
66      default:
67        jj_la1[0] = jj_gen;
68        ;
69      }
70      if(l==null)
71        {if (true) return new UName(resolvePrefix(""),p.image);}
72      else
73        {if (true) return new UName(resolvePrefix(p.image),l.image);}
74      throw new Error("Missing return statement in function");
75    }
76  
77    final public String Prefix() throws ParseException {
78                      Token p;
79      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
80      case NCNAME:
81        p = jj_consume_token(NCNAME);
82                {if (true) return resolvePrefix(p.image);}
83        break;
84      default:
85        jj_la1[1] = jj_gen;
86     {if (true) return resolvePrefix("");}
87      }
88      throw new Error("Missing return statement in function");
89    }
90  
91    final public List RelativeSchemaComponentPath() throws ParseException {
92    List steps = new ArrayList();
93    Step s;
94      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
95      case 16:
96      case 17:
97        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
98        case 16:
99          jj_consume_token(16);
100           steps.add(new Step.Any(Axis.ROOT));
101         break;
102       case 17:
103         jj_consume_token(17);
104           steps.add(new Step.Any(Axis.DESCENDANTS));
105         break;
106       default:
107         jj_la1[2] = jj_gen;
108         jj_consume_token(-1);
109         throw new ParseException();
110       }
111       break;
112     default:
113       jj_la1[3] = jj_gen;
114       ;
115     }
116     s = Step();
117             steps.add(s);
118     label_1:
119     while (true) {
120       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
121       case 16:
122       case 17:
123         ;
124         break;
125       default:
126         jj_la1[4] = jj_gen;
127         break label_1;
128       }
129       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
130       case 16:
131         jj_consume_token(16);
132         break;
133       case 17:
134         jj_consume_token(17);
135             steps.add(new Step.Any(Axis.DESCENDANTS));
136         break;
137       default:
138         jj_la1[5] = jj_gen;
139         jj_consume_token(-1);
140         throw new ParseException();
141       }
142       s = Step();
143               steps.add(s);
144     }
145     {if (true) return steps;}
146     throw new Error("Missing return statement in function");
147   }
148 
149   final public Step Step() throws ParseException {
150   Step s; String p; Token n;
151     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
152     case 18:
153     case 19:
154       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
155       case 18:
156         jj_consume_token(18);
157         break;
158       case 19:
159         jj_consume_token(19);
160         break;
161       default:
162         jj_la1[6] = jj_gen;
163         jj_consume_token(-1);
164         throw new ParseException();
165       }
166       s = NameOrWildcard(Axis.ATTRIBUTE);
167       break;
168     case NCNAME:
169     case 20:
170     case 45:
171       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
172       case 20:
173         jj_consume_token(20);
174         break;
175       default:
176         jj_la1[7] = jj_gen;
177         ;
178       }
179       s = NameOrWildcard(Axis.ELEMENT);
180       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
181       case NUMBER:
182         Predicate(s);
183         break;
184       default:
185         jj_la1[8] = jj_gen;
186         ;
187       }
188       break;
189     case 21:
190       jj_consume_token(21);
191       s = NameOrWildcard(Axis.SUBSTITUTION_GROUP);
192       break;
193     case 22:
194     case 23:
195       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
196       case 22:
197         jj_consume_token(22);
198         break;
199       case 23:
200         jj_consume_token(23);
201         break;
202       default:
203         jj_la1[9] = jj_gen;
204         jj_consume_token(-1);
205         throw new ParseException();
206       }
207       s = NameOrWildcardOrAnonymous(Axis.TYPE_DEFINITION);
208       break;
209     case 24:
210       jj_consume_token(24);
211       s = NameOrWildcard(Axis.BASETYPE);
212       break;
213     case 25:
214       jj_consume_token(25);
215       s = NameOrWildcard(Axis.PRIMITIVE_TYPE);
216       break;
217     case 26:
218       jj_consume_token(26);
219       s = NameOrWildcardOrAnonymous(Axis.ITEM_TYPE);
220       break;
221     case 27:
222       jj_consume_token(27);
223       s = NameOrWildcardOrAnonymous(Axis.MEMBER_TYPE);
224       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
225       case NUMBER:
226         Predicate(s);
227         break;
228       default:
229         jj_la1[10] = jj_gen;
230         ;
231       }
232       break;
233     case 28:
234       jj_consume_token(28);
235       s = NameOrWildcardOrAnonymous(Axis.SCOPE);
236       break;
237     case 29:
238       jj_consume_token(29);
239       s = NameOrWildcard(Axis.ATTRIBUTE_GROUP);
240       break;
241     case 30:
242       jj_consume_token(30);
243       s = NameOrWildcard(Axis.MODEL_GROUP_DECL);
244       break;
245     case 31:
246       jj_consume_token(31);
247       s = NameOrWildcard(Axis.IDENTITY_CONSTRAINT);
248       break;
249     case 32:
250       jj_consume_token(32);
251       s = NameOrWildcard(Axis.REFERENCED_KEY);
252       break;
253     case 33:
254       jj_consume_token(33);
255       s = NameOrWildcard(Axis.NOTATION);
256       break;
257     case 34:
258       jj_consume_token(34);
259                            s=new Step.Any(Axis.MODELGROUP_SEQUENCE);
260       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
261       case NUMBER:
262         Predicate(s);
263         break;
264       default:
265         jj_la1[11] = jj_gen;
266         ;
267       }
268       break;
269     case 35:
270       jj_consume_token(35);
271                            s=new Step.Any(Axis.MODELGROUP_CHOICE);
272       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
273       case NUMBER:
274         Predicate(s);
275         break;
276       default:
277         jj_la1[12] = jj_gen;
278         ;
279       }
280       break;
281     case 36:
282       jj_consume_token(36);
283                            s=new Step.Any(Axis.MODELGROUP_ALL);
284       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
285       case NUMBER:
286         Predicate(s);
287         break;
288       default:
289         jj_la1[13] = jj_gen;
290         ;
291       }
292       break;
293     case 37:
294       jj_consume_token(37);
295                            s=new Step.Any(Axis.MODELGROUP_ANY);
296       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
297       case NUMBER:
298         Predicate(s);
299         break;
300       default:
301         jj_la1[14] = jj_gen;
302         ;
303       }
304       break;
305     case 38:
306       jj_consume_token(38);
307                            s=new Step.Any(Axis.WILDCARD);
308       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
309       case NUMBER:
310         Predicate(s);
311         break;
312       default:
313         jj_la1[15] = jj_gen;
314         ;
315       }
316       break;
317     case 39:
318       jj_consume_token(39);
319                            s=new Step.Any(Axis.ATTRIBUTE_WILDCARD);
320       break;
321     case 40:
322       jj_consume_token(40);
323                            s=new Step.Any(Axis.FACET);
324       break;
325     case 41:
326       jj_consume_token(41);
327       n = jj_consume_token(FACETNAME);
328                            s=new Step.Facet(Axis.FACET,n.image);
329       break;
330     case 42:
331       jj_consume_token(42);
332                            s=new Step.Any(Axis.DESCENDANTS);
333       break;
334     case 43:
335       jj_consume_token(43);
336       p = Prefix();
337                            s=new Step.Schema(Axis.X_SCHEMA,p);
338       break;
339     case 44:
340       jj_consume_token(44);
341                            s=new Step.Any(Axis.X_SCHEMA);
342       break;
343     default:
344       jj_la1[16] = jj_gen;
345       jj_consume_token(-1);
346       throw new ParseException();
347     }
348    {if (true) return s;}
349     throw new Error("Missing return statement in function");
350   }
351 
352   final public Step NameOrWildcard(Axis a) throws ParseException {
353                                UName un;
354     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
355     case NCNAME:
356       un = QName();
357                {if (true) return new Step.Named(a,un);}
358       break;
359     case 45:
360       jj_consume_token(45);
361                {if (true) return new Step.Any(a);}
362       break;
363     default:
364       jj_la1[17] = jj_gen;
365       jj_consume_token(-1);
366       throw new ParseException();
367     }
368     throw new Error("Missing return statement in function");
369   }
370 
371   final public Step NameOrWildcardOrAnonymous(Axis a) throws ParseException {
372                                           UName un;
373     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
374     case NCNAME:
375       un = QName();
376                {if (true) return new Step.Named(a,un);}
377       break;
378     case 45:
379       jj_consume_token(45);
380                {if (true) return new Step.Any(a);}
381       break;
382     case 46:
383       jj_consume_token(46);
384                  {if (true) return new Step.AnonymousType(a);}
385       break;
386     default:
387       jj_la1[18] = jj_gen;
388       jj_consume_token(-1);
389       throw new ParseException();
390     }
391     throw new Error("Missing return statement in function");
392   }
393 
394   final public int Predicate(Step s) throws ParseException {
395   Token t;
396     t = jj_consume_token(NUMBER);
397                {if (true) return s.predicate=Integer.parseInt(trim(t.image));}
398     throw new Error("Missing return statement in function");
399   }
400 
401   public SCDParserTokenManager token_source;
402   SimpleCharStream jj_input_stream;
403   public Token token, jj_nt;
404   private int jj_ntk;
405   private int jj_gen;
406   final private int[] jj_la1 = new int[19];
407   static private int[] jj_la1_0;
408   static private int[] jj_la1_1;
409   static {
410       jj_la1_0();
411       jj_la1_1();
412    }
413    private static void jj_la1_0() {
414       jj_la1_0 = new int[] {0x8000,0x1000,0x30000,0x30000,0x30000,0x30000,0xc0000,0x100000,0x2000,0xc00000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0xfffc1000,0x1000,0x1000,};
415    }
416    private static void jj_la1_1() {
417       jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3fff,0x2000,0x6000,};
418    }
419 
420   public SCDParser(java.io.InputStream stream) {
421      this(stream, null);
422   }
423   public SCDParser(java.io.InputStream stream, String encoding) {
424     try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
425     token_source = new SCDParserTokenManager(jj_input_stream);
426     token = new Token();
427     jj_ntk = -1;
428     jj_gen = 0;
429     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
430   }
431 
432   public void ReInit(java.io.InputStream stream) {
433      ReInit(stream, null);
434   }
435   public void ReInit(java.io.InputStream stream, String encoding) {
436     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
437     token_source.ReInit(jj_input_stream);
438     token = new Token();
439     jj_ntk = -1;
440     jj_gen = 0;
441     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
442   }
443 
444   public SCDParser(java.io.Reader stream) {
445     jj_input_stream = new SimpleCharStream(stream, 1, 1);
446     token_source = new SCDParserTokenManager(jj_input_stream);
447     token = new Token();
448     jj_ntk = -1;
449     jj_gen = 0;
450     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
451   }
452 
453   public void ReInit(java.io.Reader stream) {
454     jj_input_stream.ReInit(stream, 1, 1);
455     token_source.ReInit(jj_input_stream);
456     token = new Token();
457     jj_ntk = -1;
458     jj_gen = 0;
459     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
460   }
461 
462   public SCDParser(SCDParserTokenManager tm) {
463     token_source = tm;
464     token = new Token();
465     jj_ntk = -1;
466     jj_gen = 0;
467     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
468   }
469 
470   public void ReInit(SCDParserTokenManager tm) {
471     token_source = tm;
472     token = new Token();
473     jj_ntk = -1;
474     jj_gen = 0;
475     for (int i = 0; i < 19; i++) jj_la1[i] = -1;
476   }
477 
478   final private Token jj_consume_token(int kind) throws ParseException {
479     Token oldToken;
480     if ((oldToken = token).next != null) token = token.next;
481     else token = token.next = token_source.getNextToken();
482     jj_ntk = -1;
483     if (token.kind == kind) {
484       jj_gen++;
485       return token;
486     }
487     token = oldToken;
488     jj_kind = kind;
489     throw generateParseException();
490   }
491 
492   final public Token getNextToken() {
493     if (token.next != null) token = token.next;
494     else token = token.next = token_source.getNextToken();
495     jj_ntk = -1;
496     jj_gen++;
497     return token;
498   }
499 
500   final public Token getToken(int index) {
501     Token t = token;
502     for (int i = 0; i < index; i++) {
503       if (t.next != null) t = t.next;
504       else t = t.next = token_source.getNextToken();
505     }
506     return t;
507   }
508 
509   final private int jj_ntk() {
510     if ((jj_nt=token.next) == null)
511       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
512     else
513       return (jj_ntk = jj_nt.kind);
514   }
515 
516   private java.util.Vector jj_expentries = new java.util.Vector();
517   private int[] jj_expentry;
518   private int jj_kind = -1;
519 
520   public ParseException generateParseException() {
521     jj_expentries.removeAllElements();
522     boolean[] la1tokens = new boolean[47];
523     for (int i = 0; i < 47; i++) {
524       la1tokens[i] = false;
525     }
526     if (jj_kind >= 0) {
527       la1tokens[jj_kind] = true;
528       jj_kind = -1;
529     }
530     for (int i = 0; i < 19; i++) {
531       if (jj_la1[i] == jj_gen) {
532         for (int j = 0; j < 32; j++) {
533           if ((jj_la1_0[i] & (1<<j)) != 0) {
534             la1tokens[j] = true;
535           }
536           if ((jj_la1_1[i] & (1<<j)) != 0) {
537             la1tokens[32+j] = true;
538           }
539         }
540       }
541     }
542     for (int i = 0; i < 47; i++) {
543       if (la1tokens[i]) {
544         jj_expentry = new int[1];
545         jj_expentry[0] = i;
546         jj_expentries.addElement(jj_expentry);
547       }
548     }
549     int[][] exptokseq = new int[jj_expentries.size()][];
550     for (int i = 0; i < jj_expentries.size(); i++) {
551       exptokseq[i] = (int[])jj_expentries.elementAt(i);
552     }
553     return new ParseException(token, exptokseq, tokenImage);
554   }
555 
556   final public void enable_tracing() {
557   }
558 
559   final public void disable_tracing() {
560   }
561 
562 }