001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.teams.jdo;
021:
022: import java.lang.reflect.*;
023: import java.util.*;
024:
025: import com.versant.core.jdo.tools.ant.*;
026:
027: public class JdoEnhancer {
028:
029: private String className;
030: private String methodName;
031: private Class[] types;
032: private Object[] params;
033:
034: private final static Map<String, JdoEnhancer> enhancers = registerEnhancers();
035:
036: private JdoEnhancer() {
037: }
038:
039: public JdoEnhancer(String enhancerClass, String enhancerMethod,
040: Class[] parameterTypes, Object[] parameters) {
041: className = enhancerClass;
042: methodName = enhancerMethod;
043: types = parameterTypes;
044: params = parameters;
045: }
046:
047: public static void main(String[] args) throws Exception {
048:
049: if (args == null || args.length == 0) {
050: System.err
051: .println("Supply the name of the enhancer to org.polepos.teams.jdo.JdoEnhancer#main()");
052: printRegisteredEnhancers();
053: return;
054: }
055:
056: JdoEnhancer enhancer = enhancers.get(args[0]);
057: if (enhancer == null) {
058: System.err
059: .println("Enhancer "
060: + args[0]
061: + " is not registered in org.polepos.teams.jdo.JdoEnhancer");
062: printRegisteredEnhancers();
063: return;
064: }
065:
066: if (enhancer.isRunnable()) {
067: enhancer.run();
068: } else {
069: try {
070: enhancer.callByReflection();
071: } catch (Exception e) {
072: System.err
073: .println("Jdo enhancing was not possible with the supplied enhancer name.");
074: e.printStackTrace();
075: printRegisteredEnhancers();
076: }
077: }
078: }
079:
080: private static void printRegisteredEnhancers() {
081: System.err
082: .println("The following enhancers are registered, but they are only");
083: System.err
084: .println("available if the respective Jars are present in /lib");
085: for (String key : enhancers.keySet()) {
086: System.err.println(key);
087: }
088: }
089:
090: private void callByReflection() throws ClassNotFoundException,
091: SecurityException, NoSuchMethodException,
092: IllegalArgumentException, IllegalAccessException,
093: InvocationTargetException {
094: Class clazz = Class.forName(className);
095: Method method = clazz.getMethod(methodName, types);
096: method.invoke(null, params);
097: }
098:
099: private final static Map<String, JdoEnhancer> registerEnhancers() {
100:
101: Map<String, JdoEnhancer> map = new HashMap<String, JdoEnhancer>();
102:
103: // tested successfully with odbfe.jar and jdo.jar in the lib folder
104: // Both are supplied the ObjectDB free edition downloadable from:
105: // http://www.objectdb.com
106: JdoEnhancer objectDBEnhancer = new JdoEnhancer(
107: "com.objectdb.Enhancer", "enhance",
108: new Class[] { String.class },
109: new Object[] { "org.polepos.teams.jdo.data.*" });
110: map.put("objectdb", objectDBEnhancer);
111:
112: JdoEnhancer voaEnhancer = new JdoEnhancer() {
113:
114: public boolean isRunnable() {
115: return true;
116: }
117:
118: public void run() {
119: com.versant.core.jdo.tools.enhancer.Enhancer
120: .main(new String[] { "-p",
121: "versant.properties", });
122: }
123:
124: };
125:
126: map.put("voa", voaEnhancer);
127:
128: // TODO: add more enhancers here and register them like above
129:
130: return map;
131: }
132:
133: public void run() {
134: // virtual method to override
135: }
136:
137: public boolean isRunnable() {
138: // virtual method to override
139: return false;
140: }
141:
142: }
|