public static Properties getJndiProperties(Properties properties) {
HashSet specialProps = new HashSet();
specialProps.add(Environment.JNDI_CLASS);
specialProps.add(Environment.JNDI_URL);
Iterator iter = properties.keySet().iterator();
Properties result = new Properties();
while ( iter.hasNext() ) {
String prop = (String) iter.next();
if ( prop.indexOf(Environment.JNDI_PREFIX) > -1 && !specialProps.contains(prop) ) {
result.setProperty(
prop.substring( Environment.JNDI_PREFIX.length()+1 ),
properties.getProperty(prop)
);
}
}
String jndiClass = properties.getProperty(Environment.JNDI_CLASS);
String jndiURL = properties.getProperty(Environment.JNDI_URL);
// we want to be able to just use the defaults,
// if JNDI environment properties are not supplied
// so don't put null in anywhere
if (jndiClass != null) result.put(Context.INITIAL_CONTEXT_FACTORY, jndiClass);
if (jndiURL != null) result.put(Context.PROVIDER_URL, jndiURL);
return result;
}
Transform JNDI properties passed in the form hibernate.jndi.* to the
format accepted by InitialContext by triming the leading "hibernate.jndi". |