List of usage examples for javax.naming NotContextException NotContextException
public NotContextException(String explanation)
From source file:com.dattack.naming.AbstractContext.java
@Override public NamingEnumeration<NameClassPair> list(final Name name) throws NamingException { ensureContextNotClosed();/*from w ww.j ava 2 s. c om*/ if (name == null || name.isEmpty()) { // list all elements final Map<Name, Object> enumStore = new HashMap<Name, Object>(); enumStore.putAll(objectTable); enumStore.putAll(subContexts); return new NameClassPairNamingEnumeration(enumStore); } final Name prefixName = name.getPrefix(1); if (objectTable.containsKey(prefixName)) { throw new NotContextException(String.format("%s cannot be listed", name)); } if (subContexts.containsKey(prefixName)) { return subContexts.get(prefixName).list(name.getSuffix(1)); } throw new NamingException(String.format("The context '%s' can't be found", name)); }
From source file:com.dattack.naming.AbstractContext.java
@Override public NamingEnumeration<Binding> listBindings(final Name name) throws NamingException { ensureContextNotClosed();// ww w . j ava 2 s. c o m if (name == null || name.isEmpty()) { final Map<Name, Object> enumStore = new HashMap<Name, Object>(); enumStore.putAll(objectTable); enumStore.putAll(subContexts); return new BindingNamingEnumeration(enumStore); } final Name subName = name.getPrefix(1); if (objectTable.containsKey(subName)) { throw new NotContextException(String.format("%s cannot be listed", name)); } if (subContexts.containsKey(subName)) { return subContexts.get(subName).listBindings(name.getSuffix(1)); } throw new NamingException(String.format("The named context '%s' can't be found", name)); }
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 www .ja v a 2 s. 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. * * 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 parser associated with the named context. In a * federation of namespaces, different naming systems will parse names * differently. This method allows an application to get a parser for * parsing names into their atomic components using the naming convention * of a particular naming system. Within any single naming system, * NameParser objects returned by this method must be equal (using the * equals() test).//from w w w .j a va2s.co m * * @param name the name of the context from which to get the parser * @return a name parser that can parse compound names into their atomic * components * @exception NamingException if a naming exception is encountered */ public NameParser getNameParser(Name name) throws NamingException { while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) return nameParser; if (name.size() > 1) { Object obj = bindings.get(name.get(0)); if (obj instanceof Context) { return ((Context) obj).getNameParser(name.getSuffix(1)); } else { throw new NotContextException(sm.getString("namingContext.contextExpected")); } } return nameParser; }