return ret;
}
private Savable readSavableFromCurrentElem(final Savable defVal) throws InstantiationException,
ClassNotFoundException, IOException, IllegalAccessException {
Savable ret = defVal;
Savable tmp = null;
if (_currentElem == null || _currentElem.getNodeName().equals("null")) {
return null;
}
final String reference = _currentElem.getAttribute("ref");
if (reference.length() > 0) {
ret = _referencedSavables.get(reference);
} else {
String className = _currentElem.getNodeName();
if (defVal != null) {
className = defVal.getClass().getName();
} else if (_currentElem.hasAttribute("class")) {
className = _currentElem.getAttribute("class");
}
try {
@SuppressWarnings("unchecked")
final Class<? extends Savable> clazz = (Class<? extends Savable>) Class.forName(className);
final SavableFactory ann = clazz.getAnnotation(SavableFactory.class);
if (ann == null) {
tmp = clazz.newInstance();
} else {
tmp = (Savable) clazz.getMethod(ann.factoryMethod(), (Class<?>[]) null).invoke(null,
(Object[]) null);
}
} catch (final InstantiationException e) {
Logger.getLogger(getClass().getName()).logp(
Level.SEVERE,
this.getClass().toString(),
"readSavableFromCurrentElem(Savable)",
"Could not access constructor of class '" + className + "'! \n"
+ "Some types may require the annotation SavableFactory. Please double check.");
throw new Ardor3dException(e);
} catch (final NoSuchMethodException e) {
Logger.getLogger(getClass().getName())
.logp(Level.SEVERE,
this.getClass().toString(),
"readSavableFromCurrentElem(Savable)",
e.getMessage()
+ " \n"
+ "Method specified in annotation does not appear to exist or has an invalid method signature.");
throw new Ardor3dException(e);
} catch (final Exception e) {
Logger.getLogger(getClass().getName()).logp(Level.SEVERE, this.getClass().toString(),
"readSavableFromCurrentElem(Savable)", "Exception", e);
return null;
}
final String refID = _currentElem.getAttribute("reference_ID");
if (refID.length() > 0) {
_referencedSavables.put(refID, tmp);
}
if (tmp != null) {
tmp.read(this);
ret = tmp;
}
}
return ret;
}