001// $ANTLR 2.7.7 (20060906): "SubtreeSpecificationChecker.g" -> "AntlrSubtreeSpecificationChecker.java"$
002
003/*
004 *  Licensed to the Apache Software Foundation (ASF) under one
005 *  or more contributor license agreements.  See the NOTICE file
006 *  distributed with this work for additional information
007 *  regarding copyright ownership.  The ASF licenses this file
008 *  to you under the Apache License, Version 2.0 (the
009 *  "License"); you may not use this file except in compliance
010 *  with the License.  You may obtain a copy of the License at
011 *  
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *  
014 *  Unless required by applicable law or agreed to in writing,
015 *  software distributed under the License is distributed on an
016 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 *  KIND, either express or implied.  See the License for the
018 *  specific language governing permissions and limitations
019 *  under the License. 
020 *  
021 */
022
023
024package org.apache.directory.api.ldap.model.subtree;
025
026import org.apache.directory.api.ldap.model.name.Dn;
027import org.apache.directory.api.ldap.model.filter.ExprNode;
028import org.apache.directory.api.ldap.model.filter.LeafNode;
029import org.apache.directory.api.ldap.model.filter.BranchNode;
030import org.apache.directory.api.ldap.model.filter.AndNode;
031import org.apache.directory.api.ldap.model.filter.OrNode;
032import org.apache.directory.api.ldap.model.filter.NotNode;
033import org.apache.directory.api.ldap.model.filter.EqualityNode;
034import org.apache.directory.api.ldap.model.filter.FilterParser;
035import org.apache.directory.api.util.ComponentsMonitor;
036import org.apache.directory.api.util.OptionalComponentsMonitor;
037import org.apache.directory.api.ldap.model.schema.SchemaManager;
038
039import org.slf4j.Logger;
040import org.slf4j.LoggerFactory;
041
042import antlr.TokenBuffer;
043import antlr.TokenStreamException;
044import antlr.TokenStreamIOException;
045import antlr.ANTLRException;
046import antlr.LLkParser;
047import antlr.Token;
048import antlr.TokenStream;
049import antlr.RecognitionException;
050import antlr.NoViableAltException;
051import antlr.MismatchedTokenException;
052import antlr.SemanticException;
053import antlr.ParserSharedInputState;
054import antlr.collections.impl.BitSet;
055
056/**
057 * The antlr generated subtree specification parser.
058 *
059 * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
060 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
061 */
062public class AntlrSubtreeSpecificationChecker extends antlr.LLkParser       implements AntlrSubtreeSpecificationCheckerTokenTypes
063 {
064
065    private static final Logger log = LoggerFactory.getLogger( AntlrSubtreeSpecificationChecker.class );
066    
067    private ComponentsMonitor subtreeSpecificationComponentsMonitor = null;
068    
069    /** The SchemaManager */
070    private SchemaManager schemaManager;
071
072    /**
073     * Initiaize the checker
074     */
075    public void init( SchemaManager schemaManager )
076    {
077        this.schemaManager = schemaManager;
078    }
079    
080
081    private int token2Integer( Token token ) throws RecognitionException
082    {
083        int i = 0;
084        
085        try
086        {
087            i = Integer.parseInt( token.getText());
088        }
089        catch ( NumberFormatException e )
090        {
091            throw new RecognitionException( "Value of INTEGER token " +
092                                            token.getText() +
093                                            " cannot be converted to an Integer" );
094        }
095        
096        return i;
097    }
098
099protected AntlrSubtreeSpecificationChecker(TokenBuffer tokenBuf, int k) {
100  super(tokenBuf,k);
101  tokenNames = _tokenNames;
102}
103
104public AntlrSubtreeSpecificationChecker(TokenBuffer tokenBuf) {
105  this(tokenBuf,1);
106}
107
108protected AntlrSubtreeSpecificationChecker(TokenStream lexer, int k) {
109  super(lexer,k);
110  tokenNames = _tokenNames;
111}
112
113public AntlrSubtreeSpecificationChecker(TokenStream lexer) {
114  this(lexer,1);
115}
116
117public AntlrSubtreeSpecificationChecker(ParserSharedInputState state) {
118  super(state,1);
119  tokenNames = _tokenNames;
120}
121
122        public final void wrapperEntryPoint() throws RecognitionException, TokenStreamException {
123                
124                
125                log.debug( "entered wrapperEntryPoint()" );
126                
127                
128                subtreeSpecification();
129                match(LITERAL_end);
130        }
131        
132        public final void subtreeSpecification() throws RecognitionException, TokenStreamException {
133                
134                
135                log.debug( "entered subtreeSpecification()" );
136                subtreeSpecificationComponentsMonitor = new OptionalComponentsMonitor( 
137                new String [] { "base", "specificExclusions", "minimum", "maximum", "specificationFilter" } );
138                
139                
140                match(OPEN_CURLY);
141                {
142                _loop4:
143                do {
144                        if ((LA(1)==SP)) {
145                                match(SP);
146                        }
147                        else {
148                                break _loop4;
149                        }
150                        
151                } while (true);
152                }
153                {
154                switch ( LA(1)) {
155                case ID_base:
156                case ID_specificExclusions:
157                case ID_minimum:
158                case ID_maximum:
159                case ID_specificationFilter:
160                {
161                        subtreeSpecificationComponent();
162                        {
163                        _loop7:
164                        do {
165                                if ((LA(1)==SP)) {
166                                        match(SP);
167                                }
168                                else {
169                                        break _loop7;
170                                }
171                                
172                        } while (true);
173                        }
174                        {
175                        _loop13:
176                        do {
177                                if ((LA(1)==SEP)) {
178                                        match(SEP);
179                                        {
180                                        _loop10:
181                                        do {
182                                                if ((LA(1)==SP)) {
183                                                        match(SP);
184                                                }
185                                                else {
186                                                        break _loop10;
187                                                }
188                                                
189                                        } while (true);
190                                        }
191                                        subtreeSpecificationComponent();
192                                        {
193                                        _loop12:
194                                        do {
195                                                if ((LA(1)==SP)) {
196                                                        match(SP);
197                                                }
198                                                else {
199                                                        break _loop12;
200                                                }
201                                                
202                                        } while (true);
203                                        }
204                                }
205                                else {
206                                        break _loop13;
207                                }
208                                
209                        } while (true);
210                        }
211                        break;
212                }
213                case CLOSE_CURLY:
214                {
215                        break;
216                }
217                default:
218                {
219                        throw new NoViableAltException(LT(1), getFilename());
220                }
221                }
222                }
223                match(CLOSE_CURLY);
224        }
225        
226        public final void subtreeSpecificationComponent() throws RecognitionException, TokenStreamException {
227                
228                
229                log.debug( "entered subtreeSpecification()" );
230                
231                
232                try {      // for error handling
233                        switch ( LA(1)) {
234                        case ID_base:
235                        {
236                                ss_base();
237                                
238                                subtreeSpecificationComponentsMonitor.useComponent( "base" );
239                                
240                                break;
241                        }
242                        case ID_specificExclusions:
243                        {
244                                ss_specificExclusions();
245                                
246                                subtreeSpecificationComponentsMonitor.useComponent( "specificExclusions" );
247                                
248                                break;
249                        }
250                        case ID_minimum:
251                        {
252                                ss_minimum();
253                                
254                                subtreeSpecificationComponentsMonitor.useComponent( "minimum" );
255                                
256                                break;
257                        }
258                        case ID_maximum:
259                        {
260                                ss_maximum();
261                                
262                                subtreeSpecificationComponentsMonitor.useComponent( "maximum" );
263                                
264                                break;
265                        }
266                        case ID_specificationFilter:
267                        {
268                                ss_specificationFilter();
269                                
270                                subtreeSpecificationComponentsMonitor.useComponent( "specificationFilter" );
271                                
272                                break;
273                        }
274                        default:
275                        {
276                                throw new NoViableAltException(LT(1), getFilename());
277                        }
278                        }
279                }
280                catch (IllegalArgumentException e) {
281                        
282                        throw new RecognitionException( e.getMessage() );
283                        
284                }
285        }
286        
287        public final void ss_base() throws RecognitionException, TokenStreamException {
288                
289                
290                log.debug( "entered ss_base()" );
291                
292                
293                match(ID_base);
294                {
295                int _cnt17=0;
296                _loop17:
297                do {
298                        if ((LA(1)==SP)) {
299                                match(SP);
300                        }
301                        else {
302                                if ( _cnt17>=1 ) { break _loop17; } else {throw new NoViableAltException(LT(1), getFilename());}
303                        }
304                        
305                        _cnt17++;
306                } while (true);
307                }
308                distinguishedName();
309        }
310        
311        public final void ss_specificExclusions() throws RecognitionException, TokenStreamException {
312                
313                
314                log.debug( "entered ss_specificExclusions()" );
315                
316                
317                match(ID_specificExclusions);
318                {
319                int _cnt20=0;
320                _loop20:
321                do {
322                        if ((LA(1)==SP)) {
323                                match(SP);
324                        }
325                        else {
326                                if ( _cnt20>=1 ) { break _loop20; } else {throw new NoViableAltException(LT(1), getFilename());}
327                        }
328                        
329                        _cnt20++;
330                } while (true);
331                }
332                specificExclusions();
333        }
334        
335        public final void ss_minimum() throws RecognitionException, TokenStreamException {
336                
337                
338                log.debug( "entered ss_minimum()" );
339                
340                
341                match(ID_minimum);
342                {
343                int _cnt46=0;
344                _loop46:
345                do {
346                        if ((LA(1)==SP)) {
347                                match(SP);
348                        }
349                        else {
350                                if ( _cnt46>=1 ) { break _loop46; } else {throw new NoViableAltException(LT(1), getFilename());}
351                        }
352                        
353                        _cnt46++;
354                } while (true);
355                }
356                baseDistance();
357        }
358        
359        public final void ss_maximum() throws RecognitionException, TokenStreamException {
360                
361                
362                log.debug( "entered ss_maximum()" );
363                
364                
365                match(ID_maximum);
366                {
367                int _cnt49=0;
368                _loop49:
369                do {
370                        if ((LA(1)==SP)) {
371                                match(SP);
372                        }
373                        else {
374                                if ( _cnt49>=1 ) { break _loop49; } else {throw new NoViableAltException(LT(1), getFilename());}
375                        }
376                        
377                        _cnt49++;
378                } while (true);
379                }
380                baseDistance();
381        }
382        
383        public final void ss_specificationFilter() throws RecognitionException, TokenStreamException {
384                
385                
386                log.debug( "entered ss_specificationFilter()" );
387                
388                
389                match(ID_specificationFilter);
390                {
391                int _cnt52=0;
392                _loop52:
393                do {
394                        if ((LA(1)==SP)) {
395                                match(SP);
396                        }
397                        else {
398                                if ( _cnt52>=1 ) { break _loop52; } else {throw new NoViableAltException(LT(1), getFilename());}
399                        }
400                        
401                        _cnt52++;
402                } while (true);
403                }
404                {
405                switch ( LA(1)) {
406                case ID_item:
407                case ID_and:
408                case ID_or:
409                case ID_not:
410                {
411                        {
412                        refinement();
413                        }
414                        break;
415                }
416                case FILTER:
417                {
418                        {
419                        filter();
420                        }
421                        break;
422                }
423                default:
424                {
425                        throw new NoViableAltException(LT(1), getFilename());
426                }
427                }
428                }
429        }
430        
431        public final void distinguishedName() throws RecognitionException, TokenStreamException {
432                
433                Token  token = null;
434                
435                log.debug( "entered distinguishedName()" );
436                
437                
438                try {      // for error handling
439                        token = LT(1);
440                        match(SAFEUTF8STRING);
441                        
442                        new Dn( token.getText() );
443                        log.debug( "recognized a DistinguishedName: " + token.getText() );
444                        
445                }
446                catch (Exception e) {
447                        
448                        throw new RecognitionException( "dnParser failed for " + token.getText() + " " + e.getMessage() );
449                        
450                }
451        }
452        
453        public final void specificExclusions() throws RecognitionException, TokenStreamException {
454                
455                
456                log.debug( "entered specificExclusions()" );
457                
458                
459                match(OPEN_CURLY);
460                {
461                _loop23:
462                do {
463                        if ((LA(1)==SP)) {
464                                match(SP);
465                        }
466                        else {
467                                break _loop23;
468                        }
469                        
470                } while (true);
471                }
472                {
473                switch ( LA(1)) {
474                case ID_chopBefore:
475                case ID_chopAfter:
476                {
477                        specificExclusion();
478                        {
479                        _loop26:
480                        do {
481                                if ((LA(1)==SP)) {
482                                        match(SP);
483                                }
484                                else {
485                                        break _loop26;
486                                }
487                                
488                        } while (true);
489                        }
490                        {
491                        _loop32:
492                        do {
493                                if ((LA(1)==SEP)) {
494                                        match(SEP);
495                                        {
496                                        _loop29:
497                                        do {
498                                                if ((LA(1)==SP)) {
499                                                        match(SP);
500                                                }
501                                                else {
502                                                        break _loop29;
503                                                }
504                                                
505                                        } while (true);
506                                        }
507                                        specificExclusion();
508                                        {
509                                        _loop31:
510                                        do {
511                                                if ((LA(1)==SP)) {
512                                                        match(SP);
513                                                }
514                                                else {
515                                                        break _loop31;
516                                                }
517                                                
518                                        } while (true);
519                                        }
520                                }
521                                else {
522                                        break _loop32;
523                                }
524                                
525                        } while (true);
526                        }
527                        break;
528                }
529                case CLOSE_CURLY:
530                {
531                        break;
532                }
533                default:
534                {
535                        throw new NoViableAltException(LT(1), getFilename());
536                }
537                }
538                }
539                match(CLOSE_CURLY);
540        }
541        
542        public final void specificExclusion() throws RecognitionException, TokenStreamException {
543                
544                
545                log.debug( "entered specificExclusion()" );
546                
547                
548                switch ( LA(1)) {
549                case ID_chopBefore:
550                {
551                        chopBefore();
552                        break;
553                }
554                case ID_chopAfter:
555                {
556                        chopAfter();
557                        break;
558                }
559                default:
560                {
561                        throw new NoViableAltException(LT(1), getFilename());
562                }
563                }
564        }
565        
566        public final void chopBefore() throws RecognitionException, TokenStreamException {
567                
568                
569                log.debug( "entered chopBefore()" );
570                
571                
572                match(ID_chopBefore);
573                {
574                _loop36:
575                do {
576                        if ((LA(1)==SP)) {
577                                match(SP);
578                        }
579                        else {
580                                break _loop36;
581                        }
582                        
583                } while (true);
584                }
585                match(COLON);
586                {
587                _loop38:
588                do {
589                        if ((LA(1)==SP)) {
590                                match(SP);
591                        }
592                        else {
593                                break _loop38;
594                        }
595                        
596                } while (true);
597                }
598                distinguishedName();
599        }
600        
601        public final void chopAfter() throws RecognitionException, TokenStreamException {
602                
603                
604                log.debug( "entered chopAfter()" );
605                
606                
607                match(ID_chopAfter);
608                {
609                _loop41:
610                do {
611                        if ((LA(1)==SP)) {
612                                match(SP);
613                        }
614                        else {
615                                break _loop41;
616                        }
617                        
618                } while (true);
619                }
620                match(COLON);
621                {
622                _loop43:
623                do {
624                        if ((LA(1)==SP)) {
625                                match(SP);
626                        }
627                        else {
628                                break _loop43;
629                        }
630                        
631                } while (true);
632                }
633                distinguishedName();
634        }
635        
636        public final void baseDistance() throws RecognitionException, TokenStreamException {
637                
638                Token  token = null;
639                
640                log.debug( "entered baseDistance()" );
641                
642                
643                token = LT(1);
644                match(INTEGER);
645                
646                token2Integer(token);
647                
648        }
649        
650        public final void refinement() throws RecognitionException, TokenStreamException {
651                
652                
653                log.debug( "entered refinement()" );
654                
655                
656                switch ( LA(1)) {
657                case ID_item:
658                {
659                        item();
660                        break;
661                }
662                case ID_and:
663                {
664                        and();
665                        break;
666                }
667                case ID_or:
668                {
669                        or();
670                        break;
671                }
672                case ID_not:
673                {
674                        not();
675                        break;
676                }
677                default:
678                {
679                        throw new NoViableAltException(LT(1), getFilename());
680                }
681                }
682        }
683        
684        public final void filter() throws RecognitionException, TokenStreamException {
685                
686                Token  filterToken = null;
687                
688                log.debug( "entered filter()" );
689                
690                
691                try {      // for error handling
692                        {
693                        filterToken = LT(1);
694                        match(FILTER);
695                        FilterParser.parse( filterToken.getText() );
696                        }
697                }
698                catch (Exception e) {
699                        
700                        throw new RecognitionException( "filterParser failed. " + e.getMessage() );
701                        
702                }
703        }
704        
705        public final void oid() throws RecognitionException, TokenStreamException {
706                
707                
708                log.debug( "entered oid()" );
709                Token token = null;
710                
711                
712                token = LT( 1 );
713                {
714                switch ( LA(1)) {
715                case DESCR:
716                {
717                        match(DESCR);
718                        break;
719                }
720                case NUMERICOID:
721                {
722                        match(NUMERICOID);
723                        break;
724                }
725                default:
726                {
727                        throw new NoViableAltException(LT(1), getFilename());
728                }
729                }
730                }
731                
732                log.debug( "recognized an oid: " + token.getText() );
733                
734        }
735        
736        public final void item() throws RecognitionException, TokenStreamException {
737                
738                
739                log.debug( "entered item()" );
740                
741                
742                match(ID_item);
743                {
744                _loop65:
745                do {
746                        if ((LA(1)==SP)) {
747                                match(SP);
748                        }
749                        else {
750                                break _loop65;
751                        }
752                        
753                } while (true);
754                }
755                match(COLON);
756                {
757                _loop67:
758                do {
759                        if ((LA(1)==SP)) {
760                                match(SP);
761                        }
762                        else {
763                                break _loop67;
764                        }
765                        
766                } while (true);
767                }
768                oid();
769        }
770        
771        public final void and() throws RecognitionException, TokenStreamException {
772                
773                
774                log.debug( "entered and()" );
775                
776                
777                match(ID_and);
778                {
779                _loop70:
780                do {
781                        if ((LA(1)==SP)) {
782                                match(SP);
783                        }
784                        else {
785                                break _loop70;
786                        }
787                        
788                } while (true);
789                }
790                match(COLON);
791                {
792                _loop72:
793                do {
794                        if ((LA(1)==SP)) {
795                                match(SP);
796                        }
797                        else {
798                                break _loop72;
799                        }
800                        
801                } while (true);
802                }
803                refinements();
804        }
805        
806        public final void or() throws RecognitionException, TokenStreamException {
807                
808                
809                log.debug( "entered or()" );
810                
811                
812                match(ID_or);
813                {
814                _loop75:
815                do {
816                        if ((LA(1)==SP)) {
817                                match(SP);
818                        }
819                        else {
820                                break _loop75;
821                        }
822                        
823                } while (true);
824                }
825                match(COLON);
826                {
827                _loop77:
828                do {
829                        if ((LA(1)==SP)) {
830                                match(SP);
831                        }
832                        else {
833                                break _loop77;
834                        }
835                        
836                } while (true);
837                }
838                refinements();
839        }
840        
841        public final void not() throws RecognitionException, TokenStreamException {
842                
843                
844                log.debug( "entered not()" );
845                
846                
847                match(ID_not);
848                {
849                _loop80:
850                do {
851                        if ((LA(1)==SP)) {
852                                match(SP);
853                        }
854                        else {
855                                break _loop80;
856                        }
857                        
858                } while (true);
859                }
860                match(COLON);
861                {
862                _loop82:
863                do {
864                        if ((LA(1)==SP)) {
865                                match(SP);
866                        }
867                        else {
868                                break _loop82;
869                        }
870                        
871                } while (true);
872                }
873                refinement();
874        }
875        
876        public final void refinements() throws RecognitionException, TokenStreamException {
877                
878                
879                log.debug( "entered refinements()" );
880                
881                
882                match(OPEN_CURLY);
883                {
884                _loop85:
885                do {
886                        if ((LA(1)==SP)) {
887                                match(SP);
888                        }
889                        else {
890                                break _loop85;
891                        }
892                        
893                } while (true);
894                }
895                {
896                switch ( LA(1)) {
897                case ID_item:
898                case ID_and:
899                case ID_or:
900                case ID_not:
901                {
902                        refinement();
903                        {
904                        _loop88:
905                        do {
906                                if ((LA(1)==SP)) {
907                                        match(SP);
908                                }
909                                else {
910                                        break _loop88;
911                                }
912                                
913                        } while (true);
914                        }
915                        {
916                        _loop94:
917                        do {
918                                if ((LA(1)==SEP)) {
919                                        match(SEP);
920                                        {
921                                        _loop91:
922                                        do {
923                                                if ((LA(1)==SP)) {
924                                                        match(SP);
925                                                }
926                                                else {
927                                                        break _loop91;
928                                                }
929                                                
930                                        } while (true);
931                                        }
932                                        refinement();
933                                        {
934                                        _loop93:
935                                        do {
936                                                if ((LA(1)==SP)) {
937                                                        match(SP);
938                                                }
939                                                else {
940                                                        break _loop93;
941                                                }
942                                                
943                                        } while (true);
944                                        }
945                                }
946                                else {
947                                        break _loop94;
948                                }
949                                
950                        } while (true);
951                        }
952                        break;
953                }
954                case CLOSE_CURLY:
955                {
956                        break;
957                }
958                default:
959                {
960                        throw new NoViableAltException(LT(1), getFilename());
961                }
962                }
963                }
964                match(CLOSE_CURLY);
965        }
966        
967        
968        public static final String[] _tokenNames = {
969                "<0>",
970                "EOF",
971                "<2>",
972                "NULL_TREE_LOOKAHEAD",
973                "\"end\"",
974                "OPEN_CURLY",
975                "SP",
976                "SEP",
977                "CLOSE_CURLY",
978                "\"base\"",
979                "\"specificExclusions\"",
980                "\"chopBefore\"",
981                "COLON",
982                "\"chopAfter\"",
983                "\"minimum\"",
984                "\"maximum\"",
985                "\"specificationFilter\"",
986                "FILTER",
987                "SAFEUTF8STRING",
988                "INTEGER",
989                "DESCR",
990                "NUMERICOID",
991                "\"item\"",
992                "\"and\"",
993                "\"or\"",
994                "\"not\"",
995                "INTEGER_OR_NUMERICOID",
996                "DOT",
997                "DIGIT",
998                "LDIGIT",
999                "ALPHA",
1000                "SAFEUTF8CHAR",
1001                "FILTER_VALUE"
1002        };
1003        
1004        
1005        }