1 19 20 21 package org.netbeans.modules.form; 22 23 import java.util.Map ; 24 import java.util.HashMap ; 25 import org.openide.util.Utilities; 26 import org.openide.filesystems.FileObject; 27 28 32 33 public class PersistenceObjectRegistry 34 { 35 36 private static Map _nameToClassname = new HashMap (); 37 private static Map _classToPrimaryName = new HashMap (); 38 39 private PersistenceObjectRegistry() { 40 } 41 42 public static void registerPrimaryName(String classname, String name) { 43 _classToPrimaryName.put(classname, name); 44 _nameToClassname.put(name, classname); 45 } 46 47 public static void registerPrimaryName(Class clazz, String name) { 48 _classToPrimaryName.put(clazz.getName(), name); 49 _nameToClassname.put(name, clazz.getName()); 50 } 51 52 public static void registerAlias(String classname, String alias) { 53 _nameToClassname.put(alias, classname); 54 } 55 56 public static void registerAlias(Class clazz, String alias) { 57 _nameToClassname.put(alias, clazz.getName()); 58 } 59 60 public static Object createInstance(String classname, FileObject form) 61 throws InstantiationException , IllegalAccessException , ClassNotFoundException 62 { 63 return loadClass(classname, form).newInstance(); 64 } 65 66 public static Class loadClass(String name, FileObject form) 67 throws ClassNotFoundException 68 { 69 name = Utilities.translate(name); 70 String classname =(String ) _nameToClassname.get(name); 71 if (classname == null) 72 classname = name; 73 return FormUtils.loadClass(classname, form); 74 } 75 76 public static String getPrimaryName(Object instance) { 77 return getPrimaryName(instance.getClass()); 78 } 79 80 public static String getPrimaryName(Class clazz) { 81 return getPrimaryName(clazz.getName()); 82 } 83 84 static String getPrimaryName(String className) { 85 String name = (String ) _classToPrimaryName.get(className); 86 return name != null ? name : className; 87 } 88 89 static String getClassName(String primaryName) { 90 primaryName = Utilities.translate(primaryName); 91 String classname = (String ) _nameToClassname.get(primaryName); 92 return classname != null ? classname : primaryName; 93 } 94 } 95 | Popular Tags |