private MessageStore initialiseMessageStore(VirtualHostConfiguration hostConfig, VirtualHost virtualHost)
{
final Object storeTypeAttr = virtualHost.getAttribute(VirtualHost.STORE_TYPE);
String storeType = storeTypeAttr == null ? null : String.valueOf(storeTypeAttr);
MessageStore messageStore = null;
if (storeType == null)
{
try
{
final Class<?> clazz = Class.forName(hostConfig.getMessageStoreClass());
final Object o = clazz.newInstance();
if (!(o instanceof MessageStore))
{
throw new ClassCastException(clazz + " does not implement " + MessageStore.class);
}
messageStore = (MessageStore) o;
}
catch (ClassNotFoundException e)
{
throw new ServerScopedRuntimeException("Failed to fina virtual host message store implementation, " +
"check the classpath and the configuration", e);
}
catch (InstantiationException e)
{
throw new ServerScopedRuntimeException("Failed to initialise virtual host store, " +
"check the configuration", e);
}
catch (IllegalAccessException e)
{
throw new ServerScopedRuntimeException("Failed to initialise virtual host store, " +
"check the configuration", e);
}
}
else
{
messageStore = new MessageStoreCreator().createMessageStore(storeType);
}
final
MessageStoreLogSubject
storeLogSubject = new MessageStoreLogSubject(getName(), messageStore.getClass().getSimpleName());
OperationalLoggingListener.listen(messageStore, storeLogSubject, getEventLogger());
return messageStore;
}