2010-02-22 19:42:25 +01:00
|
|
|
package com.metaweb.gridworks.operations;
|
2010-02-22 05:23:25 +01:00
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
import java.lang.reflect.Method;
|
2010-02-22 05:23:25 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2010-02-22 05:23:25 +01:00
|
|
|
import com.metaweb.gridworks.model.AbstractOperation;
|
2010-03-07 23:37:26 +01:00
|
|
|
import com.metaweb.gridworks.model.Project;
|
2010-02-22 05:23:25 +01:00
|
|
|
|
|
|
|
public abstract class OperationRegistry {
|
2010-04-05 09:15:16 +02:00
|
|
|
|
|
|
|
static final public Map<String, Class<? extends AbstractOperation>> s_opNameToClass = new HashMap<String, Class<? extends AbstractOperation>>();
|
|
|
|
static final public Map<Class<? extends AbstractOperation>, String> s_opClassToName = new HashMap<Class<? extends AbstractOperation>, String>();
|
2010-02-22 05:23:25 +01:00
|
|
|
|
|
|
|
static protected void register(String name, Class<? extends AbstractOperation> klass) {
|
|
|
|
s_opNameToClass.put(name, klass);
|
|
|
|
s_opClassToName.put(klass, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
|
|
|
register("recon", ReconOperation.class);
|
|
|
|
register("recon-mark-new-topics", ReconMarkNewTopicsOperation.class);
|
|
|
|
register("recon-match-best-candidates", ReconMatchBestCandidatesOperation.class);
|
|
|
|
register("recon-discard-judgments", ReconDiscardJudgmentsOperation.class);
|
|
|
|
register("recon-match-specific-topic-to-cells", ReconMatchSpecificTopicOperation.class);
|
2010-02-22 21:25:45 +01:00
|
|
|
register("recon-judge-similar-cells", ReconJudgeSimilarCellsOperation.class);
|
2010-02-22 05:23:25 +01:00
|
|
|
|
|
|
|
register("multivalued-cell-join", MultiValuedCellJoinOperation.class);
|
|
|
|
register("multivalued-cell-split", MultiValuedCellSplitOperation.class);
|
|
|
|
|
|
|
|
register("column-addition", ColumnAdditionOperation.class);
|
|
|
|
register("column-removal", ColumnRemovalOperation.class);
|
2010-04-06 09:47:44 +02:00
|
|
|
register("column-rename", ColumnRenameOperation.class);
|
2010-04-21 01:08:14 +02:00
|
|
|
register("column-split", ColumnSplitOperation.class);
|
2010-03-16 01:24:20 +01:00
|
|
|
register("extend-data", ExtendDataOperation.class);
|
2010-02-22 05:23:25 +01:00
|
|
|
|
2010-04-06 09:47:44 +02:00
|
|
|
register("row-removal", RowRemovalOperation.class);
|
2010-02-23 08:45:12 +01:00
|
|
|
register("row-star", RowStarOperation.class);
|
2010-04-26 03:08:56 +02:00
|
|
|
register("row-flag", RowFlagOperation.class);
|
2010-02-23 08:45:12 +01:00
|
|
|
|
2010-02-22 05:23:25 +01:00
|
|
|
register("save-protograph", SaveProtographOperation.class);
|
|
|
|
register("text-transform", TextTransformOperation.class);
|
2010-03-07 01:25:00 +01:00
|
|
|
register("mass-edit", MassEditOperation.class);
|
2010-02-22 05:23:25 +01:00
|
|
|
}
|
2010-03-07 23:37:26 +01:00
|
|
|
|
|
|
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) {
|
|
|
|
try {
|
|
|
|
String op = obj.getString("op");
|
|
|
|
|
|
|
|
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
|
|
|
|
if (klass != null) {
|
|
|
|
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
|
|
|
|
if (reconstruct != null) {
|
|
|
|
return (AbstractOperation) reconstruct.invoke(null, project, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-02-22 05:23:25 +01:00
|
|
|
}
|