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
|
package org.litesoft.core;
import org.litesoft.util.*;
import java.io.*;
import java.util.*;
public abstract class ServerSession
{
/**
* Returns the object bound with the specified pClass Name in this ServerSession, 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
* @throws IllegalStateException if this method is called on an
* expired ServerSession
*/
@SuppressWarnings({"unchecked"})
public <T extends Serializable> T getAttribute( Class<T> pClass )
{
return (T) LLgetAttribute( toName( pClass ) );
}
/**
* Returns the object bound with the specified Class Name in this ServerSession, 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
* @throws IllegalStateException if this method is called on an
* expired ServerSession
*/
public <T extends Serializable> T getRequired( Class<T> pClass )
throws NoSuchElementException
{
T zInstance = getAttribute( pClass );
if ( zInstance == null )
{
throw new NoSuchElementException();
}
return zInstance;
}
/**
* Binds an object to this ServerSession, using the pClass Name specified.
* If an object of the same pClass Name is already bound to this ServerSession,
* 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
* @throws IllegalStateException if this method is called on an
* expired ServerSession
*/
public <T extends Serializable, V extends T> void setAttribute( Class<T> pClass, V pInstance )
{
if ( pInstance == null )
{
LLremoveAttribute( toName( pClass ) );
}
else
{
LLsetAttribute( toName( pClass ), pInstance );
}
}
/**
* Removes the object bound with the specified pClass Name from
* this ServerSession. If the ServerSession 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 ServerSession
*
* @throws IllegalArgumentException if pClass is null
* @throws IllegalStateException if this method is called on an
* expired ServerSession
*/
public <T extends Serializable> void removeAttribute( Class<T> pClass )
{
LLremoveAttribute( toName( pClass ) );
}
private String toName( Class<?> pClass )
{
Utils.assertNotNull( "Class", pClass );
return pClass.getName();
}
abstract protected Serializable LLgetAttribute( String pName );
abstract protected void LLsetAttribute( String pName, Serializable pInstance );
abstract protected void LLremoveAttribute( String pName );
}
|
Revision |
Author |
Commited |
Message |
2
|
GeorgeS
|
Sun 07 Feb, 2010 12:50:58 +0000 |
|