Package javax.naming

Examples of javax.naming.Name


    public NamingEnumeration list(String name) throws NamingException {
        return list(new CompositeName(name));
    }

    public NamingEnumeration listBindings(Name name) throws NamingException {
        Name searchName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the
        // parent
        if (searchName == null)
            return this.parent.list(name);
        // If empty name, return a copy of this Context
        else if (searchName.isEmpty()) {
            NamingEnumeration e = null;
            synchronized (this.contextLock) {
                e = new WinstoneBindingEnumeration(this.bindings,
                        this.environment, this);
            }
            return e;
        }

        // Lookup the object - if it's not a context, throw an error
        else {
            Object ctx = this.lookup(searchName);
            if (ctx instanceof Context)
                try {
                    return ((Context) ctx).listBindings(new CompositeName(""));
                } finally {
                    ((Context) ctx).close();
                }
            else if (ctx == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", searchName.toString()));
            else
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext",
                        new String[] { searchName.toString(),
                                ctx.getClass().getName() }));
        }
    }
View Full Code Here


        bind(name, value, false);
    }

    protected void bind(Name name, Object value, boolean allowOverwrites)
            throws NamingException {
        Name bindName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the
        // parent
        if (bindName == null)
            this.parent.bind(name, value, allowOverwrites);
        // If empty name, complain - we should have a child name here
        else if (bindName.isEmpty())
            throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                    "WinstoneContext.AlreadyExists", name.toString()));
        else if (bindName.size() > 1) {
            Object ctx = lookup(bindName.get(0));
            if (!(ctx instanceof Context))
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext", new String[] {
                                bindName.get(0), ctx.getClass().getName() }));
            else if (ctx == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", bindName.get(0)));
            else
                try {
                    if (allowOverwrites)
                        ((Context) ctx).rebind(bindName.getSuffix(1), value);
                    else
                        ((Context) ctx).bind(bindName.getSuffix(1), value);
                } finally {
                    ((Context) ctx).close();
                }
        } else if ((!allowOverwrites) && this.bindings.get(name.get(0)) != null)
            throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                    "WinstoneContext.AlreadyExists", name.toString()));
        else {
            value = NamingManager.getStateToBind(value, new CompositeName()
                    .add(bindName.get(0)), this, this.environment);
            synchronized (this.contextLock) {
                this.bindings.put(bindName.get(0), value);
            }
        }
    }
View Full Code Here

    public void unbind(String name) throws NamingException {
        unbind(new CompositeName(name));
    }

    public void unbind(Name name) throws NamingException {
        Name unbindName = validateName(name);

        // If null, it means we don't know how to handle this -> throw to the
        // parent
        if (unbindName == null)
            this.parent.unbind(name);
        // If empty name, complain - we should have a child name here
        else if (unbindName.isEmpty())
            throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES
                    .getString("WinstoneContext.CantUnbindEmptyName"));
        else if (unbindName.size() > 1) {
            Object ctx = lookup(unbindName.get(0));
            if (!(ctx instanceof Context))
                throw new NotContextException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NotContext", new String[] {
                                unbindName.get(0), ctx.getClass().getName() }));
            else if (ctx == null)
                throw new NameNotFoundException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                        "WinstoneContext.NameNotFound", unbindName.get(0)));
            else
                try {
                    ((Context) ctx).unbind(unbindName.getSuffix(1));
                } finally {
                    ((Context) ctx).close();
                }
        } else if (this.bindings.get(name.get(0)) == null)
            throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString(
                    "WinstoneContext.NameNotFound", name.toString()));
        else {
            synchronized (this.contextLock) {
                // Object removing = this.bindings.get(unbindName.get(0));
                this.bindings.remove(unbindName.get(0));
            }
        }
    }
View Full Code Here

     * @param prefix the name of this context relative to one of its ancestors
     * @return the composition of prefix and name
     * @throws NamingException if a naming exception is encountered
     */
    public Name composeName(final Name name, final Name prefix) throws NamingException {
        Name newPrefix = (Name) name.clone();
        return newPrefix.addAll(name);
    }
View Full Code Here

     * @throws NamingException if a naming exception is encountered
     */
    public Object lookup(final String name) throws NamingException {
        logger.debug("lookup {0}", name);

        Name n = new CompositeName(name);
        if (n.size() < 1) {
            // Empty name means this context
            logger.debug("Empty name");
            return this;
        }

        if (n.size() > 1) {
            // sub context in the env tree
            String suffix = n.getSuffix(1).toString();
            // should throw exception if sub context not found!
            Context subctx = lookupCtx(n.get(0));
            return subctx.lookup(suffix);
        }
        // leaf in the env tree
        Object ret = this.bindings.get(name);
        if (ret == null) {
View Full Code Here

     * @see javax.naming.NameAlreadyBoundException
     */
    public void bind(final String name, final Object obj) throws NamingException {
        logger.debug("bind {0}", name);

        Name n = new CompositeName(name);
        if (n.size() < 1) {
            logger.error("CompNamingContext bind empty name ?");

            throw new InvalidNameException("CompNamingContext cannot bind empty name");
        }

        if (n.size() == 1) {
            // leaf in the env tree
            if (this.bindings.get(name) != null) {
                logger.error("CompNamingContext: trying to overbind");
                throw new NameAlreadyBoundException("CompNamingContext: Use rebind to bind over a name");
            }
            this.bindings.put(name, obj);
        } else {
            // sub context in the env tree
            String suffix = n.getSuffix(1).toString();
            // must create the subcontext first if it does not exist yet.
            Context subctx;
            try {
                subctx = lookupCtx(n.get(0));
            } catch (NameNotFoundException e) {
                subctx = createSubcontext(n.get(0));
            }
            subctx.bind(suffix, obj);
        }
    }
View Full Code Here

     */
    public void rebind(final String name, final Object obj) throws NamingException {

        logger.debug("rebind {0}", name);

        Name n = new CompositeName(name);
        if (n.size() < 1) {
            logger.error("CompNamingContext rebind empty name ?");
            throw new InvalidNameException("CompNamingContext cannot rebind empty name");
        }

        if (n.size() == 1) {
            // leaf in the env tree
            this.bindings.put(name, obj);
        } else {
            // sub context in the env tree
            String suffix = n.getSuffix(1).toString();
            // must create the subcontext first if it does not exist yet.
            Context subctx;
            try {
                subctx = lookupCtx(n.get(0));
            } catch (NameNotFoundException e) {
                subctx = createSubcontext(n.get(0));
            }
            subctx.rebind(suffix, obj);
        }
    }
View Full Code Here

     */
    public void unbind(final String name) throws NamingException {

        logger.debug("unbind {0}", name);

        Name n = new CompositeName(name);
        if (n.size() < 1) {
            logger.error("CompNamingContext rebind empty name ?");
            throw new InvalidNameException("CompNamingContext cannot unbind empty name");
        }

        if (n.size() == 1) {
            // leaf in the env tree
            if (this.bindings.get(name) == null) {
                logger.error("CompNamingContext nothing to unbind");
                throw new NameNotFoundException(name);
            }
            this.bindings.remove(name);
        } else {
            // sub context in the env tree
            String suffix = n.getSuffix(1).toString();
            // should throw exception if sub context not found!
            Context subctx = lookupCtx(n.get(0));
            subctx.unbind(suffix);
        }
    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public Context createSubcontext(final String name) throws NamingException {
        logger.debug("createSubcontext {0}", name);

        Name n = new CompositeName(name);
        if (n.size() < 1) {
            logger.error("CompNamingContext createSubcontext with empty name ?");
            throw new InvalidNameException("CompNamingContext cannot create empty Subcontext");
        }

        Context ctx = null; // returned ctx
        if (n.size() == 1) {
            // leaf in the env tree: create ctx and bind it in parent.
            ctx = new ContextImpl(this.compId, this.environment);
            this.bindings.put(name, ctx);
        } else {
            // as for bind, we must create first all the subcontexts
            // if they don't exist yet.
            String suffix = n.getSuffix(1).toString();
            Context subctx;
            String newName = n.get(0);
            try {
                subctx = lookupCtx(newName);
            } catch (NameNotFoundException e) {
                subctx = createSubcontext(newName);
            }
View Full Code Here

   public void testNameChanges() throws Exception
   {
      getLog().debug("+++ testNameChanges");
      InitialContext ctx = getInitialContext();
      // JBAS-8540
      Name name = ctx.getNameParser("").parse("jnp://" + getServerHostForURL() + "/jmx");
      Name copy = (Name) name.clone();
      Object obj = ctx.lookup(name);
      getLog().debug("lookup("+name+") = "+obj);
      assertTrue("name.equals(copy), name="+name, name.equals(copy));
   }
View Full Code Here

TOP

Related Classes of javax.naming.Name

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.