|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractFreezable.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (C) The DNA Group. All rights reserved.
|
|
| 3 |
*
|
|
| 4 |
* This software is published under the terms of the DNA
|
|
| 5 |
* Software License version 1.1, a copy of which has been included
|
|
| 6 |
* with this distribution in the LICENSE.txt file.
|
|
| 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 | 18 |
public void makeReadOnly() |
| 29 |
{
|
|
| 30 | 18 |
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 | 234 |
protected final void checkWriteable() |
| 41 |
{
|
|
| 42 | 234 |
if( m_readOnly )
|
| 43 |
{
|
|
| 44 | 3 |
final String message = |
| 45 |
"Resource (" + this + ") is read only and can not be modified"; |
|
| 46 | 3 |
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 | 18 |
protected final boolean isReadOnly() |
| 57 |
{
|
|
| 58 | 18 |
return m_readOnly;
|
| 59 |
} |
|
| 60 |
} |
|
| 61 |
|
|
||||||||||