1
2
3
4
5
6
7
8 package org.codehaus.dna.impl;
9
10 /***
11 * Abstract utility class for resources that can be "frozen"
12 * and made read-only after being constructed.
13 *
14 * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
15 */
16 abstract class AbstractFreezable
17 implements Freezable
18 {
19 /***
20 * Flag indicating whether resource has been
21 * made read-only yet.
22 */
23 private boolean m_readOnly;
24
25 /***
26 * Mark the resource as read only.
27 */
28 public void makeReadOnly()
29 {
30 m_readOnly = true;
31 }
32
33 /***
34 * Check if the resource has been "frozen"
35 * and thus is read only. If read-only then
36 * throw an IllegalStateException.
37 *
38 * @throws IllegalStateException if resource is read-only
39 */
40 protected final void checkWriteable()
41 {
42 if( m_readOnly )
43 {
44 final String message =
45 "Resource (" + this + ") is read only and can not be modified";
46 throw new IllegalStateException( message );
47 }
48 }
49
50 /***
51 * Return true if resource has been made read-only or frozen.
52 *
53 * @return true if resource has been made read-only or
54 * frozen, false otherwise.
55 */
56 protected final boolean isReadOnly()
57 {
58 return m_readOnly;
59 }
60 }