1 19 20 package org.netbeans.modules.form; 21 22 import java.util.*; 23 import org.openide.*; 24 import org.openide.util.Lookup; 25 26 36 37 public abstract class PersistenceManager { 38 39 42 47 public abstract boolean canLoadForm(FormDataObject formObject) 48 throws PersistenceException; 49 50 58 public abstract void loadForm(FormDataObject formObject, 59 FormModel formModel, 60 List nonfatalErrors) 61 throws PersistenceException; 62 63 71 public abstract void saveForm(FormDataObject formObject, 72 FormModel formModel, 73 List nonfatalErrors) 74 throws PersistenceException; 75 76 79 private static List managers; 80 private static List managersByName; 81 82 public static void registerManager(PersistenceManager manager) { 83 getManagersList().add(manager); 84 } 85 86 public static void unregisterManager(PersistenceManager manager) { 87 getManagersList().remove(manager); 88 } 89 90 static void registerManager(String managerClassName) { 91 getManagersNamesList().add(managerClassName); 92 } 93 94 public static Iterator getManagers() { 95 ClassLoader classLoader = null; 96 Iterator iter = getManagersNamesList().iterator(); 97 while (iter.hasNext()) { if (classLoader == null) 99 classLoader = (ClassLoader )Lookup.getDefault().lookup(ClassLoader .class); 100 101 String pmClassName = (String ) iter.next(); 102 try { 103 PersistenceManager manager = (PersistenceManager) 104 classLoader.loadClass(pmClassName).newInstance(); 105 getManagersList().add(manager); 106 } 107 catch (Exception ex1) { 108 notifyError(ex1, pmClassName); 109 } 110 catch (LinkageError ex2) { 111 notifyError(ex2, pmClassName); 112 } 113 } 114 getManagersNamesList().clear(); 116 return getManagersList().iterator(); 117 } 118 119 private static List getManagersList() { 120 if (managers == null) { 121 managers = new ArrayList(); 122 managers.add(new GandalfPersistenceManager()); 123 } 124 return managers; 125 } 126 127 private static List getManagersNamesList() { 128 if (managersByName == null) 129 managersByName = new ArrayList(); 130 return managersByName; 131 } 132 133 private static void notifyError(Throwable th, String pmClassName) { 134 String msg = FormUtils.getFormattedBundleString( 135 "FMT_ERR_PersistenceManagerInstantiation", new Object [] { pmClassName }); 137 138 ErrorManager errorManager = ErrorManager.getDefault(); 139 errorManager.annotate(th, msg); 140 errorManager.notify(ErrorManager.EXCEPTION, th); 141 } 142 } 143 | Popular Tags |