List of usage examples for org.springframework.mock.jndi SimpleNamingContextBuilder createInitialContextFactory
@Override @SuppressWarnings("unchecked") public InitialContextFactory createInitialContextFactory(@Nullable Hashtable<?, ?> environment)
From source file:org.codehaus.groovy.grails.cli.jndi.JndiBindingSupport.java
/** * Bindings a JNDI context.//from w ww. j av a 2 s . com * * @return The bound JNDI context */ @SuppressWarnings({ "unchecked", "rawtypes" }) Object bind() { SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); if (jndiConfig != null) { // ensure the commons-dbcp factory is used System.setProperty("javax.sql.DataSource.Factory", "org.apache.commons.dbcp.BasicDataSourceFactory"); for (Object o : jndiConfig.entrySet()) { Map.Entry entry = (Map.Entry) o; Object propsObj = entry.getValue(); final String entryName = entry.getKey().toString(); if (propsObj instanceof Map) { Map<String, Object> props = (Map) propsObj; Object typeObj = props.get(TYPE); if (typeObj != null) { props.remove(TYPE); String type = typeObj.toString(); JndiBindingHandler handler = jndiBinders.get(type); if (handler != null) { handler.handleBinding(builder, entryName, props); } else { try { Class<?> c = Class.forName(type, true, Thread.currentThread().getContextClassLoader()); Object beanObj = BeanUtils.instantiate(c); bindProperties(beanObj, props); builder.bind(entryName, beanObj); } catch (BeanInstantiationException e) { // ignore } catch (ClassNotFoundException e) { // ignore } } } } else { builder.bind(entryName, propsObj); } } } try { builder.activate(); return builder.createInitialContextFactory(null).getInitialContext(null); } catch (Exception e) { return null; } }