Search in sources :

Example 6 with LinkRef

use of javax.naming.LinkRef in project camel by apache.

the class JndiContext method lookup.

public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object value = bindings.get(first);
                if (value == null) {
                    throw new NameNotFoundException(name);
                } else if (value instanceof Context && path.size() > 1) {
                    Context subContext = (Context) value;
                    value = subContext.lookup(path.getSuffix(1));
                }
                return value;
            }
        }
    }
    if (result instanceof Provider) {
        Provider provider = (Provider) result;
        result = provider.get();
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof JndiContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new JndiContext((JndiContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) Provider(com.google.inject.Provider) LinkRef(javax.naming.LinkRef)

Example 7 with LinkRef

use of javax.naming.LinkRef in project camel by apache.

the class JndiContext method lookup.

public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object value = bindings.get(first);
                if (value == null) {
                    throw new NameNotFoundException(name);
                } else if (value instanceof Context && path.size() > 1) {
                    Context subContext = (Context) value;
                    value = subContext.lookup(path.getSuffix(1));
                }
                return value;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof JndiContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new JndiContext((JndiContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) LinkRef(javax.naming.LinkRef)

Example 8 with LinkRef

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

the class AbstractContext method lookup.

// 
// Lookup
// 
public Object lookup(String name) throws NamingException {
    if (name == null)
        throw new NullPointerException("name is null");
    Object value = lookup(name, null);
    // if we got a link back we need to resolve it
    if (value instanceof LinkRef) {
        LinkRef linkRef = (LinkRef) value;
        value = lookup(linkRef.getLinkName());
    }
    return value;
}
Also used : LinkRef(javax.naming.LinkRef)

Example 9 with LinkRef

use of javax.naming.LinkRef in project mule by mulesoft.

the class DefaultSpringJndiContext method lookup.

public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object obj = bindings.get(first);
                if (obj == null) {
                    throw new NameNotFoundException(name);
                } else if (obj instanceof Context && path.size() > 1) {
                    Context subContext = (Context) obj;
                    obj = subContext.lookup(path.getSuffix(1));
                }
                return obj;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof DefaultSpringJndiContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new DefaultSpringJndiContext((DefaultSpringJndiContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) LinkRef(javax.naming.LinkRef)

Example 10 with LinkRef

use of javax.naming.LinkRef in project activemq-artemis by apache.

the class ReadOnlyContext method lookup.

@Override
public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object obj = bindings.get(first);
                if (obj == null) {
                    throw new NameNotFoundException(name);
                } else if (obj instanceof Context && path.size() > 1) {
                    Context subContext = (Context) obj;
                    obj = subContext.lookup(path.getSuffix(1));
                }
                return obj;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof ReadOnlyContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new ReadOnlyContext((ReadOnlyContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) LinkRef(javax.naming.LinkRef)

Aggregations

LinkRef (javax.naming.LinkRef)32 Context (javax.naming.Context)23 NamingException (javax.naming.NamingException)18 InitialContext (javax.naming.InitialContext)17 NameNotFoundException (javax.naming.NameNotFoundException)17 Reference (javax.naming.Reference)15 NotContextException (javax.naming.NotContextException)11 OperationNotSupportedException (javax.naming.OperationNotSupportedException)11 CompositeName (javax.naming.CompositeName)10 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)8 Name (javax.naming.Name)7 Referenceable (javax.naming.Referenceable)4 Test (org.junit.Test)4 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 Binding (javax.naming.Binding)2 CannotProceedException (javax.naming.CannotProceedException)2 CompoundName (javax.naming.CompoundName)2 Provider (com.google.inject.Provider)1 IOException (java.io.IOException)1