01: /*
02: * Copyright (C) The DNA Group. All rights reserved.
03: *
04: * This software is published under the terms of the DNA
05: * Software License version 1.1, a copy of which has been included
06: * with this distribution in the LICENSE.txt file.
07: */
08: package org.codehaus.dna.impl;
09:
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 implements Freezable {
17: /**
18: * Flag indicating whether resource has been
19: * made read-only yet.
20: */
21: private boolean m_readOnly;
22:
23: /**
24: * Mark the resource as read only.
25: */
26: public void makeReadOnly() {
27: m_readOnly = true;
28: }
29:
30: /**
31: * Check if the resource has been "frozen"
32: * and thus is read only. If read-only then
33: * throw an IllegalStateException.
34: *
35: * @throws IllegalStateException if resource is read-only
36: */
37: protected final void checkWriteable() {
38: if (m_readOnly) {
39: final String message = "Resource (" + this
40: + ") is read only and can not be modified";
41: throw new IllegalStateException(message);
42: }
43: }
44:
45: /**
46: * Return true if resource has been made read-only or frozen.
47: *
48: * @return true if resource has been made read-only or
49: * frozen, false otherwise.
50: */
51: protected final boolean isReadOnly() {
52: return m_readOnly;
53: }
54: }
|