KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tanukisoftware > wrapper > WrapperProperties


1 package org.tanukisoftware.wrapper;
2
3 /*
4  * Copyright (c) 1999, 2006 Tanuki Software Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of the Java Service Wrapper and associated
8  * documentation files (the "Software"), to deal in the Software
9  * without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sub-license,
11  * and/or sell copies of the Software, and to permit persons to
12  * whom the Software is furnished to do so, subject to the
13  * following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */

27
28 import java.io.InputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Properties JavaDoc;
35 import java.util.Set JavaDoc;
36
37 /**
38  * Provides a Properties object which can be locked to prevent modification
39  * by the user.
40  *
41  * @author Leif Mortenson <leif@tanukisoftware.com>
42  */

43 class WrapperProperties
44     extends Properties JavaDoc
45 {
46     boolean m_locked = false;
47     
48     /**
49      * Locks the Properties object against future modification.
50      */

51     public void lock()
52     {
53         m_locked = true;
54     }
55     
56     public void load( InputStream JavaDoc inStream )
57         throws IOException JavaDoc
58     {
59         if ( m_locked )
60         {
61             throw new IllegalStateException JavaDoc( "Read Only" );
62         }
63         super.load( inStream );
64     }
65     
66     public Object JavaDoc setProperty( String JavaDoc key, String JavaDoc value )
67     {
68         if ( m_locked )
69         {
70             throw new IllegalStateException JavaDoc( "Read Only" );
71         }
72         return super.setProperty( key, value );
73     }
74     
75     public void clear()
76     {
77         if ( m_locked )
78         {
79             throw new IllegalStateException JavaDoc( "Read Only" );
80         }
81         super.clear();
82     }
83     
84     public Set JavaDoc entrySet()
85     {
86         if ( m_locked )
87         {
88             return Collections.unmodifiableSet( super.entrySet() );
89         }
90         else
91         {
92             return super.entrySet();
93         }
94     }
95     
96     public Set JavaDoc keySet()
97     {
98         if ( m_locked )
99         {
100             return Collections.unmodifiableSet( super.keySet() );
101         }
102         else
103         {
104             return super.keySet();
105         }
106     }
107     
108     public Object JavaDoc put( Object JavaDoc key, Object JavaDoc value )
109     {
110         if ( m_locked )
111         {
112             throw new IllegalStateException JavaDoc( "Read Only" );
113         }
114         return super.put( key, value );
115     }
116     
117     public void putAll( Map JavaDoc map )
118     {
119         if ( m_locked )
120         {
121             throw new IllegalStateException JavaDoc( "Read Only" );
122         }
123         super.putAll( map );
124     }
125     
126     public Object JavaDoc remove( Object JavaDoc key )
127     {
128         if ( m_locked )
129         {
130             throw new IllegalStateException JavaDoc( "Read Only" );
131         }
132         return super.remove( key );
133     }
134     
135     public Collection JavaDoc values()
136     {
137         if ( m_locked )
138         {
139             return Collections.unmodifiableCollection( super.values() );
140         }
141         else
142         {
143             return super.values();
144         }
145     }
146 }
147
148
Popular Tags