FileDocCategorySizeDatePackage
SPathParser.javaAPI DocGlassfish v2 API17543Sat May 05 19:17:16 BST 2007org.apache.taglibs.standard.extra.spath

SPathParser

public class SPathParser extends Object implements SPathParserConstants

Fields Summary
public SPathParserTokenManager
token_source
ASCII_UCodeESC_CharStream
jj_input_stream
public Token
token
public Token
jj_nt
private int
jj_ntk
private Token
jj_scanpos
private Token
jj_lastpos
private int
jj_la
public boolean
lookingAhead
private boolean
jj_semLA
private int
jj_gen
private final int[]
jj_la1
private final int[]
jj_la1_0
private final JJCalls[]
jj_2_rtns
private boolean
jj_rescan
private int
jj_gc
private Vector
jj_expentries
private int[]
jj_expentry
private int
jj_kind
private int[]
jj_lasttokens
private int
jj_endpos
Constructors Summary
public SPathParser(String x)

    this(new java.io.StringReader(x));
  
public SPathParser(InputStream stream)


     
    jj_input_stream = new ASCII_UCodeESC_CharStream(stream, 1, 1);
    token_source = new SPathParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  
public SPathParser(Reader stream)

    jj_input_stream = new ASCII_UCodeESC_CharStream(stream, 1, 1);
    token_source = new SPathParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  
public SPathParser(SPathParserTokenManager tm)

    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  
Methods Summary
public voidReInit(java.io.InputStream stream)

    jj_input_stream.ReInit(stream, 1, 1);
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  
public voidReInit(java.io.Reader stream)

    jj_input_stream.ReInit(stream, 1, 1);
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  
public voidReInit(SPathParserTokenManager tm)

    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  
public final AbsolutePathabsolutePath()

  RelativePath relPath;
    jj_consume_token(SLASH);
    relPath = relativePath();
   {if (true) return new AbsolutePath(relPath);}
    throw new Error("Missing return statement in function");
  
public final PredicateattributePredicate()

  Token attname, target;
    jj_consume_token(AT);
    attname = jj_consume_token(QNAME);
    jj_consume_token(EQUALS);
    target = jj_consume_token(LITERAL);
    {if (true) return new AttributePredicate(attname.toString(), target.toString());}
    throw new Error("Missing return statement in function");
  
public final voiddisable_tracing()

  
public final voidenable_tracing()

  
public final Pathexpression()

  Path expr;
    if (jj_2_1(2147483647)) {
      expr = absolutePath();
      jj_consume_token(0);
    } else {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case QNAME:
      case NSWILDCARD:
      case SLASH:
      case STAR:
        expr = relativePath();
        jj_consume_token(0);
        break;
      default:
        jj_la1[0] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
   {if (true) return expr;}
    throw new Error("Missing return statement in function");
  
public final ParseExceptiongenerateParseException()

    jj_expentries.removeAllElements();
    boolean[] la1tokens = new boolean[20];
    for (int i = 0; i < 20; i++) {
      la1tokens[i] = false;
    }
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 5; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<<j)) != 0) {
            la1tokens[j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 20; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.addElement(jj_expentry);
      }
    }
    jj_endpos = 0;
    jj_rescan_token();
    jj_add_error_token(0, 0);
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = (int[])jj_expentries.elementAt(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  
public final TokengetNextToken()

    if (token.next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    jj_gen++;
    return token;
  
public final TokengetToken(int index)

    Token t = lookingAhead ? jj_scanpos : token;
    for (int i = 0; i < index; i++) {
      if (t.next != null) t = t.next;
      else t = t.next = token_source.getNextToken();
    }
    return t;
  
private final booleanjj_2_1(int xla)

    jj_la = xla; jj_lastpos = jj_scanpos = token;
    boolean retval = !jj_3_1();
    jj_save(0, xla);
    return retval;
  
private final booleanjj_3R_10()

    if (jj_scan_token(NSWILDCARD)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_11()

    if (jj_scan_token(QNAME)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_12()

    if (jj_scan_token(START_BRACKET)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_3R_13()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_scan_token(END_BRACKET)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_13()

    if (jj_scan_token(AT)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_scan_token(QNAME)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_scan_token(EQUALS)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_scan_token(LITERAL)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_2()

    if (jj_scan_token(SLASH)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_3R_3()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_3()

    if (jj_3R_4()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_5()) jj_scanpos = xsp;
    else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_4()

    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_6()) jj_scanpos = xsp;
    else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_3R_7()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    while (true) {
      xsp = jj_scanpos;
      if (jj_3R_8()) { jj_scanpos = xsp; break; }
      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    }
    return false;
  
private final booleanjj_3R_5()

    if (jj_scan_token(SLASH)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    if (jj_3R_3()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_6()

    if (jj_scan_token(SLASH)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_7()

    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_9()) {
    jj_scanpos = xsp;
    if (jj_3R_10()) {
    jj_scanpos = xsp;
    if (jj_3R_11()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_8()

    if (jj_3R_12()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3R_9()

    if (jj_scan_token(STAR)) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private final booleanjj_3_1()

    if (jj_3R_2()) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
    return false;
  
private voidjj_add_error_token(int kind, int pos)


        
    if (pos >= 100) return;
    if (pos == jj_endpos + 1) {
      jj_lasttokens[jj_endpos++] = kind;
    } else if (jj_endpos != 0) {
      jj_expentry = new int[jj_endpos];
      for (int i = 0; i < jj_endpos; i++) {
        jj_expentry[i] = jj_lasttokens[i];
      }
      boolean exists = false;
      for (java.util.Enumeration enum_ = jj_expentries.elements(); enum_.hasMoreElements();) {
        int[] oldentry = (int[])(enum_.nextElement());
        if (oldentry.length == jj_expentry.length) {
          exists = true;
          for (int i = 0; i < jj_expentry.length; i++) {
            if (oldentry[i] != jj_expentry[i]) {
              exists = false;
              break;
            }
          }
          if (exists) break;
        }
      }
      if (!exists) jj_expentries.addElement(jj_expentry);
      if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
    }
  
private final Tokenjj_consume_token(int kind)

    Token oldToken;
    if ((oldToken = token).next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    if (token.kind == kind) {
      jj_gen++;
      if (++jj_gc > 100) {
        jj_gc = 0;
        for (int i = 0; i < jj_2_rtns.length; i++) {
          JJCalls c = jj_2_rtns[i];
          while (c != null) {
            if (c.gen < jj_gen) c.first = null;
            c = c.next;
          }
        }
      }
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  
private final intjj_ntk()

    if ((jj_nt=token.next) == null)
      return (jj_ntk = (token.next=token_source.getNextToken()).kind);
    else
      return (jj_ntk = jj_nt.kind);
  
private final voidjj_rescan_token()

    jj_rescan = true;
    for (int i = 0; i < 1; i++) {
      JJCalls p = jj_2_rtns[i];
      do {
        if (p.gen > jj_gen) {
          jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
          switch (i) {
            case 0: jj_3_1(); break;
          }
        }
        p = p.next;
      } while (p != null);
    }
    jj_rescan = false;
  
private final voidjj_save(int index, int xla)

    JJCalls p = jj_2_rtns[index];
    while (p.gen > jj_gen) {
      if (p.next == null) { p = p.next = new JJCalls(); break; }
      p = p.next;
    }
    p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
  
private final booleanjj_scan_token(int kind)

    if (jj_scanpos == jj_lastpos) {
      jj_la--;
      if (jj_scanpos.next == null) {
        jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
      } else {
        jj_lastpos = jj_scanpos = jj_scanpos.next;
      }
    } else {
      jj_scanpos = jj_scanpos.next;
    }
    if (jj_rescan) {
      int i = 0; Token tok = token;
      while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
      if (tok != null) jj_add_error_token(kind, i);
    }
    return (jj_scanpos.kind != kind);
  
public static voidmain(java.lang.String[] args)
Simple command-line parser interface, primarily for testing.

    SPathParser parser = new SPathParser(System.in);
    Path p = parser.expression();
    java.util.List l = p.getSteps();

    // output for simple testing
    System.out.println();
    if (p instanceof AbsolutePath)
        System.out.println("Root: /");
    for (int i = 0; i < l.size(); i++) {
        Step s = (Step) l.get(i);
        System.out.print("Step: " + s.getName());
        if (s.isDepthUnlimited())
            System.out.print("(*)");
        System.out.println();
    }
  
public final java.lang.StringnameTest()

  Token name;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case STAR:
      name = jj_consume_token(STAR);
      break;
    case NSWILDCARD:
      name = jj_consume_token(NSWILDCARD);
      break;
    case QNAME:
      name = jj_consume_token(QNAME);
      break;
    default:
      jj_la1[4] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
   {if (true) return name.toString();}
    throw new Error("Missing return statement in function");
  
public final Predicatepredicate()

  Predicate p;
    jj_consume_token(START_BRACKET);
    p = attributePredicate();
    jj_consume_token(END_BRACKET);
    {if (true) return p;}
    throw new Error("Missing return statement in function");
  
public final RelativePathrelativePath()

  RelativePath relPath = null;
  Step step;
    step = step();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case SLASH:
      jj_consume_token(SLASH);
      relPath = relativePath();
      break;
    default:
      jj_la1[1] = jj_gen;
      ;
    }
   {if (true) return new RelativePath(step, relPath);}
    throw new Error("Missing return statement in function");
  
public final Stepstep()

  Token slash = null;
  String nt;
  Vector pl = null;
  Predicate p;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case SLASH:
      slash = jj_consume_token(SLASH);
      break;
    default:
      jj_la1[2] = jj_gen;
      ;
    }
    nt = nameTest();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case START_BRACKET:
        ;
        break;
      default:
        jj_la1[3] = jj_gen;
        break label_1;
      }
      p = predicate();
          if (pl == null) pl = new Vector();
          pl.add(p);
    }
   // if 'slash != null', then we have '//' versus '/'
   {if (true) return new Step(slash != null, nt, pl);}
    throw new Error("Missing return statement in function");