Allowed a single operation class to be registered under several names, so that we can rename operations (to better names) while maintaining backward compatibility.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1443 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-10-07 05:42:01 +00:00
parent 1de5e7c00e
commit 9ea477c80d
3 changed files with 24 additions and 11 deletions

View File

@ -2,6 +2,8 @@ package com.google.refine.operations;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
@ -13,14 +15,23 @@ import edu.mit.simile.butterfly.ButterflyModule;
public abstract class OperationRegistry {
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>();
static final public Map<String, List<Class<? extends AbstractOperation>>> s_opNameToClass =
new HashMap<String, List<Class<? extends AbstractOperation>>>();
static final public Map<Class<? extends AbstractOperation>, String> s_opClassToName =
new HashMap<Class<? extends AbstractOperation>, String>();
static public void registerOperation(ButterflyModule module, String name, Class<? extends AbstractOperation> klass) {
String key = module.getName() + "/" + name;
s_opNameToClass.put(key, klass);
s_opClassToName.put(klass, key);
List<Class<? extends AbstractOperation>> classes = s_opNameToClass.get(key);
if (classes == null) {
classes = new LinkedList<Class<? extends AbstractOperation>>();
s_opNameToClass.put(key, classes);
}
classes.add(klass);
}
static public AbstractOperation reconstruct(Project project, JSONObject obj) {
@ -30,8 +41,10 @@ public abstract class OperationRegistry {
op = "core/" + op; // backward compatible
}
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass != null) {
List<Class<? extends AbstractOperation>> classes = s_opNameToClass.get(op);
if (classes != null && classes.size() > 0) {
Class<? extends AbstractOperation> klass = classes.get(classes.size() - 1);
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
if (reconstruct != null) {
return (AbstractOperation) reconstruct.invoke(null, project, obj);

View File

@ -35,22 +35,20 @@ public class SaveProtographOperation extends AbstractOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value("Save protograph");
writer.key("description"); writer.value(getBriefDescription());
writer.key("protograph"); _protograph.write(writer, options);
writer.endObject();
}
protected String getBriefDescription(Project project) {
return "Save schema skeleton";
protected String getBriefDescription() {
return "Save schema alignment skeleton";
}
@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
String description = "Save schema-alignment protograph";
Change change = new ProtographChange(_protograph);
return new HistoryEntry(historyEntryID, project, description, SaveProtographOperation.this, change);
return new HistoryEntry(historyEntryID, project, getBriefDescription(), SaveProtographOperation.this, change);
}
static public class ProtographChange implements Change {

View File

@ -139,7 +139,9 @@ function registerOperations() {
OR.registerOperation(module, "recon-judge-similar-cells", Packages.com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation);
OR.registerOperation(module, "import-qa-data", Packages.com.google.refine.operations.recon.ImportQADataOperation);
// for backward compatibility
OR.registerOperation(module, "save-protograph", Packages.com.google.refine.operations.SaveProtographOperation);
OR.registerOperation(module, "save-schema-alignment-skeleton", Packages.com.google.refine.operations.SaveProtographOperation);
}
/*