1 /*
2 * Zemucan: A Syntax Assistant for DB2
3 * Copyright (C) 2009, 2010 Andres Gomez Casanova
4 *
5 * This file is part of Zemucan.
6 *
7 * Zemucan is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Zemucan is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 *
20 * Contact:
21 * a n g o c a at y a h o o dot c o m
22 * Cra. 45 No 61 - 31, Bogota, Colombia.
23 *
24 * Author: $LastChangedBy: angoca $:
25 * Date: $LastChangedDate: 2011-03-06 10:15:32 -0500 (dom, 06 mar 2011) $:
26 * Revision: $LastChangedRevision: 1913 $:
27 * URL: $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/grammarReaderApi/src/main/java/name/angoca/zemucan/grammarReader/api/AbstractGrammarReader.java $:
28 */
29 package name.angoca.zemucan.grammarReader.api;
30
31 import name.angoca.zemucan.AbstractZemucanException;
32 import name.angoca.zemucan.core.graph.model.Graph;
33 import name.angoca.zemucan.core.graph.model.StartingNode;
34
35 /**
36 * This is the specification of the class that builds the grammar graph from the
37 * grammar file. The implementation of this class has to have a construction
38 * with a Graph as parameter. The initialization is done via reflection, and
39 * that is the only constructor that it uses.
40 * <p>
41 * <b>Control Version</b>
42 * <p>
43 * <ul>
44 * <li>1.0.0 Class creation.</li>
45 * <li>1.0.1 GraphToken renamed by GraphNode</li>
46 * <li>1.1.0 Delimiters</li>
47 * <li>1.7.0 Synchronized version with implementation.</li>
48 * <li>1.8.0 New structure.</li>
49 * <li>1.9.0 Return graph.</li>
50 * <li>1.10.0 Protected attributes -> private.</li>
51 * </ul>
52 *
53 * @author Andres Gomez Casanova <a
54 * href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
55 * @version 1.10.0 2010-06-18
56 * @since 1.0
57 */
58 public abstract class AbstractGrammarReader {
59
60 /**
61 * Grammar delimiters.
62 */
63 private String delimiters;
64 /**
65 * If the grammar has been processed.
66 */
67 private boolean grammarProcessed;
68 /**
69 * Starting node.
70 */
71 private StartingNode startingNode;
72
73 /**
74 * Define the default values of the attributes.
75 */
76 protected AbstractGrammarReader() {
77 this.delimiters = null;
78 this.grammarProcessed = false;
79 this.startingNode = null;
80 }
81
82 /**
83 * Creates the graph, and establishes the delimiters.
84 *
85 * @return The generated graph.
86 * @throws AbstractZemucanException
87 * If the delimiters are wrongly defined in the grammar.
88 */
89 public abstract Graph/* ! */generateGraph() throws AbstractZemucanException;
90
91 /**
92 * Returns the delimiters that separates the tokens.
93 *
94 * @return the delimiters
95 * @throws AbstractGrammarReaderException
96 * If the grammar has not been processed.
97 */
98 public final String/* ! */getDelimiters()
99 throws AbstractGrammarReaderException {
100 if (!this.grammarProcessed) {
101 throw new UnprocessedGrammarException();
102 }
103 return this.delimiters;
104 }
105
106 /**
107 * Returns the token that is the entering point to the graph.
108 *
109 * @return the startingToken.
110 * @throws AbstractGrammarReaderException
111 * If the grammar has not been processed..
112 */
113 public final StartingNode/* ! */getStartingNode()
114 throws AbstractGrammarReaderException {
115 if (!this.grammarProcessed) {
116 throw new UnprocessedGrammarException();
117 }
118 return this.startingNode;
119 }
120
121 /**
122 * Establishes the delimiters attribute.
123 *
124 * @param delims
125 * Delimiters of the grammar.
126 */
127 protected final void setDelimiters(final String/* ! */delims) {
128 this.delimiters = delims;
129 }
130
131 /**
132 * Establishes if the grammar has already been processed.
133 *
134 * @param processed
135 * true if the grammar has been processed.
136 */
137 protected final void setGrammarProcessed(final boolean processed) {
138 this.grammarProcessed = processed;
139 }
140
141 /**
142 * Establishes the starting node of the graph.
143 *
144 * @param node
145 * Node that is the starting node of the graph.
146 */
147 protected final void setStartingNode(final StartingNode/* ! */node) {
148 this.startingNode = node;
149 }
150 }