0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: /* Generated By:JavaCC: Do not edit this line. LdapUrlParser.java */
0018:
0019: package org.apache.harmony.jndi.provider.ldap.parser;
0020:
0021: import java.io.FileInputStream;
0022: import java.io.FileNotFoundException;
0023: import java.util.ArrayList;
0024: import java.util.List;
0025: import java.io.StringReader;
0026: import javax.naming.directory.SearchControls;
0027: import org.apache.harmony.jndi.provider.ldap.Filter;
0028: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
0029:
0030: public class LdapUrlParser implements LdapUrlParserConstants {
0031: private SearchControls controls;
0032:
0033: private Filter filter;
0034:
0035: private String baseObject = "";
0036:
0037: private String host = DEFAULT_HOST;
0038:
0039: private int port = DEFAULT_PORT;
0040:
0041: private boolean hasAttributes = false;
0042:
0043: private boolean hasScope = false;
0044:
0045: private boolean hasFilter = false;
0046:
0047: private boolean hasExtensions = false;
0048:
0049: private boolean isEndEOF = false;
0050:
0051: private static final int DEFAULT_PORT = 389;
0052:
0053: private static final int DEFAULT_SSL_PORT = 636;
0054:
0055: private static final String DEFAULT_HOST = "localhost";
0056:
0057: public LdapUrlParser(String url) {
0058: this (new StringReader(url));
0059: isEndEOF = true;
0060: }
0061:
0062: public SearchControls getControls() {
0063: return controls;
0064: }
0065:
0066: public Filter getFilter() {
0067: return filter;
0068: }
0069:
0070: private String convertToUtf8Char(String s) {
0071: byte[] bs = new byte[] { (byte) Integer.parseInt(s, 16) };
0072: return Utils.getString(bs);
0073: }
0074:
0075: /**
0076: * get the host part of the url, if host part is omitted, <code>null</code>
0077: * will be return
0078: *
0079: * @return host part of the url or <code>null</code> if it's omitted
0080: */
0081: public String getHost() {
0082: return host;
0083: }
0084:
0085: /**
0086: * get the port number of the url, if this part is omitted, -1 will be
0087: * return
0088: *
0089: * @return port number of the url or -1 if it's omitted
0090: */
0091: public int getPort() {
0092: return port;
0093: }
0094:
0095: public String getBaseObject() {
0096: return baseObject;
0097: }
0098:
0099: public boolean hasFilter() {
0100: return hasFilter;
0101: }
0102:
0103: public boolean hasAttributes() {
0104: return hasAttributes;
0105: }
0106:
0107: public boolean hasScope() {
0108: return hasScope;
0109: }
0110:
0111: public boolean hasExtensions() {
0112: return hasExtensions;
0113: }
0114:
0115: public static void main(String args[]) throws ParseException,
0116: FileNotFoundException {
0117: LdapUrlParser parser = new LdapUrlParser(new FileInputStream(
0118: "parser.url.test"));
0119: // URLParser parser = new URLParser(System.in);
0120: // FilterParser parser = new FilterParser(System.in);
0121: //System.out.println(parser.value());
0122: parser.test();
0123: //parser.value();
0124: }
0125:
0126: final public void parseURL() throws ParseException {
0127: Token t;
0128: t = jj_consume_token(SCHEME);
0129: if (t.image.equals("ldaps://")) {
0130: port = DEFAULT_SSL_PORT;
0131: }
0132: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0133: case SCHEME:
0134: case PRE_XTOKEN:
0135: case SCOPE:
0136: case PERCENT:
0137: case PERIOD:
0138: case EXCLAM_MARK:
0139: case EQUAL:
0140: case HEX_CHAR:
0141: case NOHEX_CHAR:
0142: case DIGIT:
0143: case ZERO:
0144: case CHAR:
0145: hostport();
0146: break;
0147: default:
0148: jj_la1[0] = jj_gen;
0149: ;
0150: }
0151: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0152: case SLASH:
0153: jj_consume_token(SLASH);
0154: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0155: case SCHEME:
0156: case PRE_XTOKEN:
0157: case SCOPE:
0158: case PERCENT:
0159: case PERIOD:
0160: case EXCLAM_MARK:
0161: case EQUAL:
0162: case HEX_CHAR:
0163: case NOHEX_CHAR:
0164: case DIGIT:
0165: case ZERO:
0166: case CHAR:
0167: dn();
0168: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0169: case QUESTION_MARK:
0170: jj_consume_token(QUESTION_MARK);
0171: attributes();
0172: break;
0173: default:
0174: jj_la1[1] = jj_gen;
0175: ;
0176: }
0177: break;
0178: default:
0179: jj_la1[2] = jj_gen;
0180: ;
0181: }
0182: break;
0183: default:
0184: jj_la1[3] = jj_gen;
0185: ;
0186: }
0187: if (isEndEOF) {
0188: eof();
0189: }
0190: }
0191:
0192: final public void eof() throws ParseException {
0193: jj_consume_token(0);
0194: }
0195:
0196: final public String number() throws ParseException {
0197: StringBuilder value = new StringBuilder();
0198: Token t;
0199: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0200: case ZERO:
0201: t = jj_consume_token(ZERO);
0202: value.append(t.image);
0203: break;
0204: case DIGIT:
0205: t = jj_consume_token(DIGIT);
0206: value.append(t.image);
0207: label_1: while (true) {
0208: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0209: case DIGIT:
0210: case ZERO:
0211: ;
0212: break;
0213: default:
0214: jj_la1[4] = jj_gen;
0215: break label_1;
0216: }
0217: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0218: case ZERO:
0219: t = jj_consume_token(ZERO);
0220: value.append(t.image);
0221: break;
0222: case DIGIT:
0223: t = jj_consume_token(DIGIT);
0224: value.append(t.image);
0225: break;
0226: default:
0227: jj_la1[5] = jj_gen;
0228: jj_consume_token(-1);
0229: throw new ParseException();
0230: }
0231: }
0232: break;
0233: default:
0234: jj_la1[6] = jj_gen;
0235: jj_consume_token(-1);
0236: throw new ParseException();
0237: }
0238: {
0239: if (true)
0240: return value.toString();
0241: }
0242: throw new Error("Missing return statement in function");
0243: }
0244:
0245: final public String hexDigit() throws ParseException {
0246: String value;
0247: Token t;
0248: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0249: case HEX_CHAR:
0250: t = jj_consume_token(HEX_CHAR);
0251: break;
0252: case DIGIT:
0253: t = jj_consume_token(DIGIT);
0254: break;
0255: case ZERO:
0256: t = jj_consume_token(ZERO);
0257: break;
0258: default:
0259: jj_la1[7] = jj_gen;
0260: jj_consume_token(-1);
0261: throw new ParseException();
0262: }
0263: value = t.image;
0264: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0265: case HEX_CHAR:
0266: t = jj_consume_token(HEX_CHAR);
0267: break;
0268: case DIGIT:
0269: t = jj_consume_token(DIGIT);
0270: break;
0271: case ZERO:
0272: t = jj_consume_token(ZERO);
0273: break;
0274: default:
0275: jj_la1[8] = jj_gen;
0276: jj_consume_token(-1);
0277: throw new ParseException();
0278: }
0279: value += t.image;
0280: {
0281: if (true)
0282: return value;
0283: }
0284: throw new Error("Missing return statement in function");
0285: }
0286:
0287: final public String value() throws ParseException {
0288: StringBuilder value = new StringBuilder();
0289: String ch;
0290: label_2: while (true) {
0291: ch = ch();
0292: value.append(ch);
0293: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0294: case SCHEME:
0295: case PRE_XTOKEN:
0296: case SCOPE:
0297: case PERCENT:
0298: case PERIOD:
0299: case EXCLAM_MARK:
0300: case EQUAL:
0301: case HEX_CHAR:
0302: case NOHEX_CHAR:
0303: case DIGIT:
0304: case ZERO:
0305: case CHAR:
0306: ;
0307: break;
0308: default:
0309: jj_la1[9] = jj_gen;
0310: break label_2;
0311: }
0312: }
0313: {
0314: if (true)
0315: return value.toString();
0316: }
0317: throw new Error("Missing return statement in function");
0318: }
0319:
0320: final public String ch() throws ParseException {
0321: Token t;
0322: String value;
0323: String temp;
0324: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0325: case CHAR:
0326: t = jj_consume_token(CHAR);
0327: value = t.image;
0328: break;
0329: case PERCENT:
0330: t = jj_consume_token(PERCENT);
0331: value = hexDigit();
0332: value = convertToUtf8Char(value);
0333: break;
0334: case ZERO:
0335: t = jj_consume_token(ZERO);
0336: value = t.image;
0337: break;
0338: case DIGIT:
0339: t = jj_consume_token(DIGIT);
0340: value = t.image;
0341: break;
0342: case HEX_CHAR:
0343: t = jj_consume_token(HEX_CHAR);
0344: value = t.image;
0345: break;
0346: case NOHEX_CHAR:
0347: t = jj_consume_token(NOHEX_CHAR);
0348: value = t.image;
0349: break;
0350: case SCHEME:
0351: t = jj_consume_token(SCHEME);
0352: value = t.image;
0353: break;
0354: case EQUAL:
0355: t = jj_consume_token(EQUAL);
0356: value = t.image;
0357: break;
0358: case PERIOD:
0359: t = jj_consume_token(PERIOD);
0360: value = t.image;
0361: break;
0362: case EXCLAM_MARK:
0363: t = jj_consume_token(EXCLAM_MARK);
0364: value = t.image;
0365: break;
0366: case SCOPE:
0367: t = jj_consume_token(SCOPE);
0368: value = t.image;
0369: break;
0370: case PRE_XTOKEN:
0371: t = jj_consume_token(PRE_XTOKEN);
0372: value = t.image;
0373: break;
0374: default:
0375: jj_la1[10] = jj_gen;
0376: jj_consume_token(-1);
0377: throw new ParseException();
0378: }
0379: {
0380: if (true)
0381: return value;
0382: }
0383: throw new Error("Missing return statement in function");
0384: }
0385:
0386: final public void hostport() throws ParseException {
0387: String ch;
0388: StringBuilder h = new StringBuilder();
0389: label_3: while (true) {
0390: ch = ch();
0391: h.append(ch);
0392: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0393: case SCHEME:
0394: case PRE_XTOKEN:
0395: case SCOPE:
0396: case PERCENT:
0397: case PERIOD:
0398: case EXCLAM_MARK:
0399: case EQUAL:
0400: case HEX_CHAR:
0401: case NOHEX_CHAR:
0402: case DIGIT:
0403: case ZERO:
0404: case CHAR:
0405: ;
0406: break;
0407: default:
0408: jj_la1[11] = jj_gen;
0409: break label_3;
0410: }
0411: }
0412: host = h.toString();
0413: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0414: case COLON:
0415: jj_consume_token(COLON);
0416: ch = number();
0417: port = Integer.valueOf(ch);
0418: break;
0419: default:
0420: jj_la1[12] = jj_gen;
0421: ;
0422: }
0423: }
0424:
0425: final public void dn() throws ParseException {
0426: Token t;
0427: String value;
0428: StringBuilder dn = new StringBuilder();
0429: value = value();
0430: dn.append(value);
0431: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0432: case COMMA:
0433: label_4: while (true) {
0434: t = jj_consume_token(COMMA);
0435: dn.append(t.image);
0436: value = value();
0437: dn.append(value);
0438: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0439: case COMMA:
0440: ;
0441: break;
0442: default:
0443: jj_la1[13] = jj_gen;
0444: break label_4;
0445: }
0446: }
0447: break;
0448: default:
0449: jj_la1[14] = jj_gen;
0450: ;
0451: }
0452: baseObject = dn.toString();
0453: }
0454:
0455: final public void attributes() throws ParseException {
0456: String value;
0457: List attrs = new ArrayList();
0458: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0459: case SCHEME:
0460: case PRE_XTOKEN:
0461: case SCOPE:
0462: case PERCENT:
0463: case PERIOD:
0464: case EXCLAM_MARK:
0465: case EQUAL:
0466: case HEX_CHAR:
0467: case NOHEX_CHAR:
0468: case DIGIT:
0469: case ZERO:
0470: case CHAR:
0471: value = value();
0472: attrs.add(value);
0473: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0474: case COMMA:
0475: label_5: while (true) {
0476: jj_consume_token(COMMA);
0477: value = value();
0478: attrs.add(value);
0479: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0480: case COMMA:
0481: ;
0482: break;
0483: default:
0484: jj_la1[15] = jj_gen;
0485: break label_5;
0486: }
0487: }
0488: break;
0489: default:
0490: jj_la1[16] = jj_gen;
0491: ;
0492: }
0493: break;
0494: default:
0495: jj_la1[17] = jj_gen;
0496: ;
0497: }
0498: if (attrs.size() != 0) {
0499: hasAttributes = true;
0500: if (controls == null) {
0501: // FIXME: test what default search parameter value is
0502: controls = new SearchControls();
0503: }
0504: controls.setReturningAttributes((String[]) attrs
0505: .toArray(new String[0]));
0506: }
0507: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0508: case QUESTION_MARK:
0509: jj_consume_token(QUESTION_MARK);
0510: scope();
0511: break;
0512: default:
0513: jj_la1[18] = jj_gen;
0514: ;
0515: }
0516: }
0517:
0518: final public void attrDescr() throws ParseException {
0519: value();
0520: }
0521:
0522: final public void scope() throws ParseException {
0523: Token t;
0524: String scope;
0525: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0526: case SCOPE:
0527: t = jj_consume_token(SCOPE);
0528: scope = t.image;
0529: hasScope = true;
0530: if (controls == null) {
0531: controls = new SearchControls();
0532: }
0533: if (scope.equals("base")) {
0534: controls.setSearchScope(SearchControls.OBJECT_SCOPE);
0535: } else if (scope.equals("one")) {
0536: controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
0537: } else {
0538: controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
0539: }
0540: break;
0541: default:
0542: jj_la1[19] = jj_gen;
0543: ;
0544: }
0545: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0546: case QUESTION_MARK:
0547: jj_consume_token(QUESTION_MARK);
0548: filter();
0549: break;
0550: default:
0551: jj_la1[20] = jj_gen;
0552: ;
0553: }
0554: }
0555:
0556: final public void filter() throws ParseException {
0557: String value;
0558: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0559: case SCHEME:
0560: case PRE_XTOKEN:
0561: case SCOPE:
0562: case PERCENT:
0563: case PERIOD:
0564: case EXCLAM_MARK:
0565: case EQUAL:
0566: case HEX_CHAR:
0567: case NOHEX_CHAR:
0568: case DIGIT:
0569: case ZERO:
0570: case CHAR:
0571: value = value();
0572: FilterParser parser = new FilterParser(new StringReader(
0573: value));
0574: filter = parser.parse();
0575: hasFilter = true;
0576: break;
0577: default:
0578: jj_la1[21] = jj_gen;
0579: ;
0580: }
0581: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0582: case QUESTION_MARK:
0583: jj_consume_token(QUESTION_MARK);
0584: extensions();
0585: break;
0586: default:
0587: jj_la1[22] = jj_gen;
0588: ;
0589: }
0590: }
0591:
0592: final public void extensions() throws ParseException {
0593: extension();
0594: hasExtensions = true;
0595: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0596: case COMMA:
0597: label_6: while (true) {
0598: jj_consume_token(COMMA);
0599: extension();
0600: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0601: case COMMA:
0602: ;
0603: break;
0604: default:
0605: jj_la1[23] = jj_gen;
0606: break label_6;
0607: }
0608: }
0609: break;
0610: default:
0611: jj_la1[24] = jj_gen;
0612: ;
0613: }
0614: }
0615:
0616: final public void extension() throws ParseException {
0617: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0618: case EXCLAM_MARK:
0619: jj_consume_token(EXCLAM_MARK);
0620: break;
0621: default:
0622: jj_la1[25] = jj_gen;
0623: ;
0624: }
0625: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0626: case DIGIT:
0627: case ZERO:
0628: oid();
0629: break;
0630: case PRE_XTOKEN:
0631: jj_consume_token(PRE_XTOKEN);
0632: oid();
0633: break;
0634: default:
0635: jj_la1[26] = jj_gen;
0636: jj_consume_token(-1);
0637: throw new ParseException();
0638: }
0639: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0640: case EQUAL:
0641: jj_consume_token(EQUAL);
0642: value();
0643: break;
0644: default:
0645: jj_la1[27] = jj_gen;
0646: ;
0647: }
0648: }
0649:
0650: final public String oid() throws ParseException {
0651: StringBuilder value = new StringBuilder();
0652: String number = null;
0653: Token t = null;
0654: number = number();
0655: value.append(number);
0656: label_7: while (true) {
0657: t = jj_consume_token(PERIOD);
0658: value.append(t.image);
0659: number = number();
0660: value.append(number);
0661: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0662: case PERIOD:
0663: ;
0664: break;
0665: default:
0666: jj_la1[28] = jj_gen;
0667: break label_7;
0668: }
0669: }
0670: {
0671: if (true)
0672: return value.toString();
0673: }
0674: throw new Error("Missing return statement in function");
0675: }
0676:
0677: final public void test() throws ParseException {
0678: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0679: case SCHEME:
0680: parseURL();
0681: jj_consume_token(17);
0682: test();
0683: break;
0684: default:
0685: jj_la1[29] = jj_gen;
0686: if (jj_2_1(2)) {
0687: jj_consume_token(17);
0688: } else {
0689: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0690: case 17:
0691: jj_consume_token(17);
0692: jj_consume_token(0);
0693: break;
0694: case 0:
0695: jj_consume_token(0);
0696: break;
0697: default:
0698: jj_la1[30] = jj_gen;
0699: jj_consume_token(-1);
0700: throw new ParseException();
0701: }
0702: }
0703: }
0704: }
0705:
0706: final private boolean jj_2_1(int xla) {
0707: jj_la = xla;
0708: jj_lastpos = jj_scanpos = token;
0709: try {
0710: return !jj_3_1();
0711: } catch (LookaheadSuccess ls) {
0712: return true;
0713: } finally {
0714: jj_save(0, xla);
0715: }
0716: }
0717:
0718: final private boolean jj_3_1() {
0719: if (jj_scan_token(17))
0720: return true;
0721: return false;
0722: }
0723:
0724: public LdapUrlParserTokenManager token_source;
0725: SimpleCharStream jj_input_stream;
0726: public Token token, jj_nt;
0727: private int jj_ntk;
0728: private Token jj_scanpos, jj_lastpos;
0729: private int jj_la;
0730: public boolean lookingAhead = false;
0731: private boolean jj_semLA;
0732: private int jj_gen;
0733: final private int[] jj_la1 = new int[31];
0734: static private int[] jj_la1_0;
0735: static {
0736: jj_la1_0();
0737: }
0738:
0739: private static void jj_la1_0() {
0740: jj_la1_0 = new int[] { 0x1fe8e, 0x20, 0x1fe8e, 0x40, 0xc000,
0741: 0xc000, 0xc000, 0xd000, 0xd000, 0x1fe8e, 0x1fe8e,
0742: 0x1fe8e, 0x100, 0x10, 0x10, 0x10, 0x10, 0x1fe8e, 0x20,
0743: 0x8, 0x20, 0x1fe8e, 0x20, 0x10, 0x10, 0x400, 0xc004,
0744: 0x800, 0x200, 0x2, 0x20001, };
0745: }
0746:
0747: final private JJCalls[] jj_2_rtns = new JJCalls[1];
0748: private boolean jj_rescan = false;
0749: private int jj_gc = 0;
0750:
0751: public LdapUrlParser(java.io.InputStream stream) {
0752: jj_input_stream = new SimpleCharStream(stream, 1, 1);
0753: token_source = new LdapUrlParserTokenManager(jj_input_stream);
0754: token = new Token();
0755: jj_ntk = -1;
0756: jj_gen = 0;
0757: for (int i = 0; i < 31; i++)
0758: jj_la1[i] = -1;
0759: for (int i = 0; i < jj_2_rtns.length; i++)
0760: jj_2_rtns[i] = new JJCalls();
0761: }
0762:
0763: public void ReInit(java.io.InputStream stream) {
0764: jj_input_stream.ReInit(stream, 1, 1);
0765: token_source.ReInit(jj_input_stream);
0766: token = new Token();
0767: jj_ntk = -1;
0768: jj_gen = 0;
0769: for (int i = 0; i < 31; i++)
0770: jj_la1[i] = -1;
0771: for (int i = 0; i < jj_2_rtns.length; i++)
0772: jj_2_rtns[i] = new JJCalls();
0773: }
0774:
0775: public LdapUrlParser(java.io.Reader stream) {
0776: jj_input_stream = new SimpleCharStream(stream, 1, 1);
0777: token_source = new LdapUrlParserTokenManager(jj_input_stream);
0778: token = new Token();
0779: jj_ntk = -1;
0780: jj_gen = 0;
0781: for (int i = 0; i < 31; i++)
0782: jj_la1[i] = -1;
0783: for (int i = 0; i < jj_2_rtns.length; i++)
0784: jj_2_rtns[i] = new JJCalls();
0785: }
0786:
0787: public void ReInit(java.io.Reader stream) {
0788: jj_input_stream.ReInit(stream, 1, 1);
0789: token_source.ReInit(jj_input_stream);
0790: token = new Token();
0791: jj_ntk = -1;
0792: jj_gen = 0;
0793: for (int i = 0; i < 31; i++)
0794: jj_la1[i] = -1;
0795: for (int i = 0; i < jj_2_rtns.length; i++)
0796: jj_2_rtns[i] = new JJCalls();
0797: }
0798:
0799: public LdapUrlParser(LdapUrlParserTokenManager tm) {
0800: token_source = tm;
0801: token = new Token();
0802: jj_ntk = -1;
0803: jj_gen = 0;
0804: for (int i = 0; i < 31; i++)
0805: jj_la1[i] = -1;
0806: for (int i = 0; i < jj_2_rtns.length; i++)
0807: jj_2_rtns[i] = new JJCalls();
0808: }
0809:
0810: public void ReInit(LdapUrlParserTokenManager tm) {
0811: token_source = tm;
0812: token = new Token();
0813: jj_ntk = -1;
0814: jj_gen = 0;
0815: for (int i = 0; i < 31; i++)
0816: jj_la1[i] = -1;
0817: for (int i = 0; i < jj_2_rtns.length; i++)
0818: jj_2_rtns[i] = new JJCalls();
0819: }
0820:
0821: final private Token jj_consume_token(int kind)
0822: throws ParseException {
0823: Token oldToken;
0824: if ((oldToken = token).next != null)
0825: token = token.next;
0826: else
0827: token = token.next = token_source.getNextToken();
0828: jj_ntk = -1;
0829: if (token.kind == kind) {
0830: jj_gen++;
0831: if (++jj_gc > 100) {
0832: jj_gc = 0;
0833: for (int i = 0; i < jj_2_rtns.length; i++) {
0834: JJCalls c = jj_2_rtns[i];
0835: while (c != null) {
0836: if (c.gen < jj_gen)
0837: c.first = null;
0838: c = c.next;
0839: }
0840: }
0841: }
0842: return token;
0843: }
0844: token = oldToken;
0845: jj_kind = kind;
0846: throw generateParseException();
0847: }
0848:
0849: static private final class LookaheadSuccess extends java.lang.Error {
0850: }
0851:
0852: final private LookaheadSuccess jj_ls = new LookaheadSuccess();
0853:
0854: final private boolean jj_scan_token(int kind) {
0855: if (jj_scanpos == jj_lastpos) {
0856: jj_la--;
0857: if (jj_scanpos.next == null) {
0858: jj_lastpos = jj_scanpos = jj_scanpos.next = token_source
0859: .getNextToken();
0860: } else {
0861: jj_lastpos = jj_scanpos = jj_scanpos.next;
0862: }
0863: } else {
0864: jj_scanpos = jj_scanpos.next;
0865: }
0866: if (jj_rescan) {
0867: int i = 0;
0868: Token tok = token;
0869: while (tok != null && tok != jj_scanpos) {
0870: i++;
0871: tok = tok.next;
0872: }
0873: if (tok != null)
0874: jj_add_error_token(kind, i);
0875: }
0876: if (jj_scanpos.kind != kind)
0877: return true;
0878: if (jj_la == 0 && jj_scanpos == jj_lastpos)
0879: throw jj_ls;
0880: return false;
0881: }
0882:
0883: final public Token getNextToken() {
0884: if (token.next != null)
0885: token = token.next;
0886: else
0887: token = token.next = token_source.getNextToken();
0888: jj_ntk = -1;
0889: jj_gen++;
0890: return token;
0891: }
0892:
0893: final public Token getToken(int index) {
0894: Token t = lookingAhead ? jj_scanpos : token;
0895: for (int i = 0; i < index; i++) {
0896: if (t.next != null)
0897: t = t.next;
0898: else
0899: t = t.next = token_source.getNextToken();
0900: }
0901: return t;
0902: }
0903:
0904: final private int jj_ntk() {
0905: if ((jj_nt = token.next) == null)
0906: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
0907: else
0908: return (jj_ntk = jj_nt.kind);
0909: }
0910:
0911: private java.util.Vector jj_expentries = new java.util.Vector();
0912: private int[] jj_expentry;
0913: private int jj_kind = -1;
0914: private int[] jj_lasttokens = new int[100];
0915: private int jj_endpos;
0916:
0917: private void jj_add_error_token(int kind, int pos) {
0918: if (pos >= 100)
0919: return;
0920: if (pos == jj_endpos + 1) {
0921: jj_lasttokens[jj_endpos++] = kind;
0922: } else if (jj_endpos != 0) {
0923: jj_expentry = new int[jj_endpos];
0924: for (int i = 0; i < jj_endpos; i++) {
0925: jj_expentry[i] = jj_lasttokens[i];
0926: }
0927: boolean exists = false;
0928: for (java.util.Enumeration e = jj_expentries.elements(); e
0929: .hasMoreElements();) {
0930: int[] oldentry = (int[]) (e.nextElement());
0931: if (oldentry.length == jj_expentry.length) {
0932: exists = true;
0933: for (int i = 0; i < jj_expentry.length; i++) {
0934: if (oldentry[i] != jj_expentry[i]) {
0935: exists = false;
0936: break;
0937: }
0938: }
0939: if (exists)
0940: break;
0941: }
0942: }
0943: if (!exists)
0944: jj_expentries.addElement(jj_expentry);
0945: if (pos != 0)
0946: jj_lasttokens[(jj_endpos = pos) - 1] = kind;
0947: }
0948: }
0949:
0950: public ParseException generateParseException() {
0951: jj_expentries.removeAllElements();
0952: boolean[] la1tokens = new boolean[18];
0953: for (int i = 0; i < 18; i++) {
0954: la1tokens[i] = false;
0955: }
0956: if (jj_kind >= 0) {
0957: la1tokens[jj_kind] = true;
0958: jj_kind = -1;
0959: }
0960: for (int i = 0; i < 31; i++) {
0961: if (jj_la1[i] == jj_gen) {
0962: for (int j = 0; j < 32; j++) {
0963: if ((jj_la1_0[i] & (1 << j)) != 0) {
0964: la1tokens[j] = true;
0965: }
0966: }
0967: }
0968: }
0969: for (int i = 0; i < 18; i++) {
0970: if (la1tokens[i]) {
0971: jj_expentry = new int[1];
0972: jj_expentry[0] = i;
0973: jj_expentries.addElement(jj_expentry);
0974: }
0975: }
0976: jj_endpos = 0;
0977: jj_rescan_token();
0978: jj_add_error_token(0, 0);
0979: int[][] exptokseq = new int[jj_expentries.size()][];
0980: for (int i = 0; i < jj_expentries.size(); i++) {
0981: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
0982: }
0983: return new ParseException(token, exptokseq, tokenImage);
0984: }
0985:
0986: final public void enable_tracing() {
0987: }
0988:
0989: final public void disable_tracing() {
0990: }
0991:
0992: final private void jj_rescan_token() {
0993: jj_rescan = true;
0994: for (int i = 0; i < 1; i++) {
0995: JJCalls p = jj_2_rtns[i];
0996: do {
0997: if (p.gen > jj_gen) {
0998: jj_la = p.arg;
0999: jj_lastpos = jj_scanpos = p.first;
1000: switch (i) {
1001: case 0:
1002: jj_3_1();
1003: break;
1004: }
1005: }
1006: p = p.next;
1007: } while (p != null);
1008: }
1009: jj_rescan = false;
1010: }
1011:
1012: final private void jj_save(int index, int xla) {
1013: JJCalls p = jj_2_rtns[index];
1014: while (p.gen > jj_gen) {
1015: if (p.next == null) {
1016: p = p.next = new JJCalls();
1017: break;
1018: }
1019: p = p.next;
1020: }
1021: p.gen = jj_gen + xla - jj_la;
1022: p.first = token;
1023: p.arg = xla;
1024: }
1025:
1026: static final class JJCalls {
1027: int gen;
1028: Token first;
1029: int arg;
1030: JJCalls next;
1031: }
1032:
1033: }
|