use of javax.naming.StringRefAddr in project aries by apache.
the class ObjectFactoryTest method testURLReferenceWithNoMatchingHandler.
@Test
public void testURLReferenceWithNoMatchingHandler() throws Exception {
Reference ref = new Reference(null);
ref.add(new StringRefAddr("URL", "wibble"));
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertSame("The naming manager should have returned the reference object", ref, obj);
}
use of javax.naming.StringRefAddr in project tomcat by apache.
the class NamingContextListener method addResource.
/**
* Set the specified resources in the naming context.
*
* @param resource the resource descriptor
*/
public void addResource(ContextResource resource) {
Reference ref = lookForLookupRef(resource);
if (ref == null) {
// Create a reference to the resource.
ref = new ResourceRef(resource.getType(), resource.getDescription(), resource.getScope(), resource.getAuth(), resource.getSingleton());
// Adding the additional parameters, if any
Iterator<String> params = resource.listProperties();
while (params.hasNext()) {
String paramName = params.next();
String paramValue = (String) resource.getProperty(paramName);
StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
}
try {
if (log.isDebugEnabled()) {
log.debug(" Adding resource ref " + resource.getName() + " " + ref);
}
createSubcontexts(envCtx, resource.getName());
envCtx.bind(resource.getName(), ref);
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
if (("javax.sql.DataSource".equals(ref.getClassName()) || "javax.sql.XADataSource".equals(ref.getClassName())) && resource.getSingleton()) {
Object actualResource = null;
try {
ObjectName on = createObjectName(resource);
actualResource = envCtx.lookup(resource.getName());
Registry.getRegistry(null, null).registerComponent(actualResource, on, null);
objectNames.put(resource.getName(), on);
} catch (Exception e) {
log.warn(sm.getString("naming.jmxRegistrationFailed", e));
}
// further and cleans up and AutoCloseable DataSource by default.
if (actualResource instanceof AutoCloseable && !resource.getCloseMethodConfigured()) {
resource.setCloseMethod("close");
}
}
}
use of javax.naming.StringRefAddr in project tomcat by apache.
the class NamingContextListener method createNamingContext.
/**
* Create and initialize the JNDI naming context.
*/
private void createNamingContext() throws NamingException {
// Creating the comp subcontext
if (container instanceof Server) {
compCtx = namingContext;
envCtx = namingContext;
} else {
compCtx = namingContext.createSubcontext("comp");
envCtx = compCtx.createSubcontext("env");
}
int i;
if (log.isDebugEnabled()) {
log.debug("Creating JNDI naming context");
}
if (namingResources == null) {
namingResources = new NamingResourcesImpl();
namingResources.setContainer(container);
}
// Resource links
ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
for (i = 0; i < resourceLinks.length; i++) {
addResourceLink(resourceLinks[i]);
}
// Resources
ContextResource[] resources = namingResources.findResources();
for (i = 0; i < resources.length; i++) {
addResource(resources[i]);
}
// Resources Env
ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
for (i = 0; i < resourceEnvRefs.length; i++) {
addResourceEnvRef(resourceEnvRefs[i]);
}
// Environment entries
ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
for (i = 0; i < contextEnvironments.length; i++) {
addEnvironment(contextEnvironments[i]);
}
// EJB references
ContextEjb[] ejbs = namingResources.findEjbs();
for (i = 0; i < ejbs.length; i++) {
addEjb(ejbs[i]);
}
// Message Destination References
MessageDestinationRef[] mdrs = namingResources.findMessageDestinationRefs();
for (i = 0; i < mdrs.length; i++) {
addMessageDestinationRef(mdrs[i]);
}
// WebServices references
ContextService[] services = namingResources.findServices();
for (i = 0; i < services.length; i++) {
addService(services[i]);
}
// Binding a User Transaction reference
if (container instanceof Context) {
try {
Reference ref = new TransactionRef();
compCtx.bind("UserTransaction", ref);
ContextTransaction transaction = namingResources.getTransaction();
if (transaction != null) {
Iterator<String> params = transaction.listProperties();
while (params.hasNext()) {
String paramName = params.next();
String paramValue = (String) transaction.getProperty(paramName);
StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
}
} catch (NameAlreadyBoundException e) {
// Ignore because UserTransaction was obviously
// added via ResourceLink
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
}
// Binding the resources directory context
if (container instanceof Context) {
try {
compCtx.bind("Resources", ((Context) container).getResources());
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
}
}
use of javax.naming.StringRefAddr in project tomcat by apache.
the class NamingContextListener method addResourceLink.
/**
* Set the specified resource link in the naming context.
*
* @param resourceLink the resource link
*/
public void addResourceLink(ContextResourceLink resourceLink) {
// Create a reference to the resource.
Reference ref = new ResourceLinkRef(resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
Iterator<String> i = resourceLink.listProperties();
while (i.hasNext()) {
String key = i.next();
Object val = resourceLink.getProperty(key);
if (val != null) {
StringRefAddr refAddr = new StringRefAddr(key, val.toString());
ref.add(refAddr);
}
}
javax.naming.Context ctx = "UserTransaction".equals(resourceLink.getName()) ? compCtx : envCtx;
try {
if (log.isDebugEnabled()) {
log.debug(" Adding resource link " + resourceLink.getName());
}
createSubcontexts(envCtx, resourceLink.getName());
ctx.bind(resourceLink.getName(), ref);
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
ResourceLinkFactory.registerGlobalResourceAccess(getGlobalNamingContext(), resourceLink.getName(), resourceLink.getGlobal());
}
use of javax.naming.StringRefAddr in project tomcat by apache.
the class DriverAdapterCPDS method getReference.
/**
* Implements {@link Referenceable}.
*/
@Override
public Reference getReference() throws NamingException {
// this class implements its own factory
final String factory = getClass().getName();
final Reference ref = new Reference(getClass().getName(), factory, null);
ref.add(new StringRefAddr("description", getDescription()));
ref.add(new StringRefAddr("driver", getDriver()));
ref.add(new StringRefAddr("loginTimeout", String.valueOf(getLoginTimeout())));
ref.add(new StringRefAddr(Constants.KEY_PASSWORD, getPassword()));
ref.add(new StringRefAddr(Constants.KEY_USER, getUser()));
ref.add(new StringRefAddr("url", getUrl()));
ref.add(new StringRefAddr("poolPreparedStatements", String.valueOf(isPoolPreparedStatements())));
ref.add(new StringRefAddr("maxIdle", String.valueOf(getMaxIdle())));
ref.add(new StringRefAddr("numTestsPerEvictionRun", String.valueOf(getNumTestsPerEvictionRun())));
ref.add(new StringRefAddr("maxPreparedStatements", String.valueOf(getMaxPreparedStatements())));
//
// Pair of current and deprecated.
ref.add(new StringRefAddr("durationBetweenEvictionRuns", String.valueOf(getDurationBetweenEvictionRuns())));
ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis", String.valueOf(getTimeBetweenEvictionRunsMillis())));
//
// Pair of current and deprecated.
ref.add(new StringRefAddr("minEvictableIdleDuration", String.valueOf(getMinEvictableIdleDuration())));
ref.add(new StringRefAddr("minEvictableIdleTimeMillis", String.valueOf(getMinEvictableIdleTimeMillis())));
return ref;
}
Aggregations