use of javax.naming.Context in project jetty.project by eclipse.
the class Transaction method unbindENC.
/**
* Unbind this Transaction from a java:comp
*/
public void unbindENC() {
try {
InitialContext ic = new InitialContext();
Context env = (Context) ic.lookup("java:comp");
__log.debug("Unbinding java:comp/" + getJndiName());
env.unbind(getJndiName());
} catch (NamingException e) {
__log.warn(e);
}
}
use of javax.naming.Context in project jetty.project by eclipse.
the class EnvConfiguration method deconfigure.
/**
* Remove jndi setup from start
* @throws Exception if unable to deconfigure
*/
@Override
public void deconfigure(WebAppContext context) throws Exception {
//get rid of any bindings for comp/env for webapp
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
ContextFactory.associateClassLoader(context.getClassLoader());
try {
Context ic = new InitialContext();
Context compCtx = (Context) ic.lookup("java:comp");
compCtx.destroySubcontext("env");
//unbind any NamingEntries that were configured in this webapp's name space
@SuppressWarnings("unchecked") List<Bound> bindings = (List<Bound>) context.getAttribute(JETTY_ENV_BINDINGS);
context.setAttribute(JETTY_ENV_BINDINGS, null);
if (bindings != null) {
Collections.reverse(bindings);
for (Bound b : bindings) b._context.destroySubcontext(b._name);
}
} catch (NameNotFoundException e) {
LOG.warn(e);
} finally {
ContextFactory.disassociateClassLoader();
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
use of javax.naming.Context in project jetty.project by eclipse.
the class NamingEntry method unbindENC.
/**
* Unbind this NamingEntry from a java:comp/env
*/
public void unbindENC() {
try {
InitialContext ic = new InitialContext();
Context env = (Context) ic.lookup("java:comp/env");
__log.debug("Unbinding java:comp/env/" + getJndiName());
env.unbind(getJndiName());
} catch (NamingException e) {
__log.warn(e);
}
}
use of javax.naming.Context in project jetty.project by eclipse.
the class NamingEntryUtil method getContextForScope.
public static Context getContextForScope(Object scope) throws NamingException {
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name name = parser.parse("");
if (scope != null) {
name.add(canonicalizeScope(scope));
}
return (Context) ic.lookup(name);
}
use of javax.naming.Context in project jetty.project by eclipse.
the class NamingEntryUtil method lookupNamingEntries.
/**
* Get all NameEntries of a certain type in the given naming
* environment scope (server-wide names or context-specific names)
*
* @param scope the object scope
* @param clazz the type of the entry
* @return all NameEntries of a certain type in the given naming environment scope (server-wide names or context-specific names)
* @throws NamingException if unable to lookup the naming entries
*/
public static List<Object> lookupNamingEntries(Object scope, Class<?> clazz) throws NamingException {
try {
Context scopeContext = getContextForScope(scope);
Context namingEntriesContext = (Context) scopeContext.lookup(NamingEntry.__contextName);
ArrayList<Object> list = new ArrayList<Object>();
lookupNamingEntries(list, namingEntriesContext, clazz);
return list;
} catch (NameNotFoundException e) {
return Collections.emptyList();
}
}
Aggregations