// this allows us to use Camel's property replacement via ref:{{jndiName}} - actually (ref:%7B%7BjndiName%7D%7D)
camelContext = new DefaultCamelContext(new JndiRegistry(jndiContext));
// we need to disable JMX so we don't depend on Spring classes
camelContext.disableJMX();
// configure correct classloading
DefaultPackageScanClassResolver packageScanClassResolver = null;
if (isAS4) {
packageScanClassResolver = (DefaultPackageScanClassResolver) camelContext.getPackageScanClassResolver();
if (packageScanClassResolver == null) {
packageScanClassResolver = new DefaultPackageScanClassResolver();
camelContext.setPackageScanClassResolver(packageScanClassResolver);
}
} else if (isAS5) {
// JBossESB on AS5+ needs this to handle VFS classloading URIs.
// JBossESB on AS4 will not work if we use this.
packageScanClassResolver = new JBossPackageScanClassResolver();
camelContext.setPackageScanClassResolver(packageScanClassResolver);
} else if (isAS6) {
try {
Class c = Class.forName(AS6_CLASS_RESOLVER);
Constructor con = c.getConstructor();
packageScanClassResolver= (DefaultPackageScanClassResolver) con.newInstance();
camelContext.setPackageScanClassResolver(packageScanClassResolver);
} catch (InstantiationException e) {
throw new ManagedLifecycleException(e);
} catch (ClassNotFoundException e) {
throw new ManagedLifecycleException(e);
} catch (SecurityException e) {
throw new ManagedLifecycleException(e);
} catch (NoSuchMethodException e) {
throw new ManagedLifecycleException(e);
} catch (IllegalArgumentException e) {
throw new ManagedLifecycleException(e);
} catch (IllegalAccessException e) {
throw new ManagedLifecycleException(e);
} catch (InvocationTargetException e) {
throw new ManagedLifecycleException(e);
}
camelContext.setPackageScanClassResolver(packageScanClassResolver);
}
Set<ClassLoader> classLoaders = new HashSet<ClassLoader>();
classLoaders.add(Thread.currentThread().getContextClassLoader());
packageScanClassResolver.setClassLoaders(classLoaders);
// register JndiTypeConverters
Set<Class<?>> jndiTypes = new HashSet<Class<?>>();
jndiTypes.add(ConnectionFactory.class);
jndiTypes.add(DataSource.class);
// TODO: add classes from comma-separated config property for more jndiTypes that get looked up?