/** * Binds an object and a naming context. * * @param obj Object to bind with naming context * @param context Associated naming context instance */ public static void bindContext(Object obj, Context context) { bindContext(obj, context, null); }
/** * Binds a naming context to a thread. * * @param name Name of the context */ public static void bindThread(Object name) throws NamingException { bindThread(name, null); }
/** * Unbind context name. * * @param name Name of the context */ public static void unbindContext(Object name) { unbindContext(name, null); }
/** * 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); } }
/** * Get the bound context. */ protected Context getBoundContext() throws NamingException { if (initialContext) { String ICName = IC_PREFIX; if (ContextBindings.isThreadBound()) { ICName += ContextBindings.getThreadName(); } else if (ContextBindings.isClassLoaderBound()) { ICName += ContextBindings.getClassLoaderName(); } Context initialContext = ContextBindings.getContext(ICName); if (initialContext == null) { // Allocating a new context and binding it to the appropriate // name initialContext = new NamingContext(env, ICName); ContextBindings.bindContext(ICName, initialContext); } return initialContext; } else { if (ContextBindings.isThreadBound()) { return ContextBindings.getThread(); } else { return ContextBindings.getClassLoader(); } } }
ContextBindings.bindContext(container, namingContext, container); if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Bound " + container); ContextBindings.bindClassLoader (container, container, ((Container) container).getLoader().getClassLoader()); (namingContext); try { ContextBindings.bindClassLoader (container, container, this.getClass().getClassLoader()); ContextBindings.unbindContext(container, container); ContextBindings.unbindClassLoader (container, container, ((Container) container).getLoader().getClassLoader()); ContextBindings.unbindClassLoader (container, container, this.getClass().getClassLoader());
/** * Unbinds a naming context to a thread. * * @param name Name of the context */ public static void unbindThread(Object name) { unbindThread(name, null); }
public void contextExited(ThreadContext exitedContext, ThreadContext reenteredContext) { // unbind the new context ContextBindings.unbindThread(OPENEJB_CONTEXT); // attempt to restore the old context Data data = exitedContext.get(Data.class); if (data != null && data.oldContextName != null) { try { ContextBindings.bindThread(data.oldContextName); } catch (NamingException e) { } } }
public void contextEntered(ThreadContext oldContext, ThreadContext newContext) { // save off the old context if possible try { Data data = new Data(getThreadName()); newContext.set(Data.class, data); } catch (NamingException ignored) { } // set the new context try { ContextBindings.bindThread(OPENEJB_CONTEXT); } catch (NamingException e) { ContextBindings.unbindContext(OPENEJB_CONTEXT); throw new IllegalArgumentException("Unable to bind OpenEJB enc"); } }
ContextBindings.unbindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());
ContextBindings.bindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());
/** * 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 { StandardServer server = (StandardServer) ServerFactory.getServer(); context = server.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; }
/** * Get the bound context. */ protected Context getBoundContext() throws NamingException { if (initialContext) { String ICName = IC_PREFIX; if (ContextBindings.isThreadBound()) { ICName += ContextBindings.getThreadName(); } else if (ContextBindings.isClassLoaderBound()) { ICName += ContextBindings.getClassLoaderName(); } Context initialContext = ContextBindings.getContext(ICName); if (initialContext == null) { // Allocating a new context and binding it to the appropriate // name initialContext = new NamingContext(env, ICName); ContextBindings.bindContext(ICName, initialContext); } return initialContext; } else { if (ContextBindings.isThreadBound()) { return ContextBindings.getThread(); } else { return ContextBindings.getClassLoader(); } } }
ContextBindings.bindContext(container, namingContext, container); if( log.isDebugEnabled() ) { log.debug("Bound " + container ); ContextBindings.bindClassLoader (container, container, ((Container) container).getLoader().getClassLoader()); (namingContext); try { ContextBindings.bindClassLoader (container, container, this.getClass().getClassLoader()); ContextBindings.unbindContext(container, container); ContextBindings.unbindClassLoader (container, container, ((Container) container).getLoader().getClassLoader()); ContextBindings.unbindClassLoader (container, container, this.getClass().getClassLoader());
/** * Unbinds a naming context to a thread. * * @param name Name of the context */ public static void unbindThread(Object name) { unbindThread(name, null); }
/** * {@inheritDoc} */ public void contextExited(ThreadContext exitedContext, ThreadContext reenteredContext) { // unbind the new context ContextBindings.unbindThread(OPENEJB_CONTEXT); // attempt to restore the old context Data data = exitedContext.get(Data.class); if (data != null && data.oldContextName != null) { try { ContextBindings.bindThread(data.oldContextName); } catch (NamingException e) { logger.error("Exception in method contextExited", e); } } }
/** * {@inheritDoc} */ public void contextEntered(ThreadContext oldContext, ThreadContext newContext) { // save off the old context if possible try { Data data = new Data(getThreadName()); newContext.set(Data.class, data); } catch (NamingException ignored) { } // set the new context try { ContextBindings.bindThread(OPENEJB_CONTEXT); } catch (NamingException e) { ContextBindings.unbindContext(OPENEJB_CONTEXT); throw new IllegalArgumentException("Unable to bind OpenEJB enc"); } }
/** * Unbinds a naming context to a class loader. * * @param name Name of the context */ public static void unbindClassLoader(Object name) { unbindClassLoader(name, null); }
/** * Binds a naming context to a class loader. * * @param name Name of the context */ public static void bindClassLoader(Object name) throws NamingException { bindClassLoader(name, null); }
/** * 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; }