use of javax.naming.Reference in project jaybird by FirebirdSQL.
the class TestDataSourceFactory method testBuildFBXADataSource_nonStandardProperties.
/**
* Tests reconstruction of a {@link FBXADataSource} using a reference.
* <p>
* This test is done with a selection of properties set through the {@link FBXADataSource#setNonStandardProperty(String)} methods. It tests
* <ol>
* <li>If the reference returned has the right factory name</li>
* <li>If the reference returned has the right classname</li>
* <li>If the object returned by the factory is a distinct new instance</li>
* <li>If all the properties set on the original are also set on the new instance</li>
* <li>If an unset property is handled correctly</li>
* </ol>
* </p>
* @throws Exception
*/
@Test
public void testBuildFBXADataSource_nonStandardProperties() throws Exception {
final FBXADataSource originalDS = new FBXADataSource();
// note number of buffers is apparently byte, so using higher values can give weird results
originalDS.setNonStandardProperty("buffersNumber=127");
originalDS.setNonStandardProperty("defaultTransactionIsolation", Integer.toString(Connection.TRANSACTION_SERIALIZABLE));
originalDS.setNonStandardProperty("madeUpProperty", "madeUpValue");
Reference ref = originalDS.getReference();
FBXADataSource newDS = (FBXADataSource) new DataSourceFactory().getObjectInstance(ref, null, null, null);
assertEquals("127", newDS.getNonStandardProperty("buffersNumber"));
assertEquals(Integer.toString(Connection.TRANSACTION_SERIALIZABLE), newDS.getNonStandardProperty("defaultTransactionIsolation"));
assertEquals("madeUpValue", newDS.getNonStandardProperty("madeUpProperty"));
assertNull(newDS.getDescription());
}
use of javax.naming.Reference in project jaybird by FirebirdSQL.
the class TestDataSourceFactory method testBuildFBConnectionPoolDataSource_basicProperties.
/**
* Tests reconstruction of a {@link FBConnectionPoolDataSource} using a reference.
* <p>
* This test is done with the basic properties exposed through setters. It tests
* <ol>
* <li>If the reference returned has the right factory name</li>
* <li>If the reference returned has the right classname</li>
* <li>If the object returned by the factory is a distinct new instance</li>
* <li>If all the properties set on the original are also set on the new instance</li>
* </ol>
* </p>
* @throws Exception
*/
@Test
public void testBuildFBConnectionPoolDataSource_basicProperties() throws Exception {
final FBConnectionPoolDataSource originalDS = new FBConnectionPoolDataSource();
fillFBAbstractCommonDataSourceProperties(originalDS);
Reference ref = originalDS.getReference();
assertEquals("Unexpected factory name", DataSourceFactory.class.getName(), ref.getFactoryClassName());
assertEquals("Unexpected class name", FBConnectionPoolDataSource.class.getName(), ref.getClassName());
FBConnectionPoolDataSource newDS = (FBConnectionPoolDataSource) new DataSourceFactory().getObjectInstance(ref, null, null, null);
assertNotSame("Expected distinct new object", originalDS, newDS);
assertFBAbstractCommonDataSourceProperties(newDS);
}
use of javax.naming.Reference in project activemq-artemis by apache.
the class ActiveMQRAConnectionFactoryObjectFactory method getObjectInstance.
@Override
public Object getObjectInstance(final Object ref, final Name name, final Context ctx, final Hashtable<?, ?> props) throws Exception {
Reference r = (Reference) ref;
byte[] bytes = (byte[]) r.get("ActiveMQ-CF").getContent();
// Deserialize
return SerializableObjectRefAddr.deserialize(bytes);
}
use of javax.naming.Reference in project activemq-artemis by apache.
the class ReadOnlyContext method lookup.
@Override
public Object lookup(String name) throws NamingException {
if (name.length() == 0) {
return this;
}
Object result = treeBindings.get(name);
if (result == null) {
result = bindings.get(name);
}
if (result == null) {
int pos = name.indexOf(':');
if (pos > 0) {
String scheme = name.substring(0, pos);
Context ctx = NamingManager.getURLContext(scheme, environment);
if (ctx == null) {
throw new NamingException("scheme " + scheme + " not recognized");
}
return ctx.lookup(name);
} else {
// Split out the first name of the path
// and look for it in the bindings map.
CompositeName path = new CompositeName(name);
if (path.size() == 0) {
return this;
} else {
String first = path.get(0);
Object obj = bindings.get(first);
if (obj == null) {
throw new NameNotFoundException(name);
} else if (obj instanceof Context && path.size() > 1) {
Context subContext = (Context) obj;
obj = subContext.lookup(path.getSuffix(1));
}
return obj;
}
}
}
if (result instanceof LinkRef) {
LinkRef ref = (LinkRef) result;
result = lookup(ref.getLinkName());
}
if (result instanceof Reference) {
try {
result = NamingManager.getObjectInstance(result, null, null, this.environment);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
}
}
if (result instanceof ReadOnlyContext) {
String prefix = getNameInNamespace();
if (prefix.length() > 0) {
prefix = prefix + SEPARATOR;
}
result = new ReadOnlyContext((ReadOnlyContext) result, environment, prefix + name);
}
return result;
}
use of javax.naming.Reference in project activemq-artemis by apache.
the class JNDIReferenceFactory method createReference.
/**
* Create a Reference instance from a JNDIStorable object
*
* @param instanceClassName
* The name of the class that is being created.
* @param po
* The properties object to use when configuring the new instance.
*
* @return Reference
*
* @throws NamingException if an error occurs while creating the new instance.
*/
public static Reference createReference(String instanceClassName, JNDIStorable po) throws NamingException {
Reference result = new Reference(instanceClassName, JNDIReferenceFactory.class.getName(), null);
try {
Properties props = po.getProperties();
for (Enumeration iter = props.propertyNames(); iter.hasMoreElements(); ) {
String key = (String) iter.nextElement();
result.add(new StringRefAddr(key, props.getProperty(key)));
}
} catch (Exception e) {
throw new NamingException(e.getMessage());
}
return result;
}
Aggregations