use of javax.naming.StringRefAddr in project mssql-jdbc by Microsoft.
the class SQLServerDataSource method getReferenceInternal.
Reference getReferenceInternal(String dataSourceClassString) {
if (dsLogger.isLoggable(Level.FINER))
dsLogger.finer(toString() + " creating reference for " + dataSourceClassString + ".");
Reference ref = new Reference(this.getClass().getName(), "com.microsoft.sqlserver.jdbc.SQLServerDataSourceObjectFactory", null);
if (null != dataSourceClassString)
ref.add(new StringRefAddr("class", dataSourceClassString));
if (trustStorePasswordStripped)
ref.add(new StringRefAddr("trustStorePasswordStripped", "true"));
// Add each property name+value pair found in connectionProps.
Enumeration<?> e = connectionProps.keys();
while (e.hasMoreElements()) {
String propertyName = (String) e.nextElement();
// If a trustStore password is set, it is omitted and a trustStorePasswordSet flag is set.
if (propertyName.equals(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString())) {
// The property set and the variable set at the same time is not possible
assert trustStorePasswordStripped == false;
ref.add(new StringRefAddr("trustStorePasswordStripped", "true"));
} else {
// do not add passwords to the collection. we have normal password
if (!propertyName.contains(SQLServerDriverStringProperty.PASSWORD.toString()))
ref.add(new StringRefAddr(propertyName, connectionProps.getProperty(propertyName)));
}
}
// Add dataSourceURL and dataSourceDescription as these will not appear in connectionProps.
if (null != dataSourceURL)
ref.add(new StringRefAddr("dataSourceURL", dataSourceURL));
if (null != dataSourceDescription)
ref.add(new StringRefAddr("dataSourceDescription", dataSourceDescription));
return ref;
}
use of javax.naming.StringRefAddr in project h2database by h2database.
the class TestDataSource method testDataSourceFactory.
private void testDataSourceFactory() throws Exception {
ObjectFactory factory = new JdbcDataSourceFactory();
assertTrue(null == factory.getObjectInstance("test", null, null, null));
Reference ref = new Reference("java.lang.String");
assertTrue(null == factory.getObjectInstance(ref, null, null, null));
ref = new Reference(JdbcDataSource.class.getName());
ref.add(new StringRefAddr("url", "jdbc:h2:mem:"));
ref.add(new StringRefAddr("user", "u"));
ref.add(new StringRefAddr("password", "p"));
ref.add(new StringRefAddr("loginTimeout", "1"));
ref.add(new StringRefAddr("description", "test"));
JdbcDataSource ds = (JdbcDataSource) factory.getObjectInstance(ref, null, null, null);
assertEquals(1, ds.getLoginTimeout());
assertEquals("test", ds.getDescription());
assertEquals("jdbc:h2:mem:", ds.getURL());
assertEquals("u", ds.getUser());
assertEquals("p", ds.getPassword());
Reference ref2 = ds.getReference();
assertEquals(ref.size(), ref2.size());
assertEquals(ref.get("url").getContent().toString(), ref2.get("url").getContent().toString());
assertEquals(ref.get("user").getContent().toString(), ref2.get("user").getContent().toString());
assertEquals(ref.get("password").getContent().toString(), ref2.get("password").getContent().toString());
assertEquals(ref.get("loginTimeout").getContent().toString(), ref2.get("loginTimeout").getContent().toString());
assertEquals(ref.get("description").getContent().toString(), ref2.get("description").getContent().toString());
ds.setPasswordChars("abc".toCharArray());
assertEquals("abc", ds.getPassword());
}
use of javax.naming.StringRefAddr in project jackrabbit by apache.
the class RepositoryImpl method getReference.
// ------------------------------------------------------< Referenceable >---
/**
* @see Referenceable#getReference()
*/
public Reference getReference() throws NamingException {
if (config instanceof Referenceable) {
Referenceable confref = (Referenceable) config;
if (reference == null) {
reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
// carry over all addresses from referenceable config
for (Enumeration<RefAddr> en = confref.getReference().getAll(); en.hasMoreElements(); ) {
reference.add(en.nextElement());
}
// also add the information required by factory class
reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
}
return reference;
} else {
throw new javax.naming.OperationNotSupportedException("Contained RepositoryConfig needs to implement javax.naming.Referenceable");
}
}
use of javax.naming.StringRefAddr in project aries by apache.
the class ObjectFactoryTest method testURLReferenceUsingURLObjectFactoryFinder.
@Test
public void testURLReferenceUsingURLObjectFactoryFinder() throws Exception {
String testObject = "Test object";
URLObjectFactoryFinder factory = Skeleton.newMock(URLObjectFactoryFinder.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
bc.registerService(URLObjectFactoryFinder.class.getName(), factory, (Dictionary) new Properties());
Reference ref = new Reference(null);
ref.add(new StringRefAddr("URL", "wibble"));
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertEquals("The naming manager should have returned the test object", testObject, obj);
}
use of javax.naming.StringRefAddr in project aries by apache.
the class ObjectFactoryTest method testURLReferenceWithMatchingHandler.
@Test
public void testURLReferenceWithMatchingHandler() throws Exception {
String testObject = "Test object";
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
Properties props = new Properties();
props.setProperty("osgi.jndi.urlScheme", "wibble");
bc.registerService(ObjectFactory.class.getName(), factory, (Dictionary) props);
Reference ref = new Reference(null);
ref.add(new StringRefAddr("URL", "wibble"));
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertEquals("The naming manager should have returned the test object", testObject, obj);
}
Aggregations