use of javax.naming.NameNotFoundException in project kernel by exoplatform.
the class SimpleContext method rename.
/**
* {@inheritDoc}
*/
public void rename(String name1, String name2) throws NamingException {
if (name1.isEmpty() || name2.isEmpty()) {
throw new InvalidNameException("Cannot bind empty name");
}
Object value;
synchronized (getMutex()) {
Map<String, Object> tmpObjects = new HashMap<String, Object>(getBindings());
if (tmpObjects.containsKey(name2)) {
throw new NameAlreadyBoundException("An object has already been binded with the name '" + name2 + "'");
} else if ((value = tmpObjects.remove(name1)) == null) {
throw new NameNotFoundException("No object has been binded with the name '" + name1 + "'");
}
tmpObjects.put(name2, value);
setBindings(tmpObjects);
}
}
use of javax.naming.NameNotFoundException in project kernel by exoplatform.
the class InitialContextTest method testCompositeNameUsing.
public void testCompositeNameUsing() throws Exception {
Name name = new CompositeName("java:comp/env/jdbc/jcr");
Enumeration en = name.getAll();
while (en.hasMoreElements()) {
en.nextElement();
}
InitialContext ctx = new InitialContext();
ctx.bind(name, "foo");
assertEquals("foo", ctx.lookup(name));
try {
ctx.bind(name, "foo2");
fail("A NameAlreadyBoundException is expected here");
} catch (NameAlreadyBoundException e) {
// expected exception
}
assertEquals("foo", ctx.lookup(name));
assertEquals("foo", ctx.lookup("java:comp/env/jdbc/jcr"));
ctx.unbind(name);
try {
ctx.lookup(name);
fail("A NameNotFoundException is expected here");
} catch (NameNotFoundException e) {
// expected exception
}
}
use of javax.naming.NameNotFoundException in project Payara by payara.
the class NamingContext method unbind.
/**
* 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.
* <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(rb.getString(LogFacade.INVALID_NAME));
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(MessageFormat.format(rb.getString(LogFacade.NAME_NOT_BOUND), name.get(0)));
}
if (name.size() > 1) {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).unbind(name.getSuffix(1));
} else {
throw new NamingException(rb.getString(LogFacade.CONTEXT_EXPECTED));
}
} else {
bindings.remove(name.get(0));
}
}
use of javax.naming.NameNotFoundException in project Payara by payara.
the class NamingContext method destroySubcontext.
/**
* Destroys the named context and removes it from the namespace. Any
* attributes associated with the name are also removed. Intermediate
* contexts are not destroyed.
* <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(rb.getString(LogFacade.INVALID_NAME));
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(MessageFormat.format(rb.getString(LogFacade.NAME_NOT_BOUND), name.get(0)));
}
if (name.size() > 1) {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).destroySubcontext(name.getSuffix(1));
} else {
throw new NamingException(rb.getString(LogFacade.CONTEXT_EXPECTED));
}
} else {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).close();
bindings.remove(name.get(0));
} else {
throw new NotContextException(rb.getString(LogFacade.CONTEXT_EXPECTED));
}
}
}
use of javax.naming.NameNotFoundException in project Payara by payara.
the class NamingContext method bind.
/**
* 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
* @param rebind if true, then perform a rebind (ie, overwrite)
* @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
*/
protected void bind(Name name, Object obj, boolean rebind) throws NamingException {
checkWritable();
while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1);
if (name.isEmpty())
throw new NamingException(rb.getString(LogFacade.INVALID_NAME));
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (name.size() > 1) {
if (entry == null) {
throw new NameNotFoundException(MessageFormat.format(rb.getString(LogFacade.NAME_NOT_BOUND), name.get(0)));
}
if (entry.type == NamingEntry.CONTEXT) {
if (rebind) {
((Context) entry.value).rebind(name.getSuffix(1), obj);
} else {
((Context) entry.value).bind(name.getSuffix(1), obj);
}
} else {
throw new NamingException(rb.getString(LogFacade.CONTEXT_EXPECTED));
}
} else {
if ((!rebind) && (entry != null)) {
throw new NamingException(MessageFormat.format(rb.getString(LogFacade.ALREADY_BOUND), name.get(0)));
} else {
// Getting the type of the object and wrapping it within a new
// NamingEntry
Object toBind = NamingManager.getStateToBind(obj, name, this, env);
if (toBind instanceof Context) {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT);
} else if (toBind instanceof LinkRef) {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF);
} else if (toBind instanceof Reference) {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
} else if (toBind instanceof Referenceable) {
toBind = ((Referenceable) toBind).getReference();
entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
} else {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY);
}
bindings.put(name.get(0), entry);
}
}
}
Aggregations