@Test public void testGetObjectInstanceWithUnknownClassName() throws Exception { Reference reference = createTestReference(Object.class.getName(), "redundant", "redundant"); Object factory = referenceFactory.getObjectInstance(reference, mockName, mockContext, testEnvironment); assertNull("Expected null when given unknown class name", factory); }
@Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; }
JNDIReferenceFactory implements ObjectFactory { @Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; } }
JNDIReferenceFactory implements ObjectFactory { @Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; }  }
JNDIReferenceFactory implements ObjectFactory { @Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; }  @Override Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment); static Reference createReference(String instanceClassName, JNDIStorable po); static Class<?> loadClass(Object thisObj, String className); }
JNDIReferenceFactory implements ObjectFactory { @Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; }  @Override Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment); static Reference createReference(String instanceClassName, JNDIStorable po); static Class<?> loadClass(Object thisObj, String className);  }