org.jboss.naming
Class NonSerializableFactory
java.lang.Object
|
+--org.jboss.naming.NonSerializableFactory
- All Implemented Interfaces:
- javax.naming.spi.ObjectFactory
- public class NonSerializableFactory
- extends java.lang.Object
- implements javax.naming.spi.ObjectFactory
A utility class that allows one to bind a non-serializable object into a
local JNDI context. The binding will only be valid for the lifetime of the
VM in which the JNDI InitialContext lives. An example usage code snippet is:
// The non-Serializable object to bind
Object nonserializable = ...;
// An arbitrary key to use in the StringRefAddr. The best key is the jndi
// name that the object will be bound under.
String key = ...;
// This places nonserializable into the NonSerializableFactory hashmap under key
NonSerializableFactory.rebind(key, nonserializable);
Context ctx = new InitialContext();
// Bind a reference to nonserializable using NonSerializableFactory as the ObjectFactory
String className = nonserializable.getClass().getName();
String factory = NonSerializableFactory.class.getName();
StringRefAddr addr = new StringRefAddr("nns", key);
Reference memoryRef = new Reference(className, addr, factory, null);
ctx.rebind(key, memoryRef);
Or you can use the rebind(Context, String, Object) convience method to simplify
the number of steps to:
Context ctx = new InitialContext();
// The non-Serializable object to bind
Object nonserializable = ...;
// The jndiName that the object will be bound into ctx with
String jndiName = ...;
// This places nonserializable into the NonSerializableFactory hashmap under key
NonSerializableFactory.rebind(ctx, jndiName, nonserializable);
To unbind the object, use the following code snippet:
new InitialContext().unbind(key);
NonSerializableFactory.unbind(key);
- Version:
- $Revision: 1.5 $
- Author:
- Scott_Stark@displayscape.com
- See Also:
ObjectFactory
,
rebind(Context, String, Object)
Method Summary |
static void |
bind(java.lang.String key,
java.lang.Object target)
Place an object into the NonSerializableFactory namespace for subsequent
access by getObject. |
java.lang.Object |
getObjectInstance(java.lang.Object obj,
javax.naming.Name name,
javax.naming.Context nameCtx,
java.util.Hashtable env)
Transform the obj Reference bound into the JNDI namespace into the
actual non-Serializable object. |
static java.lang.Object |
lookup(java.lang.String key)
Lookup a value from the NonSerializableFactory map. |
static void |
rebind(javax.naming.Context ctx,
java.lang.String key,
java.lang.Object target)
A convience method that simplifies the process of rebinding a
non-zerializable object into a JNDI context. |
static void |
rebind(java.lang.String key,
java.lang.Object target)
Place or replace an object in the NonSerializableFactory namespce
for subsequent access by getObject. |
static void |
unbind(java.lang.String key)
Remove a binding from the NonSerializableFactory map. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NonSerializableFactory
public NonSerializableFactory()
bind
public static void bind(java.lang.String key,
java.lang.Object target)
throws javax.naming.NameAlreadyBoundException
- Place an object into the NonSerializableFactory namespace for subsequent
access by getObject. There cannot be an already existing binding for key.
- Parameters:
key,
- the name to bind target under. This should typically be the
name that will be used to bind target in the JNDI namespace, but it does
not have to be.target,
- the non-Serializable object to bind.- Throws:
NameAlreadyBoundException,
- thrown if key already exists in the
NonSerializableFactory map
rebind
public static void rebind(java.lang.String key,
java.lang.Object target)
- Place or replace an object in the NonSerializableFactory namespce
for subsequent access by getObject. Any existing binding for key will be
replaced by target.
- Parameters:
key,
- the name to bind target under. This should typically be the
name that will be used to bind target in the JNDI namespace, but it does
not have to be.target,
- the non-Serializable object to bind.
unbind
public static void unbind(java.lang.String key)
throws javax.naming.NameNotFoundException
- Remove a binding from the NonSerializableFactory map.
- Parameters:
key,
- the key into the NonSerializableFactory map to remove.target,
- the non-Serializable object to bind.- Throws:
NameNotFoundException,
- thrown if key does not exist in the
NonSerializableFactory map
lookup
public static java.lang.Object lookup(java.lang.String key)
- Lookup a value from the NonSerializableFactory map.
- Returns:
- the object bound to key is one exists, null otherwise.
rebind
public static void rebind(javax.naming.Context ctx,
java.lang.String key,
java.lang.Object target)
throws javax.naming.NamingException
- A convience method that simplifies the process of rebinding a
non-zerializable object into a JNDI context.
- Parameters:
ctx,
- the JNDI context to rebind to.key,
- the key to use in both the NonSerializableFactory map and JNDI. It
must be a valid name for use in ctx.bind().target,
- the non-Serializable object to bind.- Throws:
NamingException,
- thrown on failure to rebind key into ctx.
getObjectInstance
public java.lang.Object getObjectInstance(java.lang.Object obj,
javax.naming.Name name,
javax.naming.Context nameCtx,
java.util.Hashtable env)
throws java.lang.Exception
- Transform the obj Reference bound into the JNDI namespace into the
actual non-Serializable object.
- Specified by:
getObjectInstance
in interface javax.naming.spi.ObjectFactory
- Parameters:
obj,
- the object bound in the JNDI namespace. This must be an implementation
of javax.naming.Reference with a javax.naming.RefAddr of type "nns" whose
content is the String key used to location the non-Serializable object in the
NonSerializableFactory map.name,
- ignored.nameCtx,
- ignored.env,
- ignored.- Returns:
- the non-Serializable object associated with the obj Reference if one
exists, null if one does not.
Copyright © 2000 The JBoss Organization. All Rights Reserved.