* .eve.config.Config, java.lang.String)
*/
@Override
public StateFactory getStateFactoryFromConfig(final Config config,
String configName) {
StateFactory result = null;
// get the class name from the config file
// first read from the environment specific configuration,
// if not found read from the global configuration
String className = config.get(configName, "class");
if (className == null) {
if (!configName.equals("state")) {
// Provide fallback to state if other type doesn't exist;
configName = "state";
className = config.get(configName, "class");
}
if (className == null) {
throw new IllegalArgumentException("Config parameter '"
+ config + ".class' missing in Eve configuration.");
}
}
try {
// get the class
final Class<?> stateClass = Class.forName(className);
if (!ClassUtil.hasInterface(stateClass, StateFactory.class)) {
throw new IllegalArgumentException("State factory class "
+ stateClass.getName() + " must extend "
+ State.class.getName());
}
// instantiate the state factory
final Map<String, Object> params = config.get(configName);
result = (StateFactory) stateClass.getConstructor(Map.class)
.newInstance(params);
LOG.info("Initialized state factory: " + result.toString());
} catch (final Exception e) {
LOG.log(Level.WARNING, "", e);
}
return result;
}