NonSerializableFactorypublic class NonSerializableFactory extends Object implements ObjectFactoryA 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 |
Fields Summary |
---|
private static Map | wrapperMap |
Methods Summary |
---|
public static void | bind(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.Object | getObjectInstance(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 void | rebind(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 void | unbind(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);
|
|