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