1
20 package org.crosswire.jsword.passage;
21
22 import java.io.IOException;
23 import java.io.Reader;
24 import java.io.Writer;
25 import java.util.Iterator;
26
27 import org.crosswire.jsword.JSOtherMsg;
28 import org.crosswire.jsword.versification.Versification;
29
30
37 final class ReadOnlyPassage implements Passage {
38
46 ReadOnlyPassage(Passage ref, boolean ignore) {
47 this.ref = ref;
48 this.ignore = ignore;
49 }
50
51
54 public Versification getVersification() {
55 return ref.getVersification();
56 }
57
58
61 public Passage reversify(Versification newVersification) {
62 return ref.reversify(newVersification);
63 }
64
65
68 public boolean isWhole() {
69 return ref.isWhole();
70 }
71
72
75 public Passage getWhole() {
76 return ref.getWhole();
77 }
78
79
82 public void addAll(Key key) {
83 if (ignore) {
84 return;
85 }
86
87 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
88 }
89
90
96 public void removeAll(Key key) {
97 if (ignore) {
98 return;
99 }
100
101 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
102 }
103
104
107 public void retainAll(Key key) {
108 if (ignore) {
109 return;
110 }
111
112 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
113 }
114
115
118 public boolean contains(Key key) {
119 return ref.contains(key);
120 }
121
122
125 public boolean canHaveChildren() {
126 return ref.canHaveChildren();
127 }
128
129
132 public int getChildCount() {
133 return ref.getChildCount();
134 }
135
136
139 public int getCardinality() {
140 return ref.getCardinality();
141 }
142
143
146 public Iterator<Key> iterator() {
147 return ref.iterator();
148 }
149
150
153 public Key get(int index) {
154 return ref.get(index);
155 }
156
157
160 public int indexOf(Key that) {
161 return ref.indexOf(that);
162 }
163
164
167 public Key getParent() {
168 return ref.getParent();
169 }
170
171
174 public String getName() {
175 return ref.getName();
176 }
177
178
181 public String getName(Key base) {
182 return ref.getName(base);
183 }
184
185
188 public String getRootName() {
189 return ref.getRootName();
190 }
191
192
195 public String getOsisRef() {
196 return ref.getOsisRef();
197 }
198
199
202 public String getOsisID() {
203 return ref.getOsisID();
204 }
205
206
209 public String getOverview() {
210 return ref.getOverview();
211 }
212
213
216 public boolean isEmpty() {
217 return ref.isEmpty();
218 }
219
220
223 public int countVerses() {
224 return ref.countVerses();
225 }
226
227
230 public boolean hasRanges(RestrictionType restrict) {
231 return ref.hasRanges(restrict);
232 }
233
234
237 public int countRanges(RestrictionType restrict) {
238 return ref.countRanges(restrict);
239 }
240
241
244 public Passage trimVerses(int count) {
245 return ref.trimVerses(count);
246 }
247
248
251 public Passage trimRanges(int count, RestrictionType restrict) {
252 return ref.trimRanges(count, restrict);
253 }
254
255
258 public int booksInPassage() {
259 return ref.booksInPassage();
260 }
261
262
265 public Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException {
266 return ref.getVerseAt(offset);
267 }
268
269
272 public VerseRange getRangeAt(int offset, RestrictionType restrict) throws ArrayIndexOutOfBoundsException {
273 return ref.getRangeAt(offset, restrict);
274 }
275
276
279 public Iterator<VerseRange> rangeIterator(RestrictionType restrict) {
280 return ref.rangeIterator(restrict);
281 }
282
283
286 public void add(Key that) {
287 if (ignore) {
288 return;
289 }
290
291 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
292 }
293
294
297 public void remove(Key that) {
298 if (ignore) {
299 return;
300 }
301
302 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
303 }
304
305
308 public boolean containsAll(Passage that) {
309 return ref.containsAll(that);
310 }
311
312
315 public void clear() {
316 if (ignore) {
317 return;
318 }
319
320 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
321 }
322
323
326 public void blur(int by, RestrictionType restrict) {
327 if (ignore) {
328 return;
329 }
330
331 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
332 }
333
334
337 public void readDescription(Reader in) {
338 if (ignore) {
339 return;
340 }
341
342 throw new IllegalStateException(JSOtherMsg.lookupText("Cannot alter a read-only passage"));
343 }
344
345
348 public void writeDescription(Writer out) throws IOException {
349 ref.writeDescription(out);
350 }
351
352
355 public void optimizeReads() {
356 ref.optimizeReads();
357 }
358
359
362 public void addPassageListener(PassageListener li) {
363 }
364
365
368 public void removePassageListener(PassageListener li) {
369 }
370
371 @Override
372 public boolean equals(Object obj) {
373 return ref.equals(obj);
374 }
375
376 @Override
377 public int hashCode() {
378 return ref.hashCode();
379 }
380
381 @Override
382 public String toString() {
383 return ref.toString();
384 }
385
386 @Override
387 public ReadOnlyPassage clone() {
388 ReadOnlyPassage clone = null;
389 try {
390 clone = (ReadOnlyPassage) super.clone();
391 clone.ref = this.ref;
392 clone.ignore = this.ignore;
393 } catch (CloneNotSupportedException e) {
394 assert false : e;
395 }
396
397 return clone;
398 }
399
400
403 public int compareTo(Key o) {
404 return ref.compareTo(o);
405 }
406
407
410 private Passage ref;
411
412
415 private boolean ignore;
416
417
420 private static final long serialVersionUID = 3257853173036102193L;
421
422 }
423