Search in sources :

Example 16 with Name

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

the class localContextRoot method lookupLink.

/**
     *
     *
     * @see javax.naming.Context#lookupLink(javax.naming.Name)
     */
public Object lookupLink(Name name) throws NamingException {
    synchronized (__root) {
        //return __root.lookupLink(getSuffix(name));
        Name cname = __root.toCanonicalName(name);
        if (cname == null) {
            //If no name create copy of this context with same bindings, but with copy of the environment so it can be modified
            NamingContext ctx = new NamingContext(_env, null, null, __root.getNameParser(""));
            ctx.setBindings(__root.getBindings());
            return ctx;
        }
        if (cname.size() == 0)
            throw new NamingException("Name is empty");
        if (cname.size() == 1) {
            Binding binding = __root.getBinding(cname);
            if (binding == null)
                throw new NameNotFoundException();
            Object o = binding.getObject();
            //handle links by looking up the link
            if (o instanceof Reference) {
                //deference the object
                try {
                    return NamingManager.getObjectInstance(o, cname.getPrefix(1), __root, _env);
                } catch (NamingException e) {
                    throw e;
                } catch (Exception e) {
                    __log.warn("", e);
                    throw new NamingException(e.getMessage());
                }
            } else {
                //or a plain object in which case spec says we return it
                return o;
            }
        }
        //it is a multipart name, recurse to 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)
                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).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) 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 Name

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

the class NamingContext method getNameInNamespace.

/*------------------------------------------------*/
/**
     * Get the full name of this Context node
     * by visiting it's ancestors back to root.
     *
     * NOTE: if this Context has a URL namespace then
     * the URL prefix will be missing
     *
     * @return the full name of this Context
     * @exception NamingException if an error occurs
     */
public String getNameInNamespace() throws NamingException {
    Name name = _parser.parse("");
    NamingContext c = this;
    while (c != null) {
        String str = c.getName();
        if (str != null)
            name.add(0, str);
        c = (NamingContext) c.getParent();
    }
    return name.toString();
}
Also used : CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Example 18 with Name

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

the class NamingContext method listBindings.

/*------------------------------------------------*/
/**
     * List all Bindings present at Context named by Name
     *
     * @param name a <code>Name</code> value
     * @return a <code>NamingEnumeration</code> value
     * @exception NamingException if an error occurs
     */
public NamingEnumeration listBindings(Name name) throws NamingException {
    Name cname = toCanonicalName(name);
    if (cname == null) {
        return new BindingEnumeration(__empty.iterator());
    }
    if (cname.size() == 0) {
        return new BindingEnumeration(_bindings.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 = 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), this, _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) 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 19 with Name

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

the class NamingContext method composeName.

/*------------------------------------------------*/
/** Join two names together. These are treated as
     * CompoundNames.
     *
     * @param name a <code>Name</code> value
     * @param prefix a <code>Name</code> value
     * @return a <code>Name</code> value
     * @exception NamingException if an error occurs
     */
public Name composeName(Name name, Name prefix) throws NamingException {
    if (name == null)
        throw new NamingException("Name cannot be null");
    if (prefix == null)
        throw new NamingException("Prefix cannot be null");
    Name compoundName = (CompoundName) prefix.clone();
    compoundName.addAll(name);
    return compoundName;
}
Also used : CompoundName(javax.naming.CompoundName) NamingException(javax.naming.NamingException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Example 20 with Name

use of javax.naming.Name in project hibernate-orm by hibernate.

the class JndiServiceImpl method bind.

@Override
public void bind(String jndiName, Object value) {
    final InitialContext initialContext = buildInitialContext();
    final Name name = parseName(jndiName, initialContext);
    try {
        bind(name, value, initialContext);
    } finally {
        cleanUp(initialContext);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Name(javax.naming.Name)

Aggregations

Name (javax.naming.Name)107 CompositeName (javax.naming.CompositeName)48 NamingException (javax.naming.NamingException)38 Context (javax.naming.Context)37 InitialContext (javax.naming.InitialContext)36 NameNotFoundException (javax.naming.NameNotFoundException)34 Test (org.junit.Test)32 Reference (javax.naming.Reference)24 NotContextException (javax.naming.NotContextException)22 Binding (javax.naming.Binding)19 CompoundName (javax.naming.CompoundName)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NameParser (javax.naming.NameParser)17 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 InvalidNameException (javax.naming.InvalidNameException)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)10 IOException (java.io.IOException)8 LinkRef (javax.naming.LinkRef)7 ServiceName (org.jboss.msc.service.ServiceName)7 Referenceable (javax.naming.Referenceable)6