/** * Creates and binds a new context. Creates a new context with the given * name and binds it in the target context (that named by all but * terminal atomic component of the name). All intermediate contexts and * the target context must already exist. * * @param name the name of the context to create; may not be empty * @return the newly created context * @exception NameAlreadyBoundException if name is already bound * @exception javax.naming.directory.InvalidAttributesException if creation * of the sub-context requires specification of mandatory attributes * @exception NamingException if a naming exception is encountered */ @Override public Context createSubcontext(Name name) throws NamingException { if (!checkWritable()) { return null; } NamingContext newContext = new NamingContext(env, this.name); bind(name, newContext); newContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite()); return newContext; }
/** * Builds a naming context using the given environment. */ public NamingContext(Hashtable<String,Object> env, String name, HashMap<String,NamingEntry> bindings) throws NamingException { this.env = new Hashtable<>(); // FIXME ? Could be put in the environment ? this.name = name; // Populating the environment hashtable if (env != null ) { Enumeration<String> envEntries = env.keys(); while (envEntries.hasMoreElements()) { String entryName = envEntries.nextElement(); addToEnvironment(entryName, env.get(entryName)); } } this.bindings = bindings; }
/** * Destroys the named context and removes it from the namespace. * * @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 */ @Override public void destroySubcontext(String name) throws NamingException { destroySubcontext(new CompositeName(name)); }
/** * Binds a new name to the object bound to an old name, and unbinds the * old name. Both names are relative to this context. Any attributes * associated with the old name become associated with the new name. * Intermediate contexts of the old name are not changed. * * @param oldName the name of the existing binding; may not be empty * @param newName the name of the new binding; may not be empty * @exception NameAlreadyBoundException if newName is already bound * @exception NamingException if a naming exception is encountered */ @Override public void rename(Name oldName, Name newName) throws NamingException { Object value = lookup(oldName); bind(newName, value); unbind(oldName); }
/** * Creates and binds a new context. Creates a new context with the given * name and binds it in the target context (that named by all but * terminal atomic component of the name). All intermediate contexts and * the target context must already exist. * * @param name the name of the context to create; may not be empty * @return the newly created context * @exception NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if creation of the subcontext * requires specification of mandatory attributes * @exception NamingException if a naming exception is encountered */ public Context createSubcontext(Name name) throws NamingException { checkWritable(); Context newContext = new NamingContext(env, this.name); bind(name, newContext); return newContext; }
/** * Creates and binds a new context. * * @param name the name of the context to create; may not be empty * @return the newly created context * @exception NameAlreadyBoundException if name is already bound * @exception javax.naming.directory.InvalidAttributesException if creation * of the sub-context requires specification of mandatory attributes * @exception NamingException if a naming exception is encountered */ @Override public Context createSubcontext(String name) throws NamingException { return createSubcontext(new CompositeName(name)); }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @exception NameAlreadyBoundException if name is already bound * @exception javax.naming.directory.InvalidAttributesException if object * did not supply all mandatory attributes * @exception NamingException if a naming exception is encountered */ @Override public void bind(Name name, Object obj) throws NamingException { bind(name, obj, false); }
/** * Throws a naming exception is Context is not writable. */ protected void checkWritable() throws NamingException { if (!isWritable()) throw new NamingException(sm.getString("namingContext.readOnly")); }
/** * Retrieves the parser associated with the named context. * * @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 */ @Override public NameParser getNameParser(String name) throws NamingException { return getNameParser(new CompositeName(name)); }
/** * Enumerates the names bound in the named context, along with the class * names of objects bound to them. * * @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 */ @Override public NamingEnumeration<NameClassPair> list(String name) throws NamingException { return list(new CompositeName(name)); }
/** * Enumerates the names bound in the named context, along with the * objects bound to them. * * @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(String name) throws NamingException { return listBindings(new CompositeName(name)); }
/** * Get a new (writable) initial context. */ public Context getInitialContext(Hashtable environment) throws NamingException { if (ContextBindings.isThreadBound() || (ContextBindings.isClassLoaderBound())) { // Redirect the request to the bound initial context return new SelectorContext(environment, true); } else { // If the thread is not bound, return a shared writable context if (initialContext == null) initialContext = new NamingContext(environment, MAIN); return initialContext; } }
/** * Closes this context. This method releases this context's resources * immediately, instead of waiting for them to be released automatically * by the garbage collector. * This method is idempotent: invoking it on a context that has already * been closed has no effect. Invoking any other method on a closed * context is not allowed, and results in undefined behaviour. * * @exception NamingException if a naming exception is encountered */ @Override public void close() throws NamingException { if (!checkWritable()) { return; } env.clear(); }
/** * Creates and binds a new context. Creates a new context with the given * name and binds it in the target context (that named by all but * terminal atomic component of the name). All intermediate contexts and * the target context must already exist. * * @param name the name of the context to create; may not be empty * @return the newly created context * @exception NameAlreadyBoundException if name is already bound * @exception javax.naming.directory.InvalidAttributesException if creation * of the sub-context requires specification of mandatory attributes * @exception NamingException if a naming exception is encountered */ @Override public Context createSubcontext(Name name) throws NamingException { checkWritable(); Context newContext = new NamingContext(env, this.name); bind(name, newContext); return newContext; }
/** * Creates and binds a new context. * * @param name the name of the context to create; may not be empty * @return the newly created context * @exception NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if creation of the subcontext * requires specification of mandatory attributes * @exception NamingException if a naming exception is encountered */ public Context createSubcontext(String name) throws NamingException { return createSubcontext(new CompositeName(name)); }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @exception NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if object did not supply all * mandatory attributes * @exception NamingException if a naming exception is encountered */ public void bind(Name name, Object obj) throws NamingException { bind(name, obj, false); }
/** * Throws a naming exception is Context is not writable. */ protected void checkWritable() throws NamingException { if (!isWritable()) throw new NamingException(sm.getString("namingContext.readOnly")); }
/** * Retrieves the parser associated with the named context. * * @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(String name) throws NamingException { return getNameParser(new CompositeName(name)); }
/** * Enumerates the names bound in the named context, along with the class * names of objects bound to them. * * @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(String name) throws NamingException { return list(new CompositeName(name)); }
/** * Enumerates the names bound in the named context, along with the * objects bound to them. * * @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 */ @Override public NamingEnumeration<Binding> listBindings(String name) throws NamingException { return listBindings(new CompositeName(name)); }