A GuardedObject encapsulates a target object and a Guard object,
such that access to the target object is possible
only if the Guard object allows it.
Once an object is encapsulated by a GuardedObject,
access to that object is controlled by the getObject
method, which invokes the
checkGuard
method on the Guard object that is
guarding access. If access is not allowed,
an exception is thrown.
Guard
, Permission
Modifier and Type | Field and Description |
---|---|
private final Guard | guard
The guard object. |
private final Object | object
The object we are guarding. |
private static final long |
Access | Constructor and Description |
---|---|
public | GuardedObject(Object
the object to be guarded. object, Guard the Guard object that guards access to the object. guard)Constructs a GuardedObject using the specified object and guard. |
Modifier and Type | Method and Description |
---|---|
public Object | Returns: the guarded object.Retrieves the guarded object, or throws an exception if access to the guarded object is denied by the guard. |
private void | writeObject(ObjectOutputStream
the oos)ObjectOutputStream to which data is writtenWrites this object out to a stream (i.e., serializes it). |
guard | back to summary |
---|---|
private final Guard guard The guard object.
|
object | back to summary |
---|---|
private final Object object The object we are guarding.
|
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID
|
GuardedObject | back to summary |
---|---|
public GuardedObject(Object object, Guard guard) Constructs a GuardedObject using the specified object and guard.
If the Guard object is |
getObject | back to summary |
---|---|
public Object getObject() throws SecurityException Retrieves the guarded object, or throws an exception if access to the guarded object is denied by the guard.
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream oos) throws IOException Writes this object out to a stream (i.e., serializes it). We check the guard if there is one.
|