FileDocCategorySizeDatePackage
NonSerializableFactory.javaAPI DocJBoss 4.2.14433Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3

NonSerializableFactory

public class NonSerializableFactory extends Object implements 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:

Internally, there is a static map that is keyed based on Context identityMap and the atom name of the target

author
Bill Burke.
author
Scott Stark.
version
$Revision: 57207 $
see
javax.naming.spi.ObjectFactory
see
#rebind(javax.naming.Context, String, Object)

Fields Summary
private static Map
wrapperMap
Constructors Summary
Methods Summary
public static voidbind(javax.naming.Context ctx, java.lang.String strName, java.lang.Object value)

      Name name = ctx.getNameParser("").parse(strName);
      int size = name.size();
      String atom = name.get(size - 1);
      Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1));
      String key = parentCtx.getNameInNamespace() + "/" + atom;
      wrapperMap.put(key, value);
      String className = value.getClass().getName();
      String factory = NonSerializableFactory.class.getName();
      StringRefAddr addr = new StringRefAddr("nns", key);
      Reference memoryRef = new Reference(className, addr, factory, null);
      
      parentCtx.bind(atom, memoryRef);
   
public java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable env)

	// Get the nns value from the Reference obj and use it as the map key
      Reference ref = (Reference) obj;
      RefAddr addr = ref.get("nns");
      String key = (String) addr.getContent();
      return wrapperMap.get(key);
   
public static voidrebind(javax.naming.Context ctx, java.lang.String strName, java.lang.Object value)

      Name name = ctx.getNameParser("").parse(strName);
      int size = name.size();
      String atom = name.get(size - 1);
      Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1));
      String key = parentCtx.getNameInNamespace() + "/" + atom;
      wrapperMap.put(key, value);
      String className = value.getClass().getName();
      String factory = NonSerializableFactory.class.getName();
      StringRefAddr addr = new StringRefAddr("nns", key);
      Reference memoryRef = new Reference(className, addr, factory, null);
      parentCtx.rebind(atom, memoryRef);
   
public static voidunbind(javax.naming.Context ctx, java.lang.String strName)


           
   
      Name name = ctx.getNameParser("").parse(strName);
      int size = name.size();
      String atom = name.get(size - 1);
      Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1));
      String key = parentCtx.getNameInNamespace() + "/" + atom;
      wrapperMap.remove(key);
      Util.unbind(ctx, strName);