List of usage examples for javax.naming NamingException NamingException
public NamingException(String explanation)
From source file:org.apache.naming.modules.java.ContextBindings.java
/** * Retrieves the naming context bound to a thread. *//*from w ww. ja v a2s.c o m*/ public static Context getThread() throws NamingException { Context context = (Context) threadBindings.get(Thread.currentThread()); log.info("Context=getThread: " + context); if (context == null) throw new NamingException(sm.getString("contextBindings.noContextBoundToThread")); return context; }
From source file:org.apache.naming.modules.java.ContextBindings.java
/** * Retrieves the naming context name bound to a thread. *///from ww w .j a v a 2s . c o m static Object getThreadName() throws NamingException { Object name = threadNameBindings.get(Thread.currentThread()); if (name == null) throw new NamingException(sm.getString("contextBindings.noContextBoundToThread")); return name; }
From source file:org.apache.naming.modules.java.ContextBindings.java
/** * Binds a naming context to a thread.//w ww. j av a 2 s. co m * * @param name Name of the context * @param token Security token */ public static void bindClassLoader(Object name, Object token, ClassLoader classLoader) throws NamingException { if (ContextAccessController.checkSecurityToken(name, token)) { Context context = (Context) contextNameBindings.get(name); if (context == null) throw new NamingException(sm.getString("contextBindings.unknownContext", name)); clBindings.put(classLoader, context); clNameBindings.put(classLoader, name); } }
From source file:org.apache.naming.modules.java.ContextBindings.java
/** * Retrieves the naming context bound to a class loader. *//*from ww w. ja v a 2 s . com*/ public static Context getClassLoader() throws NamingException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Context context = null; do { context = (Context) clBindings.get(cl); log.info("Context=getClassLoader: " + context + " " + cl); if (context != null) { return context; } } while ((cl = cl.getParent()) != null); throw new NamingException(sm.getString("contextBindings.noContextBoundToCL")); }
From source file:org.apache.naming.modules.java.ContextBindings.java
/** * Retrieves the naming context name bound to a class loader. *///from w w w .j a va2 s .c om static Object getClassLoaderName() throws NamingException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Object name = null; do { name = clNameBindings.get(cl); if (name != null) { return name; } } while ((cl = cl.getParent()) != null); throw new NamingException(sm.getString("contextBindings.noContextBoundToCL")); }
From source file:org.apache.naming.NamingContext.java
/** * Unbinds the named object. Removes the terminal atomic name in name * from the target context--that named by all but the terminal atomic * part of name./*w w w.j av a 2s . c o m*/ * <p> * This method is idempotent. It succeeds even if the terminal atomic * name is not bound in the target context, but throws * NameNotFoundException if any of the intermediate contexts do not exist. * * @param name the name to bind; may not be empty * @exception NameNotFoundException if an intermediate context does not * exist * @exception NamingException if a naming exception is encountered */ public void unbind(Name name) throws NamingException { checkWritable(); while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException(sm.getString("namingContext.invalidName")); NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0))); } if (name.size() > 1) { if (entry.type == NamingEntry.CONTEXT) { ((Context) entry.value).unbind(name.getSuffix(1)); } else { throw new NamingException(sm.getString("namingContext.contextExpected")); } } else { bindings.remove(name.get(0)); } }
From source file:org.apache.naming.NamingContext.java
/** * Enumerates the names bound in the named context, along with the class * names of objects bound to them. The contents of any subcontexts are * not included./* w w w . jav a2s. c o m*/ * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the names and class names of the bindings in * this context. Each element of the enumeration is of type NameClassPair. * @exception NamingException if a naming exception is encountered */ public NamingEnumeration list(Name name) throws NamingException { // Removing empty parts while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { return new NamingContextEnumeration(bindings.elements()); } NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0))); } if (entry.type != NamingEntry.CONTEXT) { throw new NamingException(sm.getString("namingContext.contextExpected")); } return ((Context) entry.value).list(name.getSuffix(1)); }
From source file:org.apache.naming.NamingContext.java
/** * Enumerates the names bound in the named context, along with the * objects bound to them. The contents of any subcontexts are not * included.//from w w w. j av a2 s. c o m * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the bindings in this context. * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ public NamingEnumeration listBindings(Name name) throws NamingException { // Removing empty parts while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { return new NamingContextBindingsEnumeration(bindings.elements()); } NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0))); } if (entry.type != NamingEntry.CONTEXT) { throw new NamingException(sm.getString("namingContext.contextExpected")); } return ((Context) entry.value).listBindings(name.getSuffix(1)); }
From source file:org.apache.naming.NamingContext.java
/** * Destroys the named context and removes it from the namespace. Any * attributes associated with the name are also removed. Intermediate * contexts are not destroyed./*from w ww . j av a2s . co m*/ * <p> * This method is idempotent. It succeeds even if the terminal atomic * name is not bound in the target context, but throws * NameNotFoundException if any of the intermediate contexts do not exist. * * In a federated naming system, a context from one naming system may be * bound to a name in another. One can subsequently look up and perform * operations on the foreign context using a composite name. However, an * attempt destroy the context using this composite name will fail with * NotContextException, because the foreign context is not a "subcontext" * of the context in which it is bound. Instead, use unbind() to remove * the binding of the foreign context. Destroying the foreign context * requires that the destroySubcontext() be performed on a context from * the foreign context's "native" naming system. * * @param name the name of the context to be destroyed; may not be empty * @exception NameNotFoundException if an intermediate context does not * exist * @exception NotContextException if the name is bound but does not name * a context, or does not name a context of the appropriate type */ public void destroySubcontext(Name name) throws NamingException { checkWritable(); while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException(sm.getString("namingContext.invalidName")); NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0))); } if (name.size() > 1) { if (entry.type == NamingEntry.CONTEXT) { ((Context) entry.value).unbind(name.getSuffix(1)); } else { throw new NamingException(sm.getString("namingContext.contextExpected")); } } else { if (entry.type == NamingEntry.CONTEXT) { ((Context) entry.value).close(); bindings.remove(name.get(0)); } else { throw new NotContextException(sm.getString("namingContext.contextExpected")); } } }
From source file:org.apache.naming.NamingContext.java
/** * Retrieves the named object./* w ww .j a va2 s . c om*/ * * @param name the name of the object to look up * @param resolveLinks If true, the links will be resolved * @return the object bound to name * @exception NamingException if a naming exception is encountered */ protected Object lookup(Name name, boolean resolveLinks) throws NamingException { // Removing empty parts while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) { // If name is empty, a newly allocated naming context is returned return new NamingContext(env, this.name, bindings); } NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0))); } if (name.size() > 1) { // If the size of the name is greater that 1, then we go through a // number of subcontexts. if (entry.type != NamingEntry.CONTEXT) { throw new NamingException(sm.getString("namingContext.contextExpected")); } return ((Context) entry.value).lookup(name.getSuffix(1)); } else { if ((resolveLinks) && (entry.type == NamingEntry.LINK_REF)) { String link = ((LinkRef) entry.value).getLinkName(); if (link.startsWith(".")) { // Link relative to this context return lookup(link.substring(1)); } else { return (new InitialContext(env)).lookup(link); } } else if (entry.type == NamingEntry.REFERENCE) { try { Object obj = NamingManager.getObjectInstance(entry.value, name, this, env); if (obj != null) { entry.value = obj; entry.type = NamingEntry.ENTRY; } return obj; } catch (NamingException e) { throw e; } catch (Exception e) { log.warn(sm.getString("namingContext.failResolvingReference"), e); throw new NamingException(e.getMessage()); } } else { return entry.value; } } }