1 19 20 package org.polepos.teams.jdo; 21 22 import java.lang.reflect.*; 23 import java.util.*; 24 25 import com.versant.core.jdo.tools.ant.*; 26 27 public class JdoEnhancer { 28 29 private String className; 30 private String methodName; 31 private Class [] types; 32 private Object [] params; 33 34 private final static Map<String , JdoEnhancer> enhancers = registerEnhancers(); 35 36 private JdoEnhancer(){ 37 } 38 39 public JdoEnhancer(String enhancerClass, String enhancerMethod, Class [] parameterTypes, 40 Object [] parameters) { 41 className = enhancerClass; 42 methodName = enhancerMethod; 43 types = parameterTypes; 44 params = parameters; 45 } 46 47 public static void main(String [] args) throws Exception { 48 49 if(args == null || args.length == 0){ 50 System.err.println("Supply the name of the enhancer to org.polepos.teams.jdo.JdoEnhancer#main()"); 51 printRegisteredEnhancers(); 52 return; 53 } 54 55 JdoEnhancer enhancer = enhancers.get(args[0]); 56 if(enhancer == null){ 57 System.err.println("Enhancer " + args[0] + " is not registered in org.polepos.teams.jdo.JdoEnhancer"); 58 printRegisteredEnhancers(); 59 return; 60 } 61 62 if(enhancer.isRunnable()){ 63 enhancer.run(); 64 }else{ 65 try { 66 enhancer.callByReflection(); 67 } catch (Exception e) { 68 System.err.println("Jdo enhancing was not possible with the supplied enhancer name."); 69 e.printStackTrace(); 70 printRegisteredEnhancers(); 71 } 72 } 73 } 74 75 private static void printRegisteredEnhancers(){ 76 System.err.println("The following enhancers are registered, but they are only"); 77 System.err.println("available if the respective Jars are present in /lib"); 78 for(String key : enhancers.keySet()){ 79 System.err.println(key); 80 } 81 } 82 83 private void callByReflection() throws ClassNotFoundException , SecurityException , 84 NoSuchMethodException , IllegalArgumentException , IllegalAccessException , 85 InvocationTargetException { 86 Class clazz = Class.forName(className); 87 Method method = clazz.getMethod(methodName, types); 88 method.invoke(null, params); 89 } 90 91 private final static Map<String , JdoEnhancer> registerEnhancers() { 92 93 Map<String , JdoEnhancer> map = new HashMap<String , JdoEnhancer>(); 94 95 JdoEnhancer objectDBEnhancer = new JdoEnhancer( 99 "com.objectdb.Enhancer", 100 "enhance", 101 new Class [] { String .class }, 102 new Object [] { "org.polepos.teams.jdo.data.*" } 103 ); 104 map.put("objectdb", objectDBEnhancer); 105 106 107 JdoEnhancer voaEnhancer = new JdoEnhancer(){ 108 109 public boolean isRunnable(){ 110 return true; 111 } 112 113 public void run(){ 114 com.versant.core.jdo.tools.enhancer.Enhancer.main( 115 new String []{ 116 "-p", 117 "versant.properties", 118 }); 119 } 120 121 }; 122 123 map.put("voa", voaEnhancer); 124 125 126 128 129 return map; 130 } 131 132 public void run() { 133 } 135 136 public boolean isRunnable() { 137 return false; 139 } 140 141 } 142 | Popular Tags |