Search in sources :

Example 16 with NotContextException

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

the class localContextRoot method createSubcontext.

/**
     *
     *
     * @see javax.naming.Context#createSubcontext(javax.naming.Name)
     */
public Context createSubcontext(Name name) throws NamingException {
    synchronized (__root) {
        if (__root.isLocked()) {
            NamingException ne = new NamingException("This context is immutable");
            ne.setRemainingName(name);
            throw ne;
        }
        Name cname = __root.toCanonicalName(name);
        if (cname == null)
            throw new NamingException("Name is null");
        if (cname.size() == 0)
            throw new NamingException("Name is empty");
        if (cname.size() == 1) {
            //not permitted to bind if something already bound at that name
            Binding binding = __root.getBinding(cname);
            if (binding != null)
                throw new NameAlreadyBoundException(cname.toString());
            //make a new naming context with the root as the parent
            Context ctx = new NamingContext((Hashtable) _env.clone(), cname.get(0), __root, __root.getNameParser(""));
            __root.addBinding(cname, ctx);
            return ctx;
        }
        //If the name has multiple subcontexts, walk the hierarchy by
        //fetching the first one. All intermediate subcontexts in the
        //name must already exist.
        String firstComponent = cname.get(0);
        Object ctx = null;
        if (firstComponent.equals(""))
            ctx = this;
        else {
            Binding binding = __root.getBinding(firstComponent);
            if (binding == null)
                throw new NameNotFoundException(firstComponent + " is not bound");
            ctx = binding.getObject();
            if (ctx instanceof Reference) {
                //deference the object
                if (__log.isDebugEnabled())
                    __log.debug("Object bound at " + firstComponent + " is a Reference");
                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) {
            return ((Context) ctx).createSubcontext(cname.getSuffix(1));
        } else
            throw new NotContextException(firstComponent + " is not a Context");
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) NotContextException(javax.naming.NotContextException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) NamingContext(org.eclipse.jetty.jndi.NamingContext) 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)

Example 17 with NotContextException

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

the class localContextRoot method rebind.

/**
     *
     *
     * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
     */
public void rebind(Name name, Object obj) throws NamingException {
    synchronized (__root) {
        if (__root.isLocked())
            throw new NamingException("This context is immutable");
        Name cname = __root.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, __root, _env);
            if (objToBind instanceof Referenceable) {
                objToBind = ((Referenceable) objToBind).getReference();
            }
            __root.removeBinding(cname);
            __root.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 = __root.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), __root, _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) NamingContext(org.eclipse.jetty.jndi.NamingContext) 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) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Example 18 with NotContextException

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

the class localContextRoot method listBindings.

/**
     *
     *
     * @see javax.naming.Context#listBindings(javax.naming.Name)
     */
public NamingEnumeration listBindings(Name name) throws NamingException {
    synchronized (__root) {
        //return __root.listBindings(getSuffix(name));
        Name cname = __root.toCanonicalName(name);
        if (cname == null) {
            List<Binding> empty = Collections.emptyList();
            return new BindingEnumeration(empty.iterator());
        }
        if (cname.size() == 0) {
            return new BindingEnumeration(__root.getBindings().values().iterator());
        }
        //multipart name
        String firstComponent = cname.get(0);
        Object ctx = null;
        //at this level in the tree
        if (firstComponent.equals(""))
            ctx = this;
        else {
            //it is a non-empty name component
            Binding binding = __root.getBinding(firstComponent);
            if (binding == null)
                throw new NameNotFoundException();
            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).listBindings(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) NamingException(javax.naming.NamingException) 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) BindingEnumeration(org.eclipse.jetty.jndi.BindingEnumeration)

Example 19 with NotContextException

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

the class NamingContext method unbind.

/*------------------------------------------------*/
/**
     * Not supported.
     *
     * @param name a <code>String</code> value
     * @exception NamingException if an error occurs
     */
public void unbind(Name name) throws NamingException {
    if (name.size() == 0)
        return;
    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 unbind it
    if (cname.size() == 1) {
        removeBinding(cname);
    } 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).unbind(cname.getSuffix(1));
        } 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) 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 20 with NotContextException

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

the class NamingContext method bind.

/*------------------------------------------------*/
/**
     * Bind a name to an object
     *
     * @param name Name of the object
     * @param obj object to bind
     * @exception NamingException if an error occurs
     */
public void bind(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) {
        //get the object to be bound
        Object objToBind = NamingManager.getStateToBind(obj, name, this, _env);
        // Check for Referenceable
        if (objToBind instanceof Referenceable) {
            objToBind = ((Referenceable) objToBind).getReference();
        }
        //anything else we should be able to bind directly
        addBinding(cname, objToBind);
    } else {
        if (__log.isDebugEnabled())
            __log.debug("Checking for existing binding for name=" + cname + " for first element of name=" + cname.get(0));
        //walk down the subcontext hierarchy
        //need to ignore trailing empty "" name components
        String firstComponent = cname.get(0);
        Object ctx = null;
        if (firstComponent.equals(""))
            ctx = this;
        else {
            Binding binding = getBinding(firstComponent);
            if (binding == null) {
                if (_supportDeepBinding) {
                    Name subname = _parser.parse(firstComponent);
                    Context subctx = new NamingContext((Hashtable) _env.clone(), firstComponent, this, _parser);
                    addBinding(subname, subctx);
                    binding = getBinding(subname);
                } else {
                    throw new NameNotFoundException(firstComponent + " 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).bind(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)

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