use of org.apache.naming.ResourceEnvRef in project tomee by apache.
the class TomcatWebAppBuilder method createReference.
private static Reference createReference(final ResourceBase resource) {
final Reference ref;
if (resource instanceof ContextResource) {
final ContextResource cr = (ContextResource) resource;
ref = new ResourceRef(resource.getType(), resource.getDescription(), cr.getScope(), cr.getAuth(), cr.getSingleton());
} else {
ref = new ResourceEnvRef(resource.getType());
}
final Iterator<String> params = resource.listProperties();
while (params.hasNext()) {
final String paramName = params.next();
final String paramValue = (String) resource.getProperty(paramName);
final StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
return ref;
}
use of org.apache.naming.ResourceEnvRef in project tomcat by apache.
the class NamingContextListener method addResourceEnvRef.
/**
* Set the specified resources in the naming context.
*
* @param resourceEnvRef the resource reference
*/
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
Reference ref = lookForLookupRef(resourceEnvRef);
if (ref == null) {
// Create a reference to the resource env.
ref = new ResourceEnvRef(resourceEnvRef.getType());
// Adding the additional parameters, if any
Iterator<String> params = resourceEnvRef.listProperties();
while (params.hasNext()) {
String paramName = params.next();
String paramValue = (String) resourceEnvRef.getProperty(paramName);
StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
}
try {
if (log.isDebugEnabled()) {
log.debug(sm.getString("naming.addResourceEnvRef", resourceEnvRef.getName()));
}
createSubcontexts(envCtx, resourceEnvRef.getName());
envCtx.bind(resourceEnvRef.getName(), ref);
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
}
use of org.apache.naming.ResourceEnvRef in project Payara by payara.
the class ResourceEnvFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete a new Resource env instance.
*
* @param obj The reference object describing the DataSource
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof ResourceEnvRef) {
Reference ref = (Reference) obj;
ObjectFactory factory = null;
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
if (factoryRefAddr != null) {
// Using the specified factory
String factoryClassName = factoryRefAddr.getContent().toString();
// Loading factory
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Class<?> factoryClass = null;
if (tcl != null) {
try {
factoryClass = tcl.loadClass(factoryClassName);
} catch (ClassNotFoundException e) {
}
} else {
try {
factoryClass = Class.forName(factoryClassName);
} catch (ClassNotFoundException e) {
}
}
if (factoryClass != null) {
try {
factory = (ObjectFactory) factoryClass.newInstance();
} catch (Throwable t) {
}
}
}
// Note: No defaults here
if (factory != null) {
return factory.getObjectInstance(obj, name, nameCtx, environment);
} else {
throw new NamingException("Cannot create resource instance");
}
}
return null;
}
use of org.apache.naming.ResourceEnvRef in project tomcat70 by apache.
the class ResourceEnvFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Create a new Resource env instance.
*
* @param obj The reference object describing the DataSource
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof ResourceEnvRef) {
Reference ref = (Reference) obj;
ObjectFactory factory = null;
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
if (factoryRefAddr != null) {
// Using the specified factory
String factoryClassName = factoryRefAddr.getContent().toString();
// Loading factory
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Class<?> factoryClass = null;
if (tcl != null) {
try {
factoryClass = tcl.loadClass(factoryClassName);
} catch (ClassNotFoundException e) {
NamingException ex = new NamingException("Could not load resource factory class");
ex.initCause(e);
throw ex;
}
} else {
try {
factoryClass = Class.forName(factoryClassName);
} catch (ClassNotFoundException e) {
NamingException ex = new NamingException("Could not load resource factory class");
ex.initCause(e);
throw ex;
}
}
if (factoryClass != null) {
try {
factory = (ObjectFactory) factoryClass.newInstance();
} catch (Throwable t) {
if (t instanceof NamingException)
throw (NamingException) t;
NamingException ex = new NamingException("Could not create resource factory instance");
ex.initCause(t);
throw ex;
}
}
}
// Note: No defaults here
if (factory != null) {
return factory.getObjectInstance(obj, name, nameCtx, environment);
} else {
throw new NamingException("Cannot create resource instance");
}
}
return null;
}
use of org.apache.naming.ResourceEnvRef in project tomcat70 by apache.
the class NamingContextListener method addResourceEnvRef.
/**
* Set the specified resources in the naming context.
*/
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
// Create a reference to the resource env.
Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
// Adding the additional parameters, if any
Iterator<String> params = resourceEnvRef.listProperties();
while (params.hasNext()) {
String paramName = params.next();
String paramValue = (String) resourceEnvRef.getProperty(paramName);
StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
try {
if (logger.isDebugEnabled())
log.debug(" Adding resource env ref " + resourceEnvRef.getName());
createSubcontexts(envCtx, resourceEnvRef.getName());
envCtx.bind(resourceEnvRef.getName(), ref);
} catch (NamingException e) {
logger.error(sm.getString("naming.bindFailed", e));
}
}
Aggregations