Java Code Examples for javax.naming.Context#INITIAL_CONTEXT_FACTORY
The following examples show how to use
javax.naming.Context#INITIAL_CONTEXT_FACTORY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InitialContextInfoTest.java From juddi with Apache License 2.0 | 6 votes |
@Test public void initialContextInfo_Java2XML() { try { List<Property> properties= new ArrayList<Property>(); Property property1 = new Property(Context.INITIAL_CONTEXT_FACTORY,"value1"); properties.add(property1); Property property2 = new Property(Context.PROVIDER_URL,"value2"); properties.add(property2); InitialContextInfo contextInfo = new InitialContextInfo(); contextInfo.setProperty(properties); JAXBContext jc = JAXBContext.newInstance(InitialContextInfo.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(contextInfo, System.out); } catch (JAXBException e) { e.printStackTrace(); fail("No exception should be thrown"); } }
Example 2
Source File: SimpleNamingContextBuilder.java From spring-analysis-note with MIT License | 5 votes |
/** * Simple InitialContextFactoryBuilder implementation, * creating a new SimpleNamingContext instance. * @see SimpleNamingContext */ @Override @SuppressWarnings("unchecked") 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 env -> new SimpleNamingContext("", this.boundObjects, (Hashtable<String, Object>) env); }
Example 3
Source File: SimpleNamingContextBuilder.java From spring-analysis-note with MIT License | 5 votes |
/** * Simple InitialContextFactoryBuilder implementation, * creating a new SimpleNamingContext instance. * @see SimpleNamingContext */ @Override @SuppressWarnings("unchecked") 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 env -> new SimpleNamingContext("", this.boundObjects, (Hashtable<String, Object>) env); }
Example 4
Source File: SimpleNamingContextBuilder.java From java-technology-stack with MIT License | 5 votes |
/** * Simple InitialContextFactoryBuilder implementation, * creating a new SimpleNamingContext instance. * @see SimpleNamingContext */ @Override @SuppressWarnings("unchecked") 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 env -> new SimpleNamingContext("", this.boundObjects, (Hashtable<String, Object>) env); }
Example 5
Source File: SimpleNamingContextBuilder.java From java-technology-stack with MIT License | 5 votes |
/** * Simple InitialContextFactoryBuilder implementation, * creating a new SimpleNamingContext instance. * @see SimpleNamingContext */ @Override @SuppressWarnings("unchecked") 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 env -> new SimpleNamingContext("", this.boundObjects, (Hashtable<String, Object>) env); }
Example 6
Source File: InitialContextFactoryImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Sets the InitialContextFactoryImpl as the initial context factory. This * helper method sets the Context.INITIAL_CONTEXT_FACTORY system properties. * The method also saves the current values of these properties so they can * be restored later on using revertSetAsInitial. This method can be called * from from setup. These properties can be set directly directly too or * through application resource file (jndi.properties). * java.naming.factory.initial=com.gemstone.gemfire.internal.jndi.InitialContextFactoryImpl * * @throws NamingException */ public void setAsInitial() throws NamingException { // Preserve current set system props String key = Context.INITIAL_CONTEXT_FACTORY; oldSystemProps.put(key, System.getProperty(key)); key = Context.URL_PKG_PREFIXES; oldSystemProps.put(key, System.getProperty(key)); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitialContextFactoryImpl.class.getName()); System.setProperty(Context.URL_PKG_PREFIXES, "com.gemstone.gemfire.internal.jndi"); }
Example 7
Source File: InitialContextFactoryImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Sets the InitialContextFactoryImpl as the initial context factory. This * helper method sets the Context.INITIAL_CONTEXT_FACTORY system properties. * The method also saves the current values of these properties so they can * be restored later on using revertSetAsInitial. This method can be called * from from setup. These properties can be set directly directly too or * through application resource file (jndi.properties). * java.naming.factory.initial=com.gemstone.gemfire.internal.jndi.InitialContextFactoryImpl * * @throws NamingException */ public void setAsInitial() throws NamingException { // Preserve current set system props String key = Context.INITIAL_CONTEXT_FACTORY; oldSystemProps.put(key, System.getProperty(key)); key = Context.URL_PKG_PREFIXES; oldSystemProps.put(key, System.getProperty(key)); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitialContextFactoryImpl.class.getName()); System.setProperty(Context.URL_PKG_PREFIXES, "com.gemstone.gemfire.internal.jndi"); }