*/
@SuppressWarnings("unchecked")
@Override
public WebSocketEngine initializeEngine() {
WebSocketEngine newEngine = null;
EngineConfig engineConfig = mConfig.getEngines().get(0);
String jarFilePath = "-";
try {
Class lEngineClass = null;
// try to load engine from classpath first,
// could be located in server bundle
try {
lEngineClass = Class.forName(engineConfig.getName());
if (mLog.isDebugEnabled()) {
mLog.debug("Engine '" + engineConfig.getName() + "' loaded from classpath.");
}
} catch (ClassNotFoundException ex) {
// in case of a class not found exception we DO NOT want to
// show the exception but subsequently load the class from
if (mLog.isDebugEnabled()) {
mLog.debug("Engine '" + engineConfig.getName() + "' not yet in classpath, hence trying to load from file...");
}
}
// if not in classpath...
// try to load engine from given .jar file
if (lEngineClass == null) {
jarFilePath = JWebSocketConfig.getLibraryFolderPath(engineConfig.getJar());
// jarFilePath may be null if .jar is included in server bundle
if (jarFilePath != null) {
if (mLog.isDebugEnabled()) {
mLog.debug("Loading engine '" + engineConfig.getName() + "' from '" + jarFilePath + "'...");
}
mClassLoader.addFile(jarFilePath);
lEngineClass = (Class<WebSocketEngine>) mClassLoader.loadClass(engineConfig.getName());
}
}
// if class found
// try to create an instance
if (lEngineClass != null) {
Constructor<WebSocketEngine> ctor = lEngineClass.getDeclaredConstructor(EngineConfiguration.class);
ctor.setAccessible(true);
newEngine = ctor.newInstance(new Object[]{engineConfig});
if (mLog.isDebugEnabled()) {
mLog.debug("Engine '" + engineConfig.getId() + "' successfully instantiated.");
}
} else {
mLog.error("jWebSocket engine class " + engineConfig.getName() + " could not be loaded.");
}
} catch (MalformedURLException e) {
mLog.error("Couldn't load the jar file for engine, make sure jar file exists or name is correct", e);
} catch (ClassNotFoundException e) {
mLog.error("Engine class '" + engineConfig.getName() + "'@'" + jarFilePath + "' not found", e);
} catch (InstantiationException e) {
mLog.error("Engine class could not be instantiated", e);
} catch (IllegalAccessException e) {
mLog.error("Illegal Access Exception while intializing engine", e);
} catch (NoSuchMethodException e) {