User: stark
Date: 01/02/07 18:29:49
Modified: src/main/org/jboss/naming NonSerializableFactory.java
Log:
Add a rebind(Context ctx, String key, Object target) class method to
simplify the number of steps required to bind a non-serializable object
into a JNDi context.
Revision Changes Path
1.3 +36 -1 jboss/src/main/org/jboss/naming/NonSerializableFactory.java
Index: NonSerializableFactory.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/naming/NonSerializableFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NonSerializableFactory.java 2001/01/21 00:23:01 1.2
+++ NonSerializableFactory.java 2001/02/08 02:29:48 1.3
@@ -14,8 +14,10 @@
import javax.naming.Name;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.RefAddr;
+import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
/** A utility class that allows one to bind a non-serializable object into a
@@ -40,6 +42,19 @@
ctx.rebind(key, memoryRef);
</code>
+Or you can use the rebind(Context, String, Object) convience method to simplify
+the number of steps to:
+<code>
+ Context ctx = new InitialContext();
+ // 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(ctx, key, nonserializable);
+</code>
+
To unbind the object, use the following code snippet:
<code>
@@ -48,9 +63,10 @@
</code>
@see javax.naming.spi.ObjectFactory
+@see #rebind(Context, String, Object)
@author [EMAIL PROTECTED]
-@version $Revision: 1.2 $
+@version $Revision: 1.3 $
*/
public class NonSerializableFactory implements ObjectFactory
{
@@ -97,6 +113,25 @@
{
if( wrapperMap.remove(key) == null )
throw new NameNotFoundException(key+" was not found in the
NonSerializableFactory map");
+ }
+
+ /** A convience method that simplifies the process of rebinding a
+ non-zerializable object into a JNDI context.
+
+ @param ctx, the JNDI context to rebind to.
+ @param key, the key to use in both the NonSerializableFactory map and JNDI.
+ @param target, the non-Serializable object to bind.
+ @throws NamingException, thrown on failure to rebind key into ctx.
+ */
+ public static synchronized void rebind(Context ctx, String key, Object target)
throws NamingException
+ {
+ NonSerializableFactory.rebind(key, target);
+ // Bind a reference to target using NonSerializableFactory as the
ObjectFactory
+ String className = target.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);
}
// --- Begin ObjectFactory interface methods