aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/security/GuardedObject.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/security/GuardedObject.java')
-rw-r--r--libjava/java/security/GuardedObject.java61
1 files changed, 43 insertions, 18 deletions
diff --git a/libjava/java/security/GuardedObject.java b/libjava/java/security/GuardedObject.java
index 2aa13e1..f07d811 100644
--- a/libjava/java/security/GuardedObject.java
+++ b/libjava/java/security/GuardedObject.java
@@ -1,5 +1,5 @@
/* GuardedObject.java -- An object protected by a Guard
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,38 +38,50 @@ exception statement from your version. */
package java.security;
import java.io.Serializable;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
/**
* This class is an object that is guarded by a <code>Guard</code> object.
- * The object that is being guarded is retrieved by a call to the only
+ * The object that is being guarded is retrieved by a call to the only
* method in this class - <code>getObject</code>. That method returns the
- * guarded <code>Object</code> after first checking with the
+ * guarded <code>Object</code> after first checking with the
* <code>Guard</code>. If the <code>Guard</code> disallows access, an
* exception will be thrown.
*
- * @version 0.0
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @since 1.1
+ * @status updated to 1.4
*/
public class GuardedObject implements Serializable
{
/**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -5240450096227834308L;
+
+ /**
* This is the Guard that is protecting the object.
+ *
+ * @serial the guard
*/
- private Guard guard;
+ private final Guard guard;
/**
* This is the object that is being guarded.
+ *
+ * @serial the protected object
*/
- private Object object;
+ private final Object object;
/**
* This method initializes a new instance of <code>GuardedObject</code>
* that protects the specified <code>Object</code> using the specified
- * <code>Guard</code>
+ * <code>Guard</code>. A null guard means there are no restrictions on
+ * accessing the object.
*
- * @param object The <code>Object</code> to guard
- * @param guard The <code>Guard</code> that is protecting the object.
+ * @param object the <code>Object</code> to guard
+ * @param guard the <code>Guard</code> that is protecting the object
*/
public GuardedObject(Object object, Guard guard)
{
@@ -78,18 +90,31 @@ public class GuardedObject implements Serializable
}
/**
- * This method first call the <code>checkGuard</code> method on the
- * <code>Guard</code> object protecting the guarded object. If the
+ * This method first call the <code>checkGuard</code> method on the
+ * <code>Guard</code> object protecting the guarded object. If the
* <code>Guard</code> disallows access, an exception is thrown, otherwise
* the <code>Object</code> is returned.
*
* @return The object being guarded
+ * @throws SecurityException if access is denied
+ */
+ public Object getObject()
+ {
+ if (guard != null)
+ guard.checkGuard(object);
+ return object;
+ }
+
+ /**
+ * Ensures that serialization is legal, by checking the guard.
*
- * @exception SecurityException If the <code>Guard</code> disallows access to the object.
+ * @param s the stream to write to
+ * @throws IOException if the underlying stream fails
*/
- public Object getObject() throws SecurityException
+ private void writeObject(ObjectOutputStream s) throws IOException
{
- guard.checkGuard(object);
- return (object);
+ if (guard != null)
+ guard.checkGuard(object);
+ s.defaultWriteObject();
}
-}
+} // class GuardedObject