Search in sources :

Example 21 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project jetty.project by eclipse.

the class NamingContext method addBinding.

/*------------------------------------------------*/
/**
     * Add a name to object binding to this Context.
     *
     * @param name a <code>Name</code> value
     * @param obj an <code>Object</code> value
     * @throws NameAlreadyBoundException if name already bound
     */
public void addBinding(Name name, Object obj) throws NameAlreadyBoundException {
    String key = name.toString();
    Binding binding = new Binding(key, obj);
    Collection<Listener> list = findListeners();
    for (Listener listener : list) {
        binding = listener.bind(this, binding);
        if (binding == null)
            break;
    }
    if (__log.isDebugEnabled())
        __log.debug("Adding binding with key=" + key + " obj=" + obj + " for context=" + _name + " as " + binding);
    if (binding != null) {
        if (_bindings.containsKey(key)) {
            if (_supportDeepBinding) {
                // jndi users like openejb.
                return;
            }
            throw new NameAlreadyBoundException(name.toString());
        }
        _bindings.put(key, binding);
    }
}
Also used : Binding(javax.naming.Binding) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException)

Example 22 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project wildfly by wildfly.

the class ExceptionMapper method mapException.

public static NamingException mapException(Exception e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
    if (e instanceof NamingException) {
        return (NamingException) e;
    }
    if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
    }
    NamingException ne;
    if (e instanceof NotFound) {
        if (ctx.federation) {
            return tryFed((NotFound) e, ctx, inputName);
        } else {
            ne = new NameNotFoundException();
        }
    } else if (e instanceof CannotProceed) {
        ne = new CannotProceedException();
        NamingContext nc = ((CannotProceed) e).cxt;
        NameComponent[] rest = ((CannotProceed) e).rest_of_name;
        // NotFound doesn't set rest as expected. -RL
        if (inputName != null && (inputName.length > rest.length)) {
            NameComponent[] resolvedName = new NameComponent[inputName.length - rest.length];
            System.arraycopy(inputName, 0, resolvedName, 0, resolvedName.length);
            // Wrap resolved NamingContext inside a CNCtx
            // Guess that its name (which is relative to ctx)
            // is the part of inputName minus rest_of_name
            ne.setResolvedObj(new CNCtx(ctx._orb, nc, ctx._env, ctx.makeFullName(resolvedName)));
        } else {
            ne.setResolvedObj(ctx);
        }
        ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
    } else if (e instanceof InvalidName) {
        ne = new InvalidNameException();
    } else if (e instanceof AlreadyBound) {
        ne = new NameAlreadyBoundException();
    } else if (e instanceof NotEmpty) {
        ne = new ContextNotEmptyException();
    } else {
        ne = new NamingException();
    }
    ne.setRootCause(e);
    return ne;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CannotProceed(org.omg.CosNaming.NamingContextPackage.CannotProceed) NamingContext(org.omg.CosNaming.NamingContext) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InvalidName(org.omg.CosNaming.NamingContextPackage.InvalidName) InvalidNameException(javax.naming.InvalidNameException) CannotProceedException(javax.naming.CannotProceedException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) NamingException(javax.naming.NamingException) AlreadyBound(org.omg.CosNaming.NamingContextPackage.AlreadyBound) NotEmpty(org.omg.CosNaming.NamingContextPackage.NotEmpty) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 23 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project geronimo-xbean by apache.

the class AbstractContext method createSubcontext.

public Context createSubcontext(Name name) throws NamingException {
    if (!modifiable)
        throw new OperationNotSupportedException("Context is read only");
    if (name == null)
        throw new NullPointerException("name is null");
    if (name.isEmpty()) {
        throw new NameAlreadyBoundException("Cannot create a subcontext if the name is empty");
    }
    Context abstractContext = createNestedSubcontext(name.toString(), Collections.EMPTY_MAP);
    addDeepBinding(name, abstractContext, false, false);
    return abstractContext;
}
Also used : OperationNotSupportedException(javax.naming.OperationNotSupportedException) InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException)

Example 24 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project geronimo-xbean by apache.

the class AbstractContext method rename.

public void rename(Name oldName, Name newName) throws NamingException {
    if (!modifiable)
        throw new OperationNotSupportedException("Context is read only");
    if (oldName == null || newName == null) {
        throw new NullPointerException("name is null");
    } else if (oldName.isEmpty() || newName.isEmpty()) {
        throw new NameAlreadyBoundException("Name cannot be empty");
    }
    this.bind(newName, this.lookup(oldName));
    this.unbind(oldName);
}
Also used : OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException)

Example 25 with NameAlreadyBoundException

use of javax.naming.NameAlreadyBoundException in project geronimo-xbean by apache.

the class WritableContext method addBinding.

protected void addBinding(AtomicReference<Map<String, Object>> bindingsRef, String name, String nameInNamespace, Object value, boolean rebind) throws NamingException {
    if (supportReferenceable && value instanceof Referenceable) {
        Reference ref = ((Referenceable) value).getReference();
        if (ref != null) {
            if (checkDereferenceDifferent) {
                try {
                    Object o = NamingManager.getObjectInstance(ref, null, null, new Hashtable());
                    if (!value.equals(o)) {
                        value = ref;
                    }
                } catch (Exception e) {
                    if (!assumeDereferenceBound) {
                        value = ref;
                    }
                }
            } else {
                value = ref;
            }
        }
    }
    if (cacheReferences) {
        value = CachingReference.wrapReference(name, value, this);
    }
    writeLock.lock();
    try {
        Map<String, Object> bindings = bindingsRef.get();
        if (!rebind && bindings.containsKey(name)) {
            throw new NameAlreadyBoundException(name);
        }
        Map<String, Object> newBindings = new HashMap<String, Object>(bindings);
        newBindings.put(name, value);
        bindingsRef.set(newBindings);
        addToIndex(nameInNamespace, value);
    } finally {
        writeLock.unlock();
    }
}
Also used : NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) Referenceable(javax.naming.Referenceable) HashMap(java.util.HashMap) Reference(javax.naming.Reference) CachingReference(org.apache.xbean.naming.reference.CachingReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) Hashtable(java.util.Hashtable) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) ContextNotEmptyException(javax.naming.ContextNotEmptyException)

Aggregations

NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)33 InitialContext (javax.naming.InitialContext)17 Context (javax.naming.Context)16 NamingException (javax.naming.NamingException)15 NameNotFoundException (javax.naming.NameNotFoundException)12 Reference (javax.naming.Reference)8 File (java.io.File)6 OperationNotSupportedException (javax.naming.OperationNotSupportedException)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 BeanContext (org.apache.openejb.BeanContext)5 InvalidNameException (javax.naming.InvalidNameException)4 LinkRef (javax.naming.LinkRef)4 Name (javax.naming.Name)4 AppContext (org.apache.openejb.AppContext)4 Properties (java.util.Properties)3 CreationalContext (javax.enterprise.context.spi.CreationalContext)3 Referenceable (javax.naming.Referenceable)3 DataSource (javax.sql.DataSource)3 InvalidObjectException (java.io.InvalidObjectException)2