litesoft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
package org.litesoft.core;
import org.litesoft.core.util.*;
import org.litesoft.util.*;
import java.io.*;
import java.util.*;
public class ServerStore implements Disposable
{
private Map mEntries = new HashMap();
public ServerStore()
{
}
public ServerStore( ServerStore pCopyFrom )
{
if ( pCopyFrom != null )
{
pCopyFrom.copyTo( mEntries );
}
}
/**
* Returns the object bound with the specified pClass Name in this ServerStore, or
* <code>null</code> if no object is bound under the pClass Name.
*
* @param pClass specifying the Class Name of the object
*
* @return the object bound with the specified Class Name
*
* @throws IllegalArgumentException if pClass is null
*/
@SuppressWarnings({"unchecked"})
public synchronized final <T> T get( Class<T> pClass )
{
return (T) mEntries.get( pClass );
}
/**
* Returns the object bound with the specified Class Name in this ServerStore, or
* <code>null</code> if no object is bound under the Class Name.
*
* @param pClass specifying the Class Name of the object
*
* @return the object bound with the specified Class Name
*
* @throws IllegalArgumentException if pClass is null
* @throws NoSuchElementException if there is no object bound to the specified Class Name
*/
public <T extends Serializable> T getRequired( Class<T> pClass )
throws NoSuchElementException
{
T zInstance = get( pClass );
if ( zInstance == null )
{
throw new NoSuchElementException();
}
return zInstance;
}
/**
* Binds an object to this ServerStore, using the pClass Name specified.
* If an object of the same pClass Name is already bound to this ServerStore,
* the object is replaced.
* <p/>
* <p>If the value passed in is null, this has the same effect as calling
* <code>removeAttribute()<code>.
*
* @param pClass the Class Name to which the object will be bound;
* cannot be null
* @param pInstance the object to be bound
*
* @throws IllegalArgumentException if pClass is null
*/
public final <T, V extends T> void set( Class<T> pClass, V pInstance )
{
if ( pInstance == null )
{
remove( pClass );
}
else
{
Object zPrev = LLput( assertNotNull( pClass ), pInstance );
if ( pInstance != zPrev ) // Same Object!
{
LLdispose( zPrev );
}
}
}
/**
* Removes the object bound with the specified pClass Name from
* this ServerStore. If the ServerStore does not have an object
* bound with the specified pClass Name, this method does nothing.
*
* @param pClass specifying the Class Name of the object
* to remove from this ServerStore
*
* @throws IllegalArgumentException if pClass is null
*/
public final <T> void remove( Class<T> pClass )
{
LLdispose( LLremove( assertNotNull( pClass ) ) );
}
@Override
protected void finalize()
throws Throwable
{
dispose();
super.finalize();
}
public void dispose()
{
Map zMap;
synchronized ( this )
{
zMap = mEntries;
mEntries = null;
}
if ( zMap != null )
{
for ( Object zInstance : zMap.values() )
{
LLdispose( zInstance );
}
}
}
private <T> Class<T> assertNotNull( Class<T> pClass )
{
Utils.assertNotNull( "Class", pClass );
return pClass;
}
@SuppressWarnings({"unchecked"})
private synchronized <T, V extends T> Object LLput( Class<T> pClass, V pInstance )
{
return mEntries.put( pClass, pInstance );
}
private synchronized <T> Object LLremove( Class<T> pClass )
{
return mEntries.remove( pClass );
}
private void LLdispose( Object pInstance )
{
if ( pInstance instanceof Disposable )
{
((Disposable) pInstance).dispose();
}
}
@SuppressWarnings({"unchecked"})
private synchronized void copyTo( Map pTarget )
{
pTarget.putAll( mEntries );
}
}
|
Revision |
Author |
Commited |
Message |
2
|
GeorgeS
|
Sun 07 Feb, 2010 12:50:58 +0000 |
|