@Override
public Hermes createHermes(FactoryConfig factoryConfig) throws JAXBException, IOException, JMSException, NamingException, InstantiationException, ClassNotFoundException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Hermes hermes = null;
ConnectionFactoryManager connectionFactoryManager = null;
JNDIConnectionFactory jndiFactory = null;
if (factoryConfig.getExtension() == null) {
factoryConfig.setExtension(HermesBrowser.getConfigDAO().createDefaultProviderExtConfig(factoryConfig.getProvider().getClassName()));
}
ClassLoader classLoader = getClass().getClassLoader();
if (factoryConfig.getClasspathId() == null) {
factoryConfig.setClasspathId(SimpleClassLoaderManager.DEFAULT_LOADER);
}
classLoader = classLoaderManager.createClassLoader(factoryConfig.getClasspathId(), factoryConfig.getExtension());
Thread.currentThread().setContextClassLoader(classLoader);
connectionFactoryManager = new ConnectionFactoryManagerImpl(classLoaderManager, factoryConfig);
//
// You can now get the factory from the manager.
if (factoryConfig.getProvider().getClassName().equals(JNDIConnectionFactory.class.getName()) || factoryConfig.getProvider().getClassName().equals(JNDIQueueConnectionFactory.class.getName())
|| factoryConfig.getProvider().getClassName().equals(JNDITopicConnectionFactory.class.getName())) {
jndiFactory = (JNDIConnectionFactory) connectionFactoryManager.getConnectionFactory();
jndiFactory._setDelegateClassLoader(classLoader);
}
for (Iterator iter2 = factoryConfig.getDestination().iterator(); iter2.hasNext();) {
DestinationConfig destinationConfig = (DestinationConfig) iter2.next();
if (destinationConfig.isDurable() && destinationConfig.getClientID() == null) {
log.warn("removing durable subscription to " + destinationConfig.getName() + "with a null clientID");
iter2.remove();
} else {
connectionFactoryManager.addDestinationConfig(destinationConfig);
}
}
if (factoryConfig.getConnection().size() > 0) {
ConnectionConfig connectionConfig = factoryConfig.getConnection().get(0);
ConnectionManager connectionManager = null;
if (connectionConfig.isConnectionPerThread()) {
connectionManager = ConnectionManagerFactory.create(ConnectionManager.Policy.CONNECTION_PER_THREAD);
} else {
connectionManager = ConnectionManagerFactory.create(ConnectionManager.Policy.SHARED_CONNECTION);
}
connectionManager.setClientID(connectionConfig.getClientID());
connectionManager.setUsername(connectionConfig.getUsername());
connectionManager.setPassword(connectionConfig.getPassword());
if (connectionConfig.getSession().size() > 0) {
SessionManager sessionManager;
DestinationManager destinationManager;
SessionConfig sessionConfig = connectionConfig.getSession().get(0);
if (jndiFactory != null) {
jndiFactory._setDelegateClassLoader(classLoader);
destinationManager = new JNDIDestinationManager(jndiFactory._getProperties(), true);
sessionManager = new ThreadLocalSessionManager(sessionConfig, destinationManager);
} else {
destinationManager = new SimpleDestinationManager();
sessionManager = new ThreadLocalSessionManager(sessionConfig, destinationManager);
}
log.debug("SESSION IS " + sessionConfig.getId());
if (sessionConfig.getReconnects() != null) {
sessionManager.setReconnects(sessionConfig.getReconnects().intValue());
}
classLoaderManager.putClassLoaderByHermes(sessionConfig.getId(), classLoader);
factoryConfigById.put(sessionConfig.getId(), factoryConfig);
sessionManager.setTransacted(sessionConfig.isTransacted());
sessionManager.setId(sessionConfig.getId());
sessionManager.setFactoryConfig(factoryConfig);
sessionManager.setAudit(sessionConfig.isAudit());
sessionManager.setParent(connectionManager);
connectionManager.setParent(connectionFactoryManager);
if (config.getAuditDirectory() != null) {
sessionManager.setAuditDirectory(config.getAuditDirectory());
} else if (sessionConfig.getAuditDirectory() != null) {
sessionManager.setAuditDirectory(sessionConfig.getAuditDirectory());
}
connectionManager.addChild(sessionManager);
hermes = new DefaultHermesImpl(factoryConfig.getExtension(), sessionManager, classLoader);
connectionFactoryManager.addChild(connectionManager);
connectionManager.setHermes(hermes);
}
}
return hermes;