本文整理汇总了Java中org.apache.naming.ContextBindings类的典型用法代码示例。如果您正苦于以下问题:Java ContextBindings类的具体用法?Java ContextBindings怎么用?Java ContextBindings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextBindings类属于org.apache.naming包,在下文中一共展示了ContextBindings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindThread
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Bind current thread, both for CL purposes and for JNDI ENC support
* during : startup, shutdown and realoading of the context.
*
* @return the previous context class loader
*/
private ClassLoader bindThread() {
ClassLoader oldContextClassLoader =
Thread.currentThread().getContextClassLoader();
if (getResources() == null)
return oldContextClassLoader;
Thread.currentThread().setContextClassLoader
(getLoader().getClassLoader());
DirContextURLStreamHandler.bind(getResources());
if (isUseNaming()) {
try {
ContextBindings.bindThread(this, this);
} catch (NamingException e) {
// Silent catch, as this is a normal case during the early
// startup stages
}
}
return oldContextClassLoader;
}
示例2: bindThread
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Bind current thread, both for CL purposes and for JNDI ENC support during
* : startup, shutdown and realoading of the context.
*
* @return the previous context class loader
*/
protected ClassLoader bindThread() {
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
if (getResources() == null)
return oldContextClassLoader;
if (getLoader() != null && getLoader().getClassLoader() != null) {
Thread.currentThread().setContextClassLoader(getLoader().getClassLoader());
}
DirContextURLStreamHandler.bindThread(getResources());
if (isUseNaming()) {
try {
ContextBindings.bindThread(this, this);
} catch (NamingException e) {
// Silent catch, as this is a normal case during the early
// startup stages
}
}
return oldContextClassLoader;
}
示例3: open
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Open the specified database connection.
*
* @return Connection to the database
*/
protected Connection open() {
try {
Context context = null;
if (localDataSource) {
context = ContextBindings.getClassLoader();
context = (Context) context.lookup("comp/env");
} else {
context = getServer().getGlobalNamingContext();
}
DataSource dataSource = (DataSource)context.lookup(dataSourceName);
return dataSource.getConnection();
} catch (Exception e) {
// Log the problem for posterity
containerLog.error(sm.getString("dataSourceRealm.exception"), e);
}
return null;
}
示例4: 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());
}
}
}
示例5: contextEntered
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
// save off the old context if possible
try {
final Data data = new Data(getThreadName());
newContext.set(Data.class, data);
} catch (final NamingException ignored) {
// no-op
}
// set the new context
try {
ContextBindings.bindThread(OPENEJB_CONTEXT, null);
} catch (final NamingException e) {
ContextBindings.unbindContext(OPENEJB_CONTEXT, null);
throw new IllegalArgumentException("Unable to bind OpenEJB enc");
}
}
示例6: bindThread
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Bind current thread, both for CL purposes and for JNDI ENC support
* during : startup, shutdown and realoading of the context.
*
* @return the previous context class loader
*/
protected ClassLoader bindThread() {
ClassLoader oldContextClassLoader =
Thread.currentThread().getContextClassLoader();
if (getResources() == null)
return oldContextClassLoader;
if (getLoader() != null && getLoader().getClassLoader() != null) {
Thread.currentThread().setContextClassLoader
(getLoader().getClassLoader());
}
DirContextURLStreamHandler.bindThread(getResources());
if (isUseNaming()) {
try {
ContextBindings.bindThread(this, this);
} catch (NamingException e) {
// Silent catch, as this is a normal case during the early
// startup stages
}
}
return oldContextClassLoader;
}
示例7: unbindThread
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Unbind thread.
*/
protected void unbindThread(ClassLoader oldContextClassLoader) {
if (isUseNaming()) {
ContextBindings.unbindThread(this, this);
}
DirContextURLStreamHandler.unbindThread();
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
}
示例8: getObjectInstance
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Crete a new Context's instance.
*/
@SuppressWarnings("unchecked")
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws NamingException {
if ((ContextBindings.isThreadBound()) ||
(ContextBindings.isClassLoaderBound())) {
return new SelectorContext((Hashtable<String,Object>)environment);
}
return null;
}
示例9: bindThread
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Bind current thread, both for CL purposes and for JNDI ENC support
* during : startup, shutdown and realoading of the context.
*
* @return the previous context class loader
*/
private ClassLoader bindThread() {
ClassLoader oldContextClassLoader =
Thread.currentThread().getContextClassLoader();
if (getResources() == null)
return oldContextClassLoader;
if (getLoader().getClassLoader() != null) {
Thread.currentThread().setContextClassLoader
(getLoader().getClassLoader());
}
DirContextURLStreamHandler.bind(getResources());
if (isUseNaming()) {
try {
ContextBindings.bindThread(this, this);
} catch (NamingException e) {
// Silent catch, as this is a normal case during the early
// startup stages
}
}
return oldContextClassLoader;
}
示例10: getObjectInstance
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Crete a new Context's instance.
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable environment)
throws NamingException {
if ((ContextBindings.isThreadBound()) ||
(ContextBindings.isClassLoaderBound())) {
return new SelectorContext(environment);
} else {
return null;
}
}
示例11: unbindThread
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Unbind thread.
*/
protected void unbindThread(ClassLoader oldContextClassLoader) {
if (isUseNaming()) {
ContextBindings.unbindThread(this, this);
}
DirContextURLStreamHandler.unbindThread();
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
}
示例12: getObjectInstance
import org.apache.naming.ContextBindings; //导入依赖的package包/类
/**
* Crete a new Context's instance.
*/
@SuppressWarnings("unchecked")
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
throws NamingException {
if ((ContextBindings.isThreadBound()) || (ContextBindings.isClassLoaderBound())) {
return new SelectorContext((Hashtable<String, Object>) environment);
}
return null;
}
示例13: 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);
}
}
示例14: 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;
}
示例15: 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());
}
}
}