Example usage for javax.naming.spi InitialContextFactory InitialContextFactory

List of usage examples for javax.naming.spi InitialContextFactory InitialContextFactory

Introduction

In this page you can find the example usage for javax.naming.spi InitialContextFactory InitialContextFactory.

Prototype

InitialContextFactory

Source Link

Usage

From source file:com.interface21.jndi.support.SimpleNamingContextBuilder.java

/**
 * Simple InitialContextFactoryBuilder implementation,
 * creating a new SimpleNamingContext instance.
 *//*w ww  .j  a  va 2 s.c om*/
public InitialContextFactory createInitialContextFactory(Hashtable environment) {
    return new InitialContextFactory() {
        public Context getInitialContext(Hashtable environment) {
            return new SimpleNamingContext("", boundObjects, environment);
        }
    };
}

From source file:io.pivotal.poc.gemfire.gtx.jndi.SimpleNamingContextBuilder.java

/**
 * Simple InitialContextFactoryBuilder implementation,
 * creating a new SimpleNamingContext instance.
 * @see SimpleNamingContext/*  ww w. j a v  a  2  s  .  co m*/
 */
@Override
public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) {
    if (activated == null && environment != null) {
        Object icf = environment.get(Context.INITIAL_CONTEXT_FACTORY);
        if (icf != null) {
            Class<?> icfClass;
            if (icf instanceof Class) {
                icfClass = (Class<?>) icf;
            } else if (icf instanceof String) {
                icfClass = ClassUtils.resolveClassName((String) icf, getClass().getClassLoader());
            } else {
                throw new IllegalArgumentException("Invalid value type for environment key ["
                        + Context.INITIAL_CONTEXT_FACTORY + "]: " + icf.getClass().getName());
            }
            if (!InitialContextFactory.class.isAssignableFrom(icfClass)) {
                throw new IllegalArgumentException("Specified class does not implement ["
                        + InitialContextFactory.class.getName() + "]: " + icf);
            }
            try {
                return (InitialContextFactory) icfClass.newInstance();
            } catch (Throwable ex) {
                throw new IllegalStateException("Cannot instantiate specified InitialContextFactory: " + icf,
                        ex);
            }
        }
    }

    // Default case...
    return new InitialContextFactory() {
        @Override
        @SuppressWarnings("unchecked")
        public Context getInitialContext(Hashtable<?, ?> environment) {
            return new SimpleNamingContext("", boundObjects, (Hashtable<String, Object>) environment);
        }
    };
}

From source file:de.micromata.genome.util.runtime.jndi.SimpleNamingContextBuilder.java

/**
 * Simple InitialContextFactoryBuilder implementation, creating a new SimpleNamingContext instance.
 * /* w w  w. ja  va  2  s .  c  om*/
 * @see SimpleNamingContext
 */
@Override
public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) {
    if (activated == null && environment != null) {
        Object icf = environment.get(Context.INITIAL_CONTEXT_FACTORY);
        if (icf != null) {
            Class<?> icfClass;
            if (icf instanceof Class) {
                icfClass = (Class<?>) icf;
            } else if (icf instanceof String) {
                icfClass = resolveClassName((String) icf, getClass().getClassLoader());
            } else {
                throw new IllegalArgumentException("Invalid value type for environment key ["
                        + Context.INITIAL_CONTEXT_FACTORY + "]: " + icf.getClass().getName());
            }
            if (!InitialContextFactory.class.isAssignableFrom(icfClass)) {
                throw new IllegalArgumentException("Specified class does not implement ["
                        + InitialContextFactory.class.getName() + "]: " + icf);
            }
            try {
                return (InitialContextFactory) icfClass.newInstance();
            } catch (Throwable ex) {
                throw new IllegalStateException("Cannot instantiate specified InitialContextFactory: " + icf,
                        ex);
            }
        }
    }

    // Default case...
    return new InitialContextFactory() {
        @Override
        @SuppressWarnings("unchecked")
        public Context getInitialContext(Hashtable<?, ?> environment) {
            return new SimpleNamingContext("", boundObjects, (Hashtable<String, Object>) environment);
        }
    };
}

From source file:org.rhq.enterprise.server.naming.AccessCheckingInitialContextFactoryBuilder.java

/**
 * @param defaultFactory the default factory to use if none can be deduced from the environment. If null, an attempt
 * is made to obtain the default InitialContextFactory of JBoss AS (which may fail depending on the classloading
 * "situation")./*from w w w . j a  v a  2 s .com*/
 * @param pretendNoFactoryBuilder true if the naming contexts should pretend as if there was no initial context
 * factory builder installed. This is to support environments as AS4, where there really was no builder initially
 * and the lookup relied on that fact.
 * 
 * @throws NamingException
 */
public AccessCheckingInitialContextFactoryBuilder(InitialContextFactory defaultFactory,
        final boolean pretendNoFactoryBuilder) throws NamingException {
    if (defaultFactory == null) {
        defaultFactory = getJbossDefaultInitialContextFactory();
    }

    defaultFactoryClassName = defaultFactory.getClass().getName();

    for (FactoryType ft : FactoryType.values()) {
        typeDefaults.put(ft, ft.wrap(defaultFactory));
    }

    this.pretendNoFactoryBuilder = pretendNoFactoryBuilder;

    this.defaultFactory = new InitialContextFactory() {
        public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
            return typeDefaults.get(FactoryType.detect(environment, pretendNoFactoryBuilder))
                    .getInitialContext(environment);
        }
    };
}

From source file:org.springframework.mock.jndi.SimpleNamingContextBuilder.java

/**
 * Simple InitialContextFactoryBuilder implementation,
 * creating a new SimpleNamingContext instance.
 * @see SimpleNamingContext//from w  w  w.ja  v  a 2  s.co m
 */
@Override
public InitialContextFactory createInitialContextFactory(@Nullable Hashtable<?, ?> environment) {
    if (activated == null && environment != null) {
        Object icf = environment.get(Context.INITIAL_CONTEXT_FACTORY);
        if (icf != null) {
            Class<?> icfClass;
            if (icf instanceof Class) {
                icfClass = (Class<?>) icf;
            } else if (icf instanceof String) {
                icfClass = ClassUtils.resolveClassName((String) icf, getClass().getClassLoader());
            } else {
                throw new IllegalArgumentException("Invalid value type for environment key ["
                        + Context.INITIAL_CONTEXT_FACTORY + "]: " + icf.getClass().getName());
            }
            if (!InitialContextFactory.class.isAssignableFrom(icfClass)) {
                throw new IllegalArgumentException("Specified class does not implement ["
                        + InitialContextFactory.class.getName() + "]: " + icf);
            }
            try {
                return (InitialContextFactory) ReflectionUtils.accessibleConstructor(icfClass).newInstance();
            } catch (Throwable ex) {
                throw new IllegalStateException("Unable to instantiate specified InitialContextFactory: " + icf,
                        ex);
            }
        }
    }

    // Default case...
    return new InitialContextFactory() {
        @Override
        @SuppressWarnings("unchecked")
        public Context getInitialContext(Hashtable<?, ?> environment) {
            return new SimpleNamingContext("", boundObjects, (Hashtable<String, Object>) environment);
        }
    };
}