KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piaget > analyze > TCRParser


1 /*
2  * TCRjava
3  *
4  * Created on April 12, 2005, 8:19 PM
5  */

6
7 package org.netbeans.modules.piaget.analyze;
8
9 import java.io.StreamTokenizer JavaDoc;
10 import java.io.File JavaDoc;
11
12 /**
13  *
14  * @author loicsegapelli
15  *
16  * Syntactical grammar:
17  *
18  * S = timestamp PROPERTY
19  * PROPERTY = ("opened" OPENCLOSE) | ("activated" WINDOW) | ("activatedNodes" NODES) | "NBGAINEDFOCUS" | "NBLOSTFOCUS"
20  * OPENCLOSE = (("opening" | "closing") WINDOW) | "exception"
21  * WINDOW = ("editor"? windowName) | "null"
22  * NODES = ("parent" nodeParentName "node" nodeName)*
23  *
24  */

25 public abstract class TCRParser extends Parser {
26     
27     boolean editor;
28     
29     /** Creates a new instance of WParser */
30     public TCRParser(File JavaDoc f) {
31         super(f);
32     }
33     
34     protected void analyzeTokenInput() throws SyntaxException{
35         nextLONG();
36         timestamp = scanner.lval;
37         caseProperty();
38     }
39     
40     private void caseProperty() throws SyntaxException{
41         nextWORD();
42         if(svalIs("opened")){
43             caseOpenClose();
44         } else if(svalIs("activated")){
45             String JavaDoc s=caseWindow();
46             if(s!=null)analyzeActivated(s,editor);
47         } else if(svalIs("activatedNodes")){
48             caseNodes();
49         } else if(svalIs("NBGAINEDFOCUS")){
50             analyzeGAINED();
51         } else if(svalIs("NBLOSTFOCUS")){
52             analyzeLOST();
53         } else {
54             throw(new SyntaxException("skipped: "+scanner.sval));
55         }
56     }
57     
58     private void caseOpenClose() throws SyntaxException{
59         String JavaDoc s;
60         nextWORD();
61         if(svalIs("opening")){
62             s=caseWindow();
63             analyzeOpen(s,editor);
64         } else if(svalIs("closing")){
65             s=caseWindow();
66             analyzeClose(s,editor);
67         } else if(svalIs("exception")){
68             throw(new SyntaxException(""));
69         } else {
70             throw(new SyntaxException("unexpected token open/close:"+scanner.sval));
71         }
72     }
73     
74     private String JavaDoc caseWindow() throws SyntaxException{
75         nextWORD();
76         if(svalIs("editor")){
77             editor=true;
78             nextWORD();
79         } else editor=false;
80         return scanner.sval;
81     }
82     
83     private void caseNodes() throws SyntaxException{
84         String JavaDoc p,s;
85         nextWORD();
86         while(scanner.lastReturned==WORD){
87             if(!svalIs("parent")) throw(new SyntaxException("no parent "+scanner.sval));
88             nextWORD();
89             p=scanner.sval;
90             nextWORD();
91             if(!svalIs("node"))throw(new SyntaxException("node name not found"));
92             nextWORD();
93             s=scanner.sval;
94             analyzeNode(p,s);
95             next();
96         }
97         // compensates one too many iterations from the loop
98
scanner.pushBack();
99     }
100     
101     
102     /*
103      * From Parser: not implemented here
104      */

105     abstract protected void eof();
106     
107     /*
108      * From parser: not implemented here
109      */

110     abstract protected void init();
111     
112     abstract protected void analyzeNode(String JavaDoc parent, String JavaDoc node);
113     
114     abstract protected void analyzeOpen(String JavaDoc windowId, boolean editor);
115     
116     abstract protected void analyzeClose(String JavaDoc windowId , boolean editor);
117     
118     abstract protected void analyzeActivated(String JavaDoc windowId, boolean editor);
119     
120     abstract protected void analyzeGAINED();
121     
122     abstract protected void analyzeLOST();
123     
124 }
125
Popular Tags