KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > schema > parser > SchemaParser


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 // $ANTLR 2.7.5 (20050128): "schema.g" -> "SchemaParser.java"$
22
package org.apache.directory.ldapstudio.browser.core.model.schema.parser;
23
24
25 import java.io.*;
26 import java.util.*;
27
28 import org.apache.directory.ldapstudio.browser.core.model.schema.*;
29
30 import antlr.TokenBuffer;
31 import antlr.TokenStreamException;
32 import antlr.TokenStreamIOException;
33 import antlr.ANTLRException;
34 import antlr.LLkParser;
35 import antlr.Token;
36 import antlr.TokenStream;
37 import antlr.RecognitionException;
38 import antlr.NoViableAltException;
39 import antlr.MismatchedTokenException;
40 import antlr.SemanticException;
41 import antlr.ParserSharedInputState;
42 import antlr.collections.impl.BitSet;
43
44
45 public class SchemaParser extends antlr.LLkParser implements SchemaTokenTypes
46 {
47
48     public static final void main( String JavaDoc[] args )
49     {
50         try
51         {
52
53             // "( 11.222.333.4444 NAME ( 'test1' 'test2' ) DESC 'a b c'
54
// OBSOLETE SUP top ABSTRACT MUST ( cn ) may ( givenName $ sn)
55
// )"
56
// "( 2.5.4.11 NAME ( 'ou' 'organizationalUnitName' ) DESC
57
// 'RFC2256: organizational unit this object belongs to' SUP
58
// name EQUALITY caseIgnoreMatch SYNTAX 1.2.3.4.5{32} COLLECTIVE
59
// USAGE userApplications )"
60
// "( 2.5.4.11 DESC 'a b c' )"
61
// "( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch'
62
// SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )"
63
// "( 2.5.13.0 NAME 'objectIdentifierMatch' APPLIES (
64
// supportedApplicationContext $ supportedFeatures $
65
// supportedExtension $ supportedControl ) )"
66
// "( 1.2.840.113548.3.1.4.11110 NAME 'ciscoccnatPAUserPIN' DESC
67
// 'User Defined Attribute' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
68
// SINGLE-VALUE X-ORIGIN ( 'Cisco AVVID' 'user defined' ) )"
69
SchemaLexer mainLexer = new SchemaLexer( new StringReader(
70                 "( 1.3.6.1.4.1.1466.115.121.1.48 NAME 'Supplier And Consumer' )" ) );
71
72             SchemaParser parser = new SchemaParser( mainLexer );
73             // ObjectClassDescription d = parser.objectClassDescription();
74
// AttributeTypeDescription d =
75
// parser.attributeTypeDescription();
76
LdapSyntaxDescription d = parser.syntaxDescription();
77             // MatchingRuleDescription d = parser.matchingRuleDescription();
78
// MatchingRuleUseDescription d =
79
// parser.matchingRuleUseDescription();
80
System.out.println( d.toString() );
81         }
82         catch ( Exception JavaDoc e )
83         {
84             System.err.println( "exception: " + e );
85             e.printStackTrace();
86         }
87     }
88
89
90     protected SchemaParser( TokenBuffer tokenBuf, int k )
91     {
92         super( tokenBuf, k );
93         tokenNames = _tokenNames;
94     }
95
96
97     public SchemaParser( TokenBuffer tokenBuf )
98     {
99         this( tokenBuf, 3 );
100     }
101
102
103     protected SchemaParser( TokenStream lexer, int k )
104     {
105         super( lexer, k );
106         tokenNames = _tokenNames;
107     }
108
109
110     public SchemaParser( TokenStream lexer )
111     {
112         this( lexer, 3 );
113     }
114
115
116     public SchemaParser( ParserSharedInputState state )
117     {
118         super( state, 3 );
119         tokenNames = _tokenNames;
120     }
121
122
123     public final ObjectClassDescription objectClassDescription() throws RecognitionException, TokenStreamException
124     {
125         ObjectClassDescription ocd = new ObjectClassDescription();
126
127         Token oid = null;
128         Token name = null;
129         Token desc = null;
130         Token sup = null;
131         Token must = null;
132         Token may = null;
133
134         {
135             oid = LT( 1 );
136             match( STARTNUMERICOID );
137             ocd.setNumericOID( oid.getText() );
138         }
139         {
140             _loop94: do
141             {
142                 switch ( LA( 1 ) )
143                 {
144                     case NAME:
145                     {
146                         {
147                             name = LT( 1 );
148                             match( NAME );
149                             ocd.setNames( qdescrs( name.getText() ) );
150                         }
151                         break;
152                     }
153                     case DESC:
154                     {
155                         {
156                             desc = LT( 1 );
157                             match( DESC );
158                             ocd.setDesc( qdstring( desc.getText() ) );
159                         }
160                         break;
161                     }
162                     case OBSOLETE:
163                     {
164                         {
165                             match( OBSOLETE );
166                             ocd.setObsolete( true );
167                         }
168                         break;
169                     }
170                     case SUP:
171                     {
172                         {
173                             sup = LT( 1 );
174                             match( SUP );
175                             ocd.setSuperiorObjectClassDescriptionNames( oids( sup.getText() ) );
176                         }
177                         break;
178                     }
179                     case ABSTRACT:
180                     case STRUCTURAL:
181                     case AUXILIARY:
182                     {
183                         {
184                             switch ( LA( 1 ) )
185                             {
186                                 case ABSTRACT:
187                                 {
188                                     match( ABSTRACT );
189                                     ocd.setAbstract( true );
190                                     break;
191                                 }
192                                 case STRUCTURAL:
193                                 {
194                                     match( STRUCTURAL );
195                                     ocd.setStructural( true );
196                                     break;
197                                 }
198                                 case AUXILIARY:
199                                 {
200                                     match( AUXILIARY );
201                                     ocd.setAuxiliary( true );
202                                     break;
203                                 }
204                                 default:
205                                 {
206                                     throw new NoViableAltException( LT( 1 ), getFilename() );
207                                 }
208                             }
209                         }
210                         break;
211                     }
212                     case MUST:
213                     {
214                         {
215                             must = LT( 1 );
216                             match( MUST );
217                             ocd.setMustAttributeTypeDescriptionNames( oids( must.getText() ) );
218                         }
219                         break;
220                     }
221                     case MAY:
222                     {
223                         {
224                             may = LT( 1 );
225                             match( MAY );
226                             ocd.setMayAttributeTypeDescriptionNames( oids( may.getText() ) );
227                         }
228                         break;
229                     }
230                     default:
231                     {
232                         break _loop94;
233                     }
234                 }
235             }
236             while ( true );
237         }
238         match( RPAR );
239         return ocd;
240     }
241
242
243     public final AttributeTypeDescription attributeTypeDescription() throws RecognitionException, TokenStreamException
244     {
245         AttributeTypeDescription atd = new AttributeTypeDescription();
246
247         Token oid = null;
248         Token name = null;
249         Token desc = null;
250         Token sup = null;
251         Token equality = null;
252         Token ordering = null;
253         Token substr = null;
254         Token syntax = null;
255         Token usage = null;
256
257         {
258             oid = LT( 1 );
259             match( STARTNUMERICOID );
260             atd.setNumericOID( oid.getText() );
261         }
262         {
263             _loop110: do
264             {
265                 switch ( LA( 1 ) )
266                 {
267                     case NAME:
268                     {
269                         {
270                             name = LT( 1 );
271                             match( NAME );
272                             atd.setNames( qdescrs( name.getText() ) );
273                         }
274                         break;
275                     }
276                     case DESC:
277                     {
278                         {
279                             desc = LT( 1 );
280                             match( DESC );
281                             atd.setDesc( qdstring( desc.getText() ) );
282                         }
283                         break;
284                     }
285                     case OBSOLETE:
286                     {
287                         {
288                             match( OBSOLETE );
289                             atd.setObsolete( true );
290                         }
291                         break;
292                     }
293                     case SUP:
294                     {
295                         {
296                             sup = LT( 1 );
297                             match( SUP );
298                             atd.setSuperiorAttributeTypeDescriptionName( oid( sup.getText() ) );
299                         }
300                         break;
301                     }
302                     case EQUALITY:
303                     {
304                         {
305                             equality = LT( 1 );
306                             match( EQUALITY );
307                             atd.setEqualityMatchingRuleDescriptionOID( oid( equality.getText() ) );
308                         }
309                         break;
310                     }
311                     case ORDERING:
312                     {
313                         {
314                             ordering = LT( 1 );
315                             match( ORDERING );
316                             atd.setOrderingMatchingRuleDescriptionOID( oid( ordering.getText() ) );
317                         }
318                         break;
319                     }
320                     case SUBSTR:
321                     {
322                         {
323                             substr = LT( 1 );
324                             match( SUBSTR );
325                             atd.setSubstringMatchingRuleDescriptionOID( oid( substr.getText() ) );
326                         }
327                         break;
328                     }
329                     case SYNTAX:
330                     {
331                         {
332                             syntax = LT( 1 );
333                             match( SYNTAX );
334                             atd.setSyntaxDescriptionNumericOIDPlusLength( qdstring( syntax.getText() ) );
335                         }
336                         break;
337                     }
338                     case SINGLE_VALUE:
339                     {
340                         {
341                             match( SINGLE_VALUE );
342                             atd.setSingleValued( true );
343                         }
344                         break;
345                     }
346                     case COLLECTIVE:
347                     {
348                         {
349                             match( COLLECTIVE );
350                             atd.setCollective( true );
351                         }
352                         break;
353                     }
354                     case NO_USER_MODIFICATION:
355                     {
356                         {
357                             match( NO_USER_MODIFICATION );
358                             atd.setNoUserModification( true );
359                         }
360                         break;
361                     }
362                     case USAGE:
363                     {
364                         {
365                             usage = LT( 1 );
366                             match( USAGE );
367                             atd.setUsage( usage.getText() );
368                         }
369                         break;
370                     }
371                     default:
372                     {
373                         break _loop110;
374                     }
375                 }
376             }
377             while ( true );
378         }
379         match( RPAR );
380         return atd;
381     }
382
383
384     public final LdapSyntaxDescription syntaxDescription() throws RecognitionException, TokenStreamException
385     {
386         LdapSyntaxDescription lsd = new LdapSyntaxDescription();
387
388         Token oid = null;
389         Token desc = null;
390         Token name = null;
391
392         {
393             oid = LT( 1 );
394             match( STARTNUMERICOID );
395             lsd.setNumericOID( oid.getText() );
396         }
397         {
398             _loop116: do
399             {
400                 switch ( LA( 1 ) )
401                 {
402                     case DESC:
403                     {
404                         {
405                             desc = LT( 1 );
406                             match( DESC );
407                             lsd.setDesc( qdstring( desc.getText() ) );
408                         }
409                         break;
410                     }
411                     case NAME:
412                     {
413                         {
414                             name = LT( 1 );
415                             match( NAME );
416                             lsd.setDesc( qdstring( name.getText() ) );
417                         }
418                         break;
419                     }
420                     default:
421                     {
422                         break _loop116;
423                     }
424                 }
425             }
426             while ( true );
427         }
428         match( RPAR );
429         return lsd;
430     }
431
432
433     public final MatchingRuleDescription matchingRuleDescription() throws RecognitionException, TokenStreamException
434     {
435         MatchingRuleDescription mrd = new MatchingRuleDescription();
436
437         Token oid = null;
438         Token name = null;
439         Token desc = null;
440         Token syntax = null;
441
442         {
443             oid = LT( 1 );
444             match( STARTNUMERICOID );
445             mrd.setNumericOID( oid.getText() );
446         }
447         {
448             _loop124: do
449             {
450                 switch ( LA( 1 ) )
451                 {
452                     case NAME:
453                     {
454                         {
455                             name = LT( 1 );
456                             match( NAME );
457                             mrd.setNames( qdescrs( name.getText() ) );
458                         }
459                         break;
460                     }
461                     case DESC:
462                     {
463                         {
464                             desc = LT( 1 );
465                             match( DESC );
466                             mrd.setDesc( qdstring( desc.getText() ) );
467                         }
468                         break;
469                     }
470                     case OBSOLETE:
471                     {
472                         {
473                             match( OBSOLETE );
474                             mrd.setObsolete( true );
475                         }
476                         break;
477                     }
478                     case SYNTAX:
479                     {
480                         {
481                             syntax = LT( 1 );
482                             match( SYNTAX );
483                             mrd.setSyntaxDescriptionNumericOID( syntax.getText() );
484                         }
485                         break;
486                     }
487                     default:
488                     {
489                         break _loop124;
490                     }
491                 }
492             }
493             while ( true );
494         }
495         match( RPAR );
496         return mrd;
497     }
498
499
500     public final MatchingRuleUseDescription matchingRuleUseDescription() throws RecognitionException,
501         TokenStreamException
502     {
503         MatchingRuleUseDescription mrud = new MatchingRuleUseDescription();
504
505         Token oid = null;
506         Token name = null;
507         Token desc = null;
508         Token applies = null;
509
510         {
511             oid = LT( 1 );
512             match( STARTNUMERICOID );
513             mrud.setNumericOID( oid.getText() );
514         }
515         {
516             _loop132: do
517             {
518                 switch ( LA( 1 ) )
519                 {
520                     case NAME:
521                     {
522                         {
523                             name = LT( 1 );
524                             match( NAME );
525                             mrud.setNames( qdescrs( name.getText() ) );
526                         }
527                         break;
528                     }
529                     case DESC:
530                     {
531                         {
532                             desc = LT( 1 );
533                             match( DESC );
534                             mrud.setDesc( qdstring( desc.getText() ) );
535                         }
536                         break;
537                     }
538                     case OBSOLETE:
539                     {
540                         {
541                             match( OBSOLETE );
542                             mrud.setObsolete( true );
543                         }
544                         break;
545                     }
546                     case APPLIES:
547                     {
548                         {
549                             applies = LT( 1 );
550                             match( APPLIES );
551                             mrud.setAppliesAttributeTypeDescriptionOIDs( oids( applies.getText() ) );
552                         }
553                         break;
554                     }
555                     default:
556                     {
557                         break _loop132;
558                     }
559                 }
560             }
561             while ( true );
562         }
563         match( RPAR );
564         return mrud;
565     }
566
567
568     public final String JavaDoc oid( String JavaDoc s ) throws RecognitionException, TokenStreamException
569     {
570         String JavaDoc oid;
571
572         SchemaValueLexer lexer = new SchemaValueLexer( new StringReader( s ) );
573         SchemaValueParser parser = new SchemaValueParser( lexer );
574         oid = parser.oid();
575
576         return oid;
577     }
578
579
580     public final String JavaDoc[] oids( String JavaDoc s ) throws RecognitionException, TokenStreamException
581     {
582         String JavaDoc[] oids;
583
584         SchemaValueLexer lexer = new SchemaValueLexer( new StringReader( s ) );
585         SchemaValueParser parser = new SchemaValueParser( lexer );
586         oids = parser.oids();
587
588         return oids;
589     }
590
591
592     public final String JavaDoc[] qdescrs( String JavaDoc s ) throws RecognitionException, TokenStreamException
593     {
594         String JavaDoc[] qdescrs;
595
596         SchemaValueLexer lexer = new SchemaValueLexer( new StringReader( s ) );
597         SchemaValueParser parser = new SchemaValueParser( lexer );
598         qdescrs = parser.qdescrs();
599
600         return qdescrs;
601     }
602
603
604     public final String JavaDoc qdstring( String JavaDoc s ) throws RecognitionException, TokenStreamException
605     {
606         String JavaDoc qdstring;
607
608         if ( s == null )
609         {
610             qdstring = null;
611         }
612         else
613         {
614             if ( s.startsWith( "'" ) )
615             {
616                 s = s.substring( 1, s.length() );
617             }
618             if ( s.endsWith( "'" ) )
619             {
620                 s = s.substring( 0, s.length() - 1 );
621             }
622             qdstring = s;
623         }
624
625         return qdstring;
626     }
627
628     public static final String JavaDoc[] _tokenNames =
629         { "<0>", "EOF", "<2>", "NULL_TREE_LOOKAHEAD", "WHSP", "LPAR", "RPAR", "QUOTE", "DOLLAR", "LBRACKET",
630             "RBRACKET", "LEN", "USAGE_USERAPPLICATIONS", "USAGE_DIRECTORYOPERATION", "USAGE_DISTRIBUTEDOPERATION",
631             "USAGE_DSAOPERATION", "STARTNUMERICOID", "NAME", "DESC", "SUP", "MUST", "MAY", "EQUALITY", "ORDERING",
632             "SUBSTR", "SYNTAX", "USAGE", "APPLIES", "X", "SINGLE_VALUE", "COLLECTIVE", "NO_USER_MODIFICATION",
633             "OBSOLETE", "ABSTRACT", "STRUCTURAL", "AUXILIARY", "VALUES", "VALUE", "UNQUOTED_STRING", "QUOTED_STRING" };
634
635 }
636
Popular Tags