1 package de.matthias_burbach.mosaique.core.model;
2
3 /***
4 * Is the abstract base class for parsed objects that relate to a file and a
5 * specific part of a file.
6 *
7 * @author Matthias Burbach
8 */
9 public abstract class AbstractFileItem {
10 /***
11 * Holds what is kind of global but still distinct for different contexts.
12 */
13 private Context context;
14
15 /***
16 * The full path of the file this item relates to.
17 */
18 private String filePath;
19
20 /***
21 * The character begin position of the text this item was parsed from.
22 * -1 means unknown.
23 */
24 private int begin = -1;
25
26 /***
27 * The character end position of the text this item was parsed from.
28 * -1 means unknown.
29 */
30 private int end = -1;
31
32 /***
33 * The text to search for within the underlying text file to find the text
34 * this item was parsed from.
35 * <p/>
36 * Serves as substitute if begin and end
37 * character positions are not available.
38 * <p/>
39 * Can be <code>null</code>.
40 */
41 private String primarySearchText;
42
43 /***
44 * The text to search for within the underlying text file
45 * relative to the matching position of the primary search text
46 * to find the text this item was parsed from.
47 * <p/>
48 * Serves as substitute if begin and end character positions are not
49 * available.
50 * <p/>
51 * Can be <code>null</code>.
52 */
53 private String secondarySearchText;
54
55 /***
56 * Signals that the (creator of this) file item has discovered an error
57 * related to this file item.
58 * Can be used to display the error state, for example.
59 */
60 private boolean erroneous = false;
61
62 /***
63 * A message about this file item. Can be an error message if
64 * {@link #erroneous} is <code>true</code>.
65 */
66 private String message;
67
68 /***
69 * @return A message about this file item. Can be an error message if
70 * {@link #isErroneous()} is <code>true</code>.
71 */
72 public String getMessage() {
73 return message;
74 }
75
76 /***
77 * @param message A message about this file item. Can be an error message if
78 * {@link #isErroneous()} is <code>true</code>.
79 */
80 public void setMessage(final String message) {
81 this.message = message;
82 }
83
84 /***
85 * @return Signals that the (creator of the) node has discovered an error
86 * related to this node.
87 * Can be used to display the error state, for example.
88 */
89 public boolean isErroneous() {
90 return erroneous;
91 }
92
93 /***
94 * @param erroneous Signals that the (creator of the) node has discovered an
95 * error related to this node.
96 * Can be used to display the error state, for example.
97 */
98 public void setErroneous(final boolean erroneous) {
99 this.erroneous = erroneous;
100 }
101
102 /***
103 * @return The full path of the file this item relates to.
104 */
105 public String getFilePath() {
106 return filePath;
107 }
108
109 /***
110 * @param filePath The full path of the file this item relates to.
111 */
112 public void setFilePath(final String filePath) {
113 this.filePath = filePath;
114 }
115
116 /***
117 * @return The character begin position of the text this item was parsed
118 * from. -1 means unknown.
119 */
120 public int getBegin() {
121 return begin;
122 }
123
124 /***
125 * @param begin The character begin position of the text this item was
126 * parsed from. -1 means unknown.
127 */
128 public void setBegin(final int begin) {
129 this.begin = begin;
130 }
131
132 /***
133 * @return The column number where the text this item was parsed from
134 * starts. -1 means unknown.
135 */
136 public int getEnd() {
137 return end;
138 }
139
140 /***
141 * @param end The character end position of the text this item was parsed
142 * from. -1 means unknown.
143 */
144 public void setEnd(final int end) {
145 this.end = end;
146 }
147
148 /***
149 * @return The text to search for within the underlying text file to find
150 * the text this item was parsed from.
151 * Can be <code>null</code>.
152 */
153 public String getPrimarySearchText() {
154 return primarySearchText;
155 }
156
157 /***
158 * @param primarySearchText The text to search for within the underlying
159 * text file to find the text this item was parsed
160 * from.
161 * Can be <code>null</code>.
162 */
163 public void setPrimarySearchText(final String primarySearchText) {
164 this.primarySearchText = primarySearchText;
165 }
166
167 /***
168 * @return The text to search for within the underlying
169 * text file relative to the matching position of
170 * the primary search text to find the text this
171 * item was parsed from.
172 * Can be <code>null</code>.
173 */
174 public String getSecondarySearchText() {
175 return secondarySearchText;
176 }
177
178 /***
179 * @param secondarySearchText The text to search for within the underlying
180 * text file relative to the matching position of
181 * the primary search text to find the text this
182 * item was parsed from.
183 * Can be <code>null</code>.
184 */
185 public void setSecondarySearchText(final String secondarySearchText) {
186 this.secondarySearchText = secondarySearchText;
187 }
188
189 /***
190 * @return The context holding the objects to be shared by a cluster of
191 * application objects.
192 */
193 protected Context getContext() {
194 return context;
195 }
196
197 /***
198 * @param context The context holding the objects to be shared by a cluster
199 * of application objects.
200 */
201 protected void setContext(final Context context) {
202 this.context = context;
203 }
204
205 /***
206 * @return The definition resolver to use by this instance
207 * (in subclass code).
208 */
209 protected DefinitionResolver getDefinitionResolver() {
210 DefinitionResolver result = null;
211 if (context != null) {
212 result = context.getDefinitionResolver();
213 } else {
214 result = DefinitionResolver.getInstance();
215 }
216 return result;
217 }
218
219 /***
220 * @return The JSP resolver to use by this instance
221 * (in subclass code).
222 */
223 protected JspResolver getJspResolver() {
224 JspResolver result = null;
225 if (context != null) {
226 result = context.getJspResolver();
227 } else {
228 result = JspResolver.getInstance();
229 }
230 return result;
231 }
232 }