KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > olap > mapping > MappingParser


1 // $ANTLR 2.7.5 (20050128): "mapping.g" -> "MappingParser.java"$
2

3 /*
4  * ============================================================================
5  * GNU Lesser General Public License
6  * ============================================================================
7  *
8  * JasperReports - Free Java report-generating library.
9  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  *
25  * JasperSoft Corporation
26  * 303 Second Street, Suite 450 North
27  * San Francisco, CA 94107
28  * http://www.jaspersoft.com
29  */

30 package net.sf.jasperreports.olap.mapping;
31
32 import java.util.List JavaDoc;
33 import java.util.ArrayList JavaDoc;
34
35 import net.sf.jasperreports.olap.mapping.*;
36
37 import antlr.TokenBuffer;
38 import antlr.TokenStreamException;
39 import antlr.TokenStreamIOException;
40 import antlr.ANTLRException;
41 import antlr.LLkParser;
42 import antlr.Token;
43 import antlr.TokenStream;
44 import antlr.RecognitionException;
45 import antlr.NoViableAltException;
46 import antlr.MismatchedTokenException;
47 import antlr.SemanticException;
48 import antlr.ParserSharedInputState;
49 import antlr.collections.impl.BitSet;
50
51 /**
52  * @author Lucian Chirita (lucianc@users.sourceforge.net)
53  * @version $Id: MappingParser.java 1316 2006-06-29 16:45:55 +0300 (Thu, 29 Jun 2006) lucianc $
54  */

55 public class MappingParser extends antlr.LLkParser implements MappingParserTokenTypes
56  {
57
58     private MappingMetadata mappingMeta;
59     
60     public void setMappingMetadata(MappingMetadata mappingMeta)
61     {
62         this.mappingMeta = mappingMeta;
63     }
64     
65     private String JavaDoc getMondrName (String JavaDoc text)
66     {
67         return text.substring(1, text.length() - 1).trim();
68     }
69     
70     private int getMondrIdx (String JavaDoc text)
71     {
72         return Integer.parseInt(text.substring(2, text.length() - 1).trim());
73     }
74
75 protected MappingParser(TokenBuffer tokenBuf, int k) {
76   super(tokenBuf,k);
77   tokenNames = _tokenNames;
78 }
79
80 public MappingParser(TokenBuffer tokenBuf) {
81   this(tokenBuf,2);
82 }
83
84 protected MappingParser(TokenStream lexer, int k) {
85   super(lexer,k);
86   tokenNames = _tokenNames;
87 }
88
89 public MappingParser(TokenStream lexer) {
90   this(lexer,2);
91 }
92
93 public MappingParser(ParserSharedInputState state) {
94   super(state,2);
95   tokenNames = _tokenNames;
96 }
97
98     public final Mapping mapping() throws RecognitionException, TokenStreamException {
99         Mapping mapping = null;
100         
101         
102         try { // for error handling
103
{
104             switch ( LA(1)) {
105             case LITERAL_Axis:
106             case LITERAL_Columns:
107             case LITERAL_Rows:
108             case LITERAL_Pages:
109             case LITERAL_Chapters:
110             case LITERAL_Sections:
111             {
112                 mapping=memberMapping();
113                 break;
114             }
115             case LITERAL_Data:
116             case LITERAL_FormattedData:
117             {
118                 mapping=dataMapping();
119                 break;
120             }
121             default:
122             {
123                 throw new NoViableAltException(LT(1), getFilename());
124             }
125             }
126             }
127             match(Token.EOF_TYPE);
128         }
129         catch (RecognitionException ex) {
130             reportError(ex);
131             recover(ex,_tokenSet_0);
132         }
133         return mapping;
134     }
135     
136     public final MemberMapping memberMapping() throws RecognitionException, TokenStreamException {
137         MemberMapping mapping = null;
138         
139         Member member; MemberProperty prop = null;
140         
141         try { // for error handling
142
member=member();
143             {
144             switch ( LA(1)) {
145             case LPAREN:
146             {
147                 prop=property();
148                 break;
149             }
150             case EOF:
151             {
152                 break;
153             }
154             default:
155             {
156                 throw new NoViableAltException(LT(1), getFilename());
157             }
158             }
159             }
160             mapping = new MemberMapping(member, prop);
161         }
162         catch (RecognitionException ex) {
163             reportError(ex);
164             recover(ex,_tokenSet_0);
165         }
166         return mapping;
167     }
168     
169     public final DataMapping dataMapping() throws RecognitionException, TokenStreamException {
170         DataMapping mapping = null;
171         
172         boolean formatted = false; List JavaDoc filter = null; List JavaDoc positions = null;
173         
174         try { // for error handling
175
{
176             {
177             switch ( LA(1)) {
178             case LITERAL_Data:
179             {
180                 match(LITERAL_Data);
181                 break;
182             }
183             case LITERAL_FormattedData:
184             {
185                 match(LITERAL_FormattedData);
186                 formatted = true;
187                 break;
188             }
189             default:
190             {
191                 throw new NoViableAltException(LT(1), getFilename());
192             }
193             }
194             }
195             {
196             if ((LA(1)==LPAREN) && (_tokenSet_1.member(LA(2)))) {
197                 filter=memberFilter();
198             }
199             else if ((LA(1)==EOF||LA(1)==LPAREN) && (_tokenSet_2.member(LA(2)))) {
200             }
201             else {
202                 throw new NoViableAltException(LT(1), getFilename());
203             }
204             
205             }
206             {
207             switch ( LA(1)) {
208             case LPAREN:
209             {
210                 positions=axisPositions();
211                 break;
212             }
213             case EOF:
214             {
215                 break;
216             }
217             default:
218             {
219                 throw new NoViableAltException(LT(1), getFilename());
220             }
221             }
222             }
223             }
224             mapping = new DataMapping(formatted, filter, positions);
225         }
226         catch (RecognitionException ex) {
227             reportError(ex);
228             recover(ex,_tokenSet_0);
229         }
230         return mapping;
231     }
232     
233     public final Member member() throws RecognitionException, TokenStreamException {
234         Member member = null;
235         
236         Axis axis; TuplePosition pos; MemberDepth depth = null;
237         
238         try { // for error handling
239
axis=axis();
240             pos=tuplePosition(axis);
241             {
242             switch ( LA(1)) {
243             case MONDRNAME:
244             case MONDRIDX:
245             {
246                 depth=memberDepth(axis, pos);
247                 break;
248             }
249             case EOF:
250             case LPAREN:
251             {
252                 break;
253             }
254             default:
255             {
256                 throw new NoViableAltException(LT(1), getFilename());
257             }
258             }
259             }
260             member = new Member(pos, depth);
261         }
262         catch (RecognitionException ex) {
263             reportError(ex);
264             recover(ex,_tokenSet_3);
265         }
266         return member;
267     }
268     
269     public final MemberProperty property() throws RecognitionException, TokenStreamException {
270         MemberProperty prop = null;
271         
272         String JavaDoc name;
273         
274         try { // for error handling
275
match(LPAREN);
276             name=name();
277             match(RPAREN);
278             prop = new MemberProperty(name);
279         }
280         catch (RecognitionException ex) {
281             reportError(ex);
282             recover(ex,_tokenSet_0);
283         }
284         return prop;
285     }
286     
287     public final Axis axis() throws RecognitionException, TokenStreamException {
288         Axis axis = null;
289         
290         int idx;
291         
292         try { // for error handling
293
{
294             switch ( LA(1)) {
295             case LITERAL_Axis:
296             {
297                 {
298                 match(LITERAL_Axis);
299                 match(LPAREN);
300                 idx=idx();
301                 match(RPAREN);
302                 }
303                 break;
304             }
305             case LITERAL_Columns:
306             case LITERAL_Rows:
307             case LITERAL_Pages:
308             case LITERAL_Chapters:
309             case LITERAL_Sections:
310             {
311                 {
312                 idx=axisName();
313                 }
314                 break;
315             }
316             default:
317             {
318                 throw new NoViableAltException(LT(1), getFilename());
319             }
320             }
321             }
322             axis = new Axis(idx);
323         }
324         catch (RecognitionException ex) {
325             reportError(ex);
326             recover(ex,_tokenSet_4);
327         }
328         return axis;
329     }
330     
331     public final TuplePosition tuplePosition(
332         Axis axis
333     ) throws RecognitionException, TokenStreamException {
334         TuplePosition pos = null;
335         
336         int idx;
337         
338         try { // for error handling
339
{
340             switch ( LA(1)) {
341             case MONDRIDX:
342             {
343                 idx=mondrIdx();
344                 break;
345             }
346             case MONDRNAME:
347             {
348                 String JavaDoc dimensionName;
349                 dimensionName=mondrName();
350                 idx = mappingMeta.getDimensionIndex(axis, dimensionName);
351                 break;
352             }
353             default:
354             {
355                 throw new NoViableAltException(LT(1), getFilename());
356             }
357             }
358             }
359             pos = new TuplePosition(axis, idx);
360         }
361         catch (RecognitionException ex) {
362             reportError(ex);
363             recover(ex,_tokenSet_5);
364         }
365         return pos;
366     }
367     
368     public final MemberDepth memberDepth(
369         Axis axis, TuplePosition pos
370     ) throws RecognitionException, TokenStreamException {
371         MemberDepth memberDepth = null;
372         
373         
374         try { // for error handling
375
{
376             switch ( LA(1)) {
377             case MONDRIDX:
378             {
379                 int depth;
380                 depth=mondrIdx();
381                 memberDepth = new MemberDepth(depth);
382                 break;
383             }
384             case MONDRNAME:
385             {
386                 String JavaDoc levelName;
387                 levelName=mondrName();
388                 memberDepth = new MemberDepth(mappingMeta.getLevelDepth(pos, levelName));
389                 break;
390             }
391             default:
392             {
393                 throw new NoViableAltException(LT(1), getFilename());
394             }
395             }
396             }
397         }
398         catch (RecognitionException ex) {
399             reportError(ex);
400             recover(ex,_tokenSet_6);
401         }
402         return memberDepth;
403     }
404     
405     public final Member memberLevel() throws RecognitionException, TokenStreamException {
406         Member member = null;
407         
408         Axis axis; TuplePosition pos; MemberDepth depth;
409         
410         try { // for error handling
411
axis=axis();
412             pos=tuplePosition(axis);
413             depth=memberDepth(axis, pos);
414             member = new Member(pos, depth);
415         }
416         catch (RecognitionException ex) {
417             reportError(ex);
418             recover(ex,_tokenSet_7);
419         }
420         return member;
421     }
422     
423     public final int idx() throws RecognitionException, TokenStreamException {
424         int i = -1;
425         
426         Token idx = null;
427         
428         try { // for error handling
429
idx = LT(1);
430             match(INT);
431             i = Integer.parseInt(idx.getText());
432         }
433         catch (RecognitionException ex) {
434             reportError(ex);
435             recover(ex,_tokenSet_7);
436         }
437         return i;
438     }
439     
440     public final int axisName() throws RecognitionException, TokenStreamException {
441         int idx = -1;
442         
443         
444         try { // for error handling
445
{
446             switch ( LA(1)) {
447             case LITERAL_Columns:
448             {
449                 match(LITERAL_Columns);
450                 idx = 0;
451                 break;
452             }
453             case LITERAL_Rows:
454             {
455                 match(LITERAL_Rows);
456                 idx = 1;
457                 break;
458             }
459             case LITERAL_Pages:
460             {
461                 match(LITERAL_Pages);
462                 idx = 2;
463                 break;
464             }
465             case LITERAL_Chapters:
466             {
467                 match(LITERAL_Chapters);
468                 idx = 3;
469                 break;
470             }
471             case LITERAL_Sections:
472             {
473                 match(LITERAL_Sections);
474                 idx = 4;
475                 break;
476             }
477             default:
478             {
479                 throw new NoViableAltException(LT(1), getFilename());
480             }
481             }
482             }
483         }
484         catch (RecognitionException ex) {
485             reportError(ex);
486             recover(ex,_tokenSet_4);
487         }
488         return idx;
489     }
490     
491     public final int mondrIdx() throws RecognitionException, TokenStreamException {
492         int i = -1;
493         
494         Token n = null;
495         
496         try { // for error handling
497
n = LT(1);
498             match(MONDRIDX);
499             i = getMondrIdx(n.getText());
500         }
501         catch (RecognitionException ex) {
502             reportError(ex);
503             recover(ex,_tokenSet_8);
504         }
505         return i;
506     }
507     
508     public final String JavaDoc mondrName() throws RecognitionException, TokenStreamException {
509         String JavaDoc name = null;
510         
511         Token n = null;
512         
513         try { // for error handling
514
n = LT(1);
515             match(MONDRNAME);
516             name = getMondrName(n.getText());
517         }
518         catch (RecognitionException ex) {
519             reportError(ex);
520             recover(ex,_tokenSet_9);
521         }
522         return name;
523     }
524     
525     public final String JavaDoc name() throws RecognitionException, TokenStreamException {
526         String JavaDoc name = null;
527         
528         Token n = null;
529         
530         try { // for error handling
531
n = LT(1);
532             match(NAME);
533             name = n.getText();
534         }
535         catch (RecognitionException ex) {
536             reportError(ex);
537             recover(ex,_tokenSet_10);
538         }
539         return name;
540     }
541     
542     public final List JavaDoc memberFilter() throws RecognitionException, TokenStreamException {
543         List JavaDoc filter = new ArrayList JavaDoc();;
544         
545         Member member;
546         
547         try { // for error handling
548
match(LPAREN);
549             member=memberLevel();
550             filter.add(member);
551             {
552             _loop26:
553             do {
554                 if ((LA(1)==COMMA)) {
555                     match(COMMA);
556                     member=memberLevel();
557                     filter.add(member);
558                 }
559                 else {
560                     break _loop26;
561                 }
562                 
563             } while (true);
564             }
565             match(RPAREN);
566         }
567         catch (RecognitionException ex) {
568             reportError(ex);
569             recover(ex,_tokenSet_3);
570         }
571         return filter;
572     }
573     
574     public final List JavaDoc axisPositions() throws RecognitionException, TokenStreamException {
575         List JavaDoc positions = new ArrayList JavaDoc();;
576         
577         AxisPosition pos; int axis = 0;
578         
579         try { // for error handling
580
match(LPAREN);
581             pos=axisPosition(axis);
582             ++axis; positions.add(pos);
583             {
584             _loop29:
585             do {
586                 if ((LA(1)==COMMA)) {
587                     match(COMMA);
588                     pos=axisPosition(axis);
589                     ++axis; positions.add(pos);
590                 }
591                 else {
592                     break _loop29;
593                 }
594                 
595             } while (true);
596             }
597             match(RPAREN);
598         }
599         catch (RecognitionException ex) {
600             reportError(ex);
601             recover(ex,_tokenSet_0);
602         }
603         return positions;
604     }
605     
606     public final AxisPosition axisPosition(
607         int axis
608     ) throws RecognitionException, TokenStreamException {
609         AxisPosition pos = null;
610         
611         int idx;
612         
613         try { // for error handling
614
{
615             switch ( LA(1)) {
616             case QMARK:
617             {
618                 match(QMARK);
619                 idx = AxisPosition.POSITION_UNSPECIFIED;
620                 break;
621             }
622             case INT:
623             {
624                 idx=idx();
625                 break;
626             }
627             case LPAREN:
628             case MONDRNAME:
629             {
630                 Tuple tuple;
631                 tuple=tuple();
632                 idx = mappingMeta.getTuplePosition(axis, tuple);
633                 break;
634             }
635             default:
636             {
637                 throw new NoViableAltException(LT(1), getFilename());
638             }
639             }
640             }
641             pos = new AxisPosition(idx);
642         }
643         catch (RecognitionException ex) {
644             reportError(ex);
645             recover(ex,_tokenSet_7);
646         }
647         return pos;
648     }
649     
650     public final Tuple tuple() throws RecognitionException, TokenStreamException {
651         Tuple tuple = null;
652         
653         TupleMember member;
654         
655         try { // for error handling
656
switch ( LA(1)) {
657             case LPAREN:
658             {
659                 {
660                 match(LPAREN);
661                 tuple = new Tuple();
662                 member=tupleMember();
663                 tuple.addMember(member);
664                 {
665                 _loop35:
666                 do {
667                     if ((LA(1)==COMMA)) {
668                         match(COMMA);
669                         member=tupleMember();
670                         tuple.addMember(member);
671                     }
672                     else {
673                         break _loop35;
674                     }
675                     
676                 } while (true);
677                 }
678                 match(RPAREN);
679                 }
680                 break;
681             }
682             case MONDRNAME:
683             {
684                 member=tupleMember();
685                 tuple = new Tuple(member);
686                 break;
687             }
688             default:
689             {
690                 throw new NoViableAltException(LT(1), getFilename());
691             }
692             }
693         }
694         catch (RecognitionException ex) {
695             reportError(ex);
696             recover(ex,_tokenSet_7);
697         }
698         return tuple;
699     }
700     
701     public final TupleMember tupleMember() throws RecognitionException, TokenStreamException {
702         TupleMember tuple = new TupleMember();
703         
704         String JavaDoc name;
705         
706         try { // for error handling
707
name=mondrName();
708             tuple.addName(name);
709             {
710             _loop38:
711             do {
712                 if ((LA(1)==POINT)) {
713                     match(POINT);
714                     name=mondrName();
715                     tuple.addName(name);
716                 }
717                 else {
718                     break _loop38;
719                 }
720                 
721             } while (true);
722             }
723         }
724         catch (RecognitionException ex) {
725             reportError(ex);
726             recover(ex,_tokenSet_7);
727         }
728         return tuple;
729     }
730     
731     
732     public static final String JavaDoc[] _tokenNames = {
733         "<0>",
734         "EOF",
735         "<2>",
736         "NULL_TREE_LOOKAHEAD",
737         "\"Axis\"",
738         "LPAREN",
739         "RPAREN",
740         "\"Columns\"",
741         "\"Rows\"",
742         "\"Pages\"",
743         "\"Chapters\"",
744         "\"Sections\"",
745         "\"Data\"",
746         "\"FormattedData\"",
747         "COMMA",
748         "QMARK",
749         "POINT",
750         "INT",
751         "MONDRNAME",
752         "MONDRIDX",
753         "NAME",
754         "PLUS",
755         "MINUS",
756         "STAR",
757         "WS",
758         "MONDRCH",
759         "DIGIT",
760         "LETTER"
761     };
762     
763     private static final long[] mk_tokenSet_0() {
764         long[] data = { 2L, 0L};
765         return data;
766     }
767     public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
768     private static final long[] mk_tokenSet_1() {
769         long[] data = { 3984L, 0L};
770         return data;
771     }
772     public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
773     private static final long[] mk_tokenSet_2() {
774         long[] data = { 426018L, 0L};
775         return data;
776     }
777     public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
778     private static final long[] mk_tokenSet_3() {
779         long[] data = { 34L, 0L};
780         return data;
781     }
782     public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
783     private static final long[] mk_tokenSet_4() {
784         long[] data = { 786432L, 0L};
785         return data;
786     }
787     public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4());
788     private static final long[] mk_tokenSet_5() {
789         long[] data = { 786466L, 0L};
790         return data;
791     }
792     public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5());
793     private static final long[] mk_tokenSet_6() {
794         long[] data = { 16482L, 0L};
795         return data;
796     }
797     public static final BitSet _tokenSet_6 = new BitSet(mk_tokenSet_6());
798     private static final long[] mk_tokenSet_7() {
799         long[] data = { 16448L, 0L};
800         return data;
801     }
802     public static final BitSet _tokenSet_7 = new BitSet(mk_tokenSet_7());
803     private static final long[] mk_tokenSet_8() {
804         long[] data = { 802914L, 0L};
805         return data;
806     }
807     public static final BitSet _tokenSet_8 = new BitSet(mk_tokenSet_8());
808     private static final long[] mk_tokenSet_9() {
809         long[] data = { 868450L, 0L};
810         return data;
811     }
812     public static final BitSet _tokenSet_9 = new BitSet(mk_tokenSet_9());
813     private static final long[] mk_tokenSet_10() {
814         long[] data = { 64L, 0L};
815         return data;
816     }
817     public static final BitSet _tokenSet_10 = new BitSet(mk_tokenSet_10());
818     
819     }
820
Popular Tags