2010-02-22 19:42:25 +01:00
|
|
|
package com.metaweb.gridworks.operations;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.browsing.Engine;
|
|
|
|
import com.metaweb.gridworks.model.AbstractOperation;
|
|
|
|
import com.metaweb.gridworks.model.Project;
|
|
|
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
|
|
|
|
2010-02-19 00:27:40 +01:00
|
|
|
abstract public class EngineDependentOperation extends AbstractOperation {
|
2010-02-05 07:29:27 +01:00
|
|
|
private static final long serialVersionUID = -2800091595856881731L;
|
|
|
|
|
|
|
|
final private String _engineConfigString;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
transient protected JSONObject _engineConfig;
|
|
|
|
|
|
|
|
protected EngineDependentOperation(JSONObject engineConfig) {
|
|
|
|
_engineConfig = engineConfig;
|
|
|
|
_engineConfigString = engineConfig.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Engine createEngine(Project project) throws Exception {
|
|
|
|
Engine engine = new Engine(project);
|
|
|
|
engine.initializeFromJSON(getEngineConfig());
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected JSONObject getEngineConfig() {
|
|
|
|
if (_engineConfig == null) {
|
|
|
|
try {
|
|
|
|
_engineConfig = ParsingUtilities.evaluateJsonStringToObject(_engineConfigString);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _engineConfig;
|
|
|
|
}
|
|
|
|
}
|