use of javax.naming.StringRefAddr in project activemq-artemis by apache.
the class JNDIReferenceFactory method getProperties.
public static Properties getProperties(Reference reference) {
Properties properties = new Properties();
for (Enumeration iter = reference.getAll(); iter.hasMoreElements(); ) {
StringRefAddr addr = (StringRefAddr) iter.nextElement();
properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent());
}
return properties;
}
use of javax.naming.StringRefAddr in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManagerFactory method getObjectInstance.
// TODO Provide hashCode to match equals
/**
* Create a PMF using the (JNDI) location or reference information specified.
* @param obj The object
* @param name Name of the object relative to the context
* @param ctx The context
* @param env properties used for creating the object
* @return The PMF instance
* @throws Exception If an error occurs generating the referenced object
*/
public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) throws Exception {
JDOPersistenceManagerFactory pmf = null;
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug("Creating PersistenceManagerFactory instance via JNDI with values " + "[object] " + (obj == null ? "" : obj.toString()) + " " + "[name] " + (name == null ? "" : name.toString()) + " " + "[context] " + (ctx == null ? "" : ctx.toString()) + " " + "[env] " + (env == null ? "" : env.toString()) + " ");
}
if (obj instanceof Reference) {
Reference ref = (Reference) obj;
if (ref.getClassName().equals(JDOClassNameConstants.JDOPersistenceManagerFactory) || ref.getClassName().equals(JDOClassNameConstants.JAVAX_JDO_PersistenceManagerFactory)) {
// Extract the properties to use for PMF creation
Properties p = new Properties();
for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) {
StringRefAddr sra = (StringRefAddr) e.nextElement();
p.setProperty(sra.getType(), (String) sra.getContent());
}
// Create the PMF
pmf = new JDOPersistenceManagerFactory(p);
// Freeze the PMF config now that we are handing out PM's : see JDO 1.0.1 [11.7]
pmf.freezeConfiguration();
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012006", name != null ? name.toString() : null));
}
} else {
NucleusLogger.PERSISTENCE.warn(Localiser.msg("012007", ref.getClassName(), JDOClassNameConstants.JDOPersistenceManagerFactory));
}
} else {
NucleusLogger.PERSISTENCE.warn(Localiser.msg("012008", (obj != null ? obj.getClass().getName() : null)));
}
return pmf;
}
use of javax.naming.StringRefAddr in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManagerFactory method getReference.
/**
* Retrieves the (JNDI) reference of this PMF object.
* @return The reference
*/
public Reference getReference() {
Reference rc = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
rc = new Reference(JDOClassNameConstants.JAVAX_JDO_PersistenceManagerFactory, JDOClassNameConstants.JDOPersistenceManagerFactory, null);
Map p = getConfiguration().getPersistenceProperties();
for (Iterator<Map.Entry> i = p.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = i.next();
String key = (String) entry.getKey();
Object valueObj = entry.getValue();
if (valueObj instanceof String) {
String value = (String) valueObj;
rc.add(new StringRefAddr(key, value));
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012009", key, value));
}
} else if (valueObj instanceof Long) {
String value = "" + valueObj;
rc.add(new StringRefAddr(key, value));
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012009", key, value));
}
} else if (valueObj instanceof Integer) {
String value = "" + valueObj;
rc.add(new StringRefAddr(key, value));
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012009", key, value));
}
} else if (valueObj instanceof Boolean) {
String value = (((Boolean) valueObj).booleanValue() ? "true" : "false");
rc.add(new StringRefAddr(key, value));
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012009", key, value));
}
} else {
NucleusLogger.PERSISTENCE.warn(Localiser.msg("012010", key));
}
}
if (p.isEmpty() && NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012011"));
}
} catch (IOException ex) {
NucleusLogger.PERSISTENCE.error(ex.getMessage());
throw new NucleusException(ex.getMessage(), ex);
}
return rc;
}
use of javax.naming.StringRefAddr in project sqlite-jna by gwenn.
the class BasicDataSource method getReference.
@Override
public Reference getReference() {
final Reference ref = new Reference(getClass().getName());
ref.add(new StringRefAddr("filename", filename));
return ref;
}
use of javax.naming.StringRefAddr in project mssql-jdbc by Microsoft.
the class SQLServerDataSource method initializeFromReference.
// Initialize this datasource from properties found inside the reference ref.
// Called by SQLServerDataSourceObjectFactory to initialize new DataSource instance.
void initializeFromReference(javax.naming.Reference ref) {
// Enumerate all the StringRefAddr objects in the Reference and assign properties appropriately.
Enumeration<?> e = ref.getAll();
while (e.hasMoreElements()) {
StringRefAddr addr = (StringRefAddr) e.nextElement();
String propertyName = addr.getType();
String propertyValue = (String) addr.getContent();
// Special case dataSourceURL and dataSourceDescription.
if ("dataSourceURL".equals(propertyName)) {
dataSourceURL = propertyValue;
} else if ("dataSourceDescription".equals(propertyName)) {
dataSourceDescription = propertyValue;
} else if ("trustStorePasswordStripped".equals(propertyName)) {
trustStorePasswordStripped = true;
} else // Just skip "class" StringRefAddr, it does not go into connectionProps
if (!"class".equals(propertyName)) {
connectionProps.setProperty(propertyName, propertyValue);
}
}
}
Aggregations