Search in sources :

Example 21 with NotContextException

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

the class NamingContext method rebind.

/*------------------------------------------------*/
/**
     * Overwrite or create a binding
     *
     * @param name a <code>Name</code> value
     * @param obj an <code>Object</code> value
     * @exception NamingException if an error occurs
     */
public void rebind(Name name, Object obj) throws NamingException {
    if (isLocked())
        throw new NamingException("This context is immutable");
    Name cname = toCanonicalName(name);
    if (cname == null)
        throw new NamingException("Name is null");
    if (cname.size() == 0)
        throw new NamingException("Name is empty");
    //if no subcontexts, just bind it
    if (cname.size() == 1) {
        //check if it is a Referenceable
        Object objToBind = NamingManager.getStateToBind(obj, name, this, _env);
        if (objToBind instanceof Referenceable) {
            objToBind = ((Referenceable) objToBind).getReference();
        }
        removeBinding(cname);
        addBinding(cname, objToBind);
    } else {
        //walk down the subcontext hierarchy
        if (__log.isDebugEnabled())
            __log.debug("Checking for existing binding for name=" + cname + " for first element of name=" + cname.get(0));
        String firstComponent = cname.get(0);
        Object ctx = null;
        if (firstComponent.equals(""))
            ctx = this;
        else {
            Binding binding = getBinding(name.get(0));
            if (binding == null)
                throw new NameNotFoundException(name.get(0) + " is not bound");
            ctx = binding.getObject();
            if (ctx instanceof Reference) {
                //deference the object
                try {
                    ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
                } catch (NamingException e) {
                    throw e;
                } catch (Exception e) {
                    __log.warn("", e);
                    throw new NamingException(e.getMessage());
                }
            }
        }
        if (ctx instanceof Context) {
            ((Context) ctx).rebind(cname.getSuffix(1), obj);
        } else
            throw new NotContextException("Object bound at " + firstComponent + " is not a Context");
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NotContextException(javax.naming.NotContextException) Referenceable(javax.naming.Referenceable) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Example 22 with NotContextException

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

the class localContextRoot method lookup.

/**
     *
     *
     * @see javax.naming.Context#lookup(javax.naming.Name)
     */
public Object lookup(Name name) throws NamingException {
    synchronized (__root) {
        if (__log.isDebugEnabled())
            __log.debug("Looking up name=\"" + name + "\"");
        Name cname = __root.toCanonicalName(name);
        if ((cname == null) || (cname.size() == 0)) {
            __log.debug("Null or empty name, returning copy of this context");
            NamingContext ctx = new NamingContext(_env, null, null, __root.getNameParser(""));
            ctx.setBindings(__root.getBindings());
            return ctx;
        }
        if (cname.size() == 1) {
            Binding binding = __root.getBinding(cname);
            if (binding == null) {
                NameNotFoundException nnfe = new NameNotFoundException();
                nnfe.setRemainingName(cname);
                throw nnfe;
            }
            Object o = binding.getObject();
            //handle links by looking up the link
            if (o instanceof LinkRef) {
                //if link name starts with ./ it is relative to current context
                String linkName = ((LinkRef) o).getLinkName();
                if (linkName.startsWith("./"))
                    return lookup(linkName.substring(2));
                else {
                    //link name is absolute
                    InitialContext ictx = new InitialContext();
                    return ictx.lookup(linkName);
                }
            } else if (o instanceof Reference) {
                //deference the object
                try {
                    return NamingManager.getObjectInstance(o, cname, __root, _env);
                } catch (NamingException e) {
                    throw e;
                } catch (final Exception e) {
                    throw new NamingException(e.getMessage()) {

                        {
                            initCause(e);
                        }
                    };
                }
            } else
                return o;
        }
        //it is a multipart name, get the first subcontext
        String firstComponent = cname.get(0);
        Object ctx = null;
        if (firstComponent.equals(""))
            ctx = this;
        else {
            Binding binding = __root.getBinding(firstComponent);
            if (binding == null) {
                NameNotFoundException nnfe = new NameNotFoundException();
                nnfe.setRemainingName(cname);
                throw nnfe;
            }
            //as we have bound a reference to an object factory
            //for the component specific contexts
            //at "comp" we need to resolve the reference
            ctx = binding.getObject();
            if (ctx instanceof Reference) {
                //deference the object
                try {
                    ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env);
                } catch (NamingException e) {
                    throw e;
                } catch (Exception e) {
                    __log.warn("", e);
                    throw new NamingException(e.getMessage());
                }
            }
        }
        if (!(ctx instanceof Context))
            throw new NotContextException();
        return ((Context) ctx).lookup(cname.getSuffix(1));
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) NotContextException(javax.naming.NotContextException) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingContext(org.eclipse.jetty.jndi.NamingContext) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name) NamingException(javax.naming.NamingException) LinkRef(javax.naming.LinkRef)

Example 23 with NotContextException

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

the class CNCtx method destroySubcontext.

/**
     * Uses the callDestroy function to destroy the context. Destroys
     * the current context if name is empty.
     *
     * @param name JNDI Name
     * @throws javax.naming.OperationNotSupportedException when list is invoked
     *                                        with a non-null argument
     */
public void destroySubcontext(Name name) throws NamingException {
    if (_nc == null)
        throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString());
    NamingContext the_nc = _nc;
    NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name);
    if (name.size() > 0) {
        try {
            javax.naming.Context ctx = (javax.naming.Context) callResolve(path);
            CNCtx cnc = (CNCtx) ctx;
            the_nc = cnc._nc;
            //remove the reference to the context
            cnc.close();
        } catch (ClassCastException e) {
            throw new NotContextException(name.toString());
        } catch (CannotProceedException e) {
            javax.naming.Context cctx = getContinuationContext(e);
            cctx.destroySubcontext(e.getRemainingName());
            return;
        } catch (NameNotFoundException e) {
            if (e.getRootCause() instanceof NotFound && leafNotFound((NotFound) e.getRootCause(), path[path.length - 1])) {
                // leaf missing OK
                return;
            }
            throw e;
        } catch (NamingException e) {
            throw e;
        }
    }
    callDestroy(the_nc);
    callUnbind(path);
}
Also used : NamingContext(org.omg.CosNaming.NamingContext) NotContextException(javax.naming.NotContextException) NameComponent(org.omg.CosNaming.NameComponent) NameNotFoundException(javax.naming.NameNotFoundException) NamingContext(org.omg.CosNaming.NamingContext) CannotProceedException(javax.naming.CannotProceedException) NamingException(javax.naming.NamingException) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 24 with NotContextException

use of javax.naming.NotContextException in project geode by apache.

the class ContextImpl method listBindings.

/**
   * Lists all bindings for Context with name name. If name is empty then this Context is assumed.
   * 
   * @param name name of Context, relative to this Context
   * @return NamingEnumeration of all name-object pairs. Each element from the enumeration is
   *         instance of Binding.
   * @throws NoPermissionException if this context has been destroyed
   * @throws InvalidNameException if name is CompositeName that spans more than one naming system
   * @throws NameNotFoundException if name can not be found
   * @throws NotContextException component of name is not bound to instance of ContextImpl, when
   *         name is not an atomic name
   * @throws NamingException if any other naming error occurs
   * 
   */
public NamingEnumeration listBindings(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0) {
        Vector bindings = new Vector();
        Iterator iterat = ctxMaps.keySet().iterator();
        while (iterat.hasNext()) {
            String bindingName = (String) iterat.next();
            bindings.addElement(new Binding(bindingName, ctxMaps.get(bindingName)));
        }
        return new NamingEnumerationImpl(bindings);
    } else {
        Object subContext = ctxMaps.get(parsedName.get(0));
        if (subContext instanceof Context) {
            Name nextLayer = nameParser.parse("");
            // getSuffix(1) only apply to name with size() > 1
            if (parsedName.size() > 1) {
                nextLayer = parsedName.getSuffix(1);
            }
            return ((Context) subContext).list(nextLayer);
        }
        if (subContext == null && !ctxMaps.containsKey(parsedName.get(0))) {
            throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(name));
        } else {
            throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(subContext));
        }
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) NameNotFoundException(javax.naming.NameNotFoundException) Iterator(java.util.Iterator) Vector(java.util.Vector) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 25 with NotContextException

use of javax.naming.NotContextException in project geode by apache.

the class ContextImpl method lookup.

/**
   * Looks up object with binding name name in this context.
   * 
   * @param name name to look up
   * @return object reference bound to name name.
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is CompositeName that spans more than one naming system
   * @throws NameNotFoundException if name can not be found.
   * @throws NotContextException component of name is not bound to instance of ContextImpl, when
   *         name is not atomic name.
   * @throws NamingException if any other naming error occurs
   * 
   */
public Object lookup(Name name) throws NamingException {
    checkIsDestroyed();
    try {
        Name parsedName = getParsedName(name);
        String nameComponent = parsedName.get(0);
        Object res = ctxMaps.get(nameComponent);
        if (res instanceof UserTransactionImpl) {
            res = new UserTransactionImpl();
        }
        // if not found
        if (!ctxMaps.containsKey(nameComponent)) {
            throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(name));
        } else // if this is a compound name
        if (parsedName.size() > 1) {
            if (res instanceof ContextImpl) {
                res = ((ContextImpl) res).lookup(parsedName.getSuffix(1));
            } else {
                throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXTIMPL_BUT_FOUND_0.toLocalizedString(res));
            }
        }
        return res;
    } catch (NameNotFoundException e) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_LOOKING_UP_0, name, e);
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(new Object[] { name }));
    } catch (SystemException se) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.severeEnabled())
            writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT, se);
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT.toLocalizedString());
    }
}
Also used : NotContextException(javax.naming.NotContextException) SystemException(javax.transaction.SystemException) NameNotFoundException(javax.naming.NameNotFoundException) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

NotContextException (javax.naming.NotContextException)25 NameNotFoundException (javax.naming.NameNotFoundException)23 Name (javax.naming.Name)22 Context (javax.naming.Context)21 NamingException (javax.naming.NamingException)19 Binding (javax.naming.Binding)17 InitialContext (javax.naming.InitialContext)17 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)17 CompoundName (javax.naming.CompoundName)16 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 Reference (javax.naming.Reference)16 IOException (java.io.IOException)9 NamingContext (org.eclipse.jetty.jndi.NamingContext)8 CompositeName (javax.naming.CompositeName)6 InvalidNameException (javax.naming.InvalidNameException)4 Referenceable (javax.naming.Referenceable)4 CannotProceedException (javax.naming.CannotProceedException)2 LinkRef (javax.naming.LinkRef)2 NamingContext (org.omg.CosNaming.NamingContext)2 MalformedURLException (java.net.MalformedURLException)1