Caught a stray rename miss. Added more generic support for renaming old Java classes so that extensions could remain backward-compatible, too

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1297 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-09-22 23:59:57 +00:00
parent 289f46bbf5
commit a112ffa9ab
2 changed files with 53 additions and 7 deletions

View File

@ -2,7 +2,9 @@ package com.google.refine;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
@ -221,13 +223,57 @@ public class RefineServlet extends Butterfly {
return s_singleton.registerOneCommand(module, commandName, commandObject);
}
static private class ClassMapping {
final String from;
final String to;
ClassMapping(String from, String to) {
this.from = from;
this.to = to;
}
}
static final private List<ClassMapping> classMappings = new ArrayList<ClassMapping>();
/**
* Add a mapping that determines how old class names can be updated to newer
* class names. Such updates are desirable as the Java code changes from version
* to version. If the "from" argument ends with *, then it's considered a prefix;
* otherwise, it's an exact string match.
*
* @param from
* @param to
*/
static public void registerClassMapping(String from, String to) {
classMappings.add(new ClassMapping(from, to.endsWith("*") ? to.substring(0, to.length() - 1) : to));
}
static {
registerClassMapping("com.metaweb.*", "com.google.*");
registerClassMapping("com.google.gridworks.*", "com.google.refine.*");
}
static final private Map<String, String> classMappingsCache = new HashMap<String, String>();
static public Class<?> getClass(String className) throws ClassNotFoundException {
if (className.startsWith("com.metaweb.")) {
className = "com.google." + className.substring("com.metaweb.".length());
String toClassName = classMappingsCache.get(className);
if (toClassName == null) {
toClassName = className;
for (ClassMapping m : classMappings) {
if (m.from.endsWith("*")) {
if (toClassName.startsWith(m.from.substring(0, m.from.length() - 1))) {
toClassName = m.to + toClassName.substring(m.from.length() - 1);
}
if (className.startsWith("com.google.gridworks.")) {
className = "com.google.refine." + className.substring("com.google.gridworks.".length());
}
return Class.forName(className);
} else {
if (m.from.equals(toClassName)) {
toClassName = m.to;
}
}
}
classMappingsCache.put(className, toClassName);
}
return Class.forName(toClassName);
}
}

View File

@ -121,7 +121,7 @@ function initializeUI(uiState) {
}
Refine.setTitle = function(status) {
var title = theProject.metadata.name + " - Gridworks";
var title = theProject.metadata.name + " - Google Refine";
if (status) {
title = status + " - " + title;
}