* Copied from GOIMPlugin.java
*/
@SuppressWarnings("unchecked")
public static synchronized <T extends IGOIMPreferenceObject> T getPreferenceObject(Class<T> cls) {
String key = cls.getName();
IGOIMPreferenceObject obj = parsedPreferenceObjects.get(key);
if(obj != null) return (T)obj;
IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
String str = preferenceStore.getString(key);
if(!str.equals("")) {
byte[] bytes = StringUtils.decodeBase64(str);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
try {
ObjectInputStream in = new ObjectInputStream(inputStream);
Object bobj = in.readObject();
in.close();
if(bobj instanceof IGOIMPreferenceObject) obj = (IGOIMPreferenceObject)bobj;
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
if(obj == null) {
try {
obj = cls.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
parsedPreferenceObjects.put(key,obj);
final Class saveCls = cls;
obj.addChangeListener(new SpheneListener<SpheneEvent>(){
public void handleEvent(SpheneEvent event) {
//saveAccountList();
savePreferenceObject(saveCls);
}});
return (T)obj;