本文整理汇总了Java中org.apache.naming.ContextBindings.bindClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java ContextBindings.bindClassLoader方法的具体用法?Java ContextBindings.bindClassLoader怎么用?Java ContextBindings.bindClassLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.naming.ContextBindings
的用法示例。
在下文中一共展示了ContextBindings.bindClassLoader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupDataSource
import org.apache.naming.ContextBindings; //导入方法依赖的package包/类
public synchronized DataSource lookupDataSource(final Context context, String resourceName) throws NamingException {
if (context != null) {
ContextBindings.bindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
}
try {
String jndiName = resolveJndiName(resourceName, (context == null));
Object o = new InitialContext().lookup(jndiName);
if (o instanceof DataSource) {
return (DataSource) o;
} else {
return null;
}
} finally {
if (context != null) {
ContextBindings.unbindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
}
}
}
示例2: changeContextBinding
import org.apache.naming.ContextBindings; //导入方法依赖的package包/类
/**
* Change context binding.
*
* @param context the context
* @param bind the bind
* @throws NamingException the naming exception
*/
private void changeContextBinding(Context context, boolean bind) throws NamingException {
Object token = getNamingToken(context);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (bind) {
ContextBindings.bindClassLoader(context, token, loader);
} else {
ContextBindings.unbindClassLoader(context, token, loader);
}
}
示例3: getApplicationResources
import org.apache.naming.ContextBindings; //导入方法依赖的package包/类
public synchronized List getApplicationResources(Context context, ContainerWrapperBean containerWrapper) throws NamingException {
List resourceList = new ArrayList();
boolean contextAvailable = containerWrapper.getTomcatContainer().getAvailable(context);
if (contextAvailable) {
logger.info("Reading CONTEXT " + context.getName());
boolean contextBound = false;
try {
ContextBindings.bindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
contextBound = true;
} catch (NamingException e) {
logger.error("Cannot bind to context. useNaming=false ?");
logger.debug(" Stack trace:", e);
}
try {
containerWrapper.getTomcatContainer().addContextResource(context, resourceList, contextBound);
containerWrapper.getTomcatContainer().addContextResourceLink(context, resourceList, contextBound);
for (int i = 0 ; i < resourceList.size() ; i++) {
lookupResource((ApplicationResource) resourceList.get(i), contextBound, false);
}
} finally {
if (contextBound) {
ContextBindings.unbindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
}
}
}
return resourceList;
}
示例4: resetResource
import org.apache.naming.ContextBindings; //导入方法依赖的package包/类
public synchronized boolean resetResource(final Context context, String resourceName) throws NamingException {
if (context != null) {
ContextBindings.bindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
}
try {
String jndiName = resolveJndiName(resourceName, (context == null));
Object o = new InitialContext().lookup(jndiName);
try {
for (Iterator it = datasourceMappers.iterator(); it.hasNext();) {
DatasourceAccessor accessor = (DatasourceAccessor) it.next();
if (accessor.reset(o)) {
return true;
}
}
return false;
} catch (Throwable e) {
//
// make sure we always re-throw ThreadDeath
//
if (e instanceof ThreadDeath) {
throw (ThreadDeath) e;
}
return false;
}
} finally {
if (context != null) {
ContextBindings.unbindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
}
}
}