import com.jme3.export.InputCapsule;
import com.jme3.export.Savable;
+import com.jme3.export.SavableClassUtil;
import com.jme3.util.BufferUtils;
import com.jme3.util.IntMap;
import java.io.IOException;
}
public int getSavableVersion(Class<? extends Savable> desiredClass){
- Class thisClass = savable.getClass();
- int count = 0;
- while (thisClass != null && thisClass != desiredClass){
- thisClass = thisClass.getSuperclass();
- count ++;
- }
- if (thisClass == null){
- throw new IllegalArgumentException(savable.getClass().getName() +
- " does not extend " +
- desiredClass.getName() + "!");
- }else if (count > cObj.classHierarchyVersions.length){
- throw new IllegalArgumentException(savable.getClass().getName() +
- " cannot access version of " +
- desiredClass.getName() +
- " because it doesn't implement Savable");
- }
- return cObj.classHierarchyVersions[count];
+ return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
+ cObj.classHierarchyVersions);
}
public BitSet readBitSet(String name, BitSet defVal) throws IOException {
}
}
+ public static int getSavedSavableVersion(Object savable, Class<? extends Savable> desiredClass, int[] versions){
+ Class thisClass = savable.getClass();
+ int count = 0;
+ while (thisClass != null && thisClass != desiredClass){
+ thisClass = thisClass.getSuperclass();
+ count ++;
+ }
+ if (thisClass == null){
+ throw new IllegalArgumentException(savable.getClass().getName() +
+ " does not extend " +
+ desiredClass.getName() + "!");
+ }else if (count > versions.length){
+ throw new IllegalArgumentException(savable.getClass().getName() +
+ " cannot access version of " +
+ desiredClass.getName() +
+ " because it doesn't implement Savable");
+ }
+ return versions[count];
+ }
+
/**
* fromName creates a new Savable from the provided class name. First registered modules
* are checked to handle special cases, if the modules do not handle the class name, the
private XMLImporter importer;
private boolean isAtRoot = true;
private Map<String, Savable> referencedSavables = new HashMap<String, Savable>();
+
+ private int[] classHierarchyVersions;
+ private Savable savable;
public DOMInputCapsule(Document doc, XMLImporter importer) {
this.doc = doc;
currentElem = doc.getDocumentElement();
}
- public int getSavableVersion(Class<? extends Savable> clazz) {
- return 0; // TODO: figure this out ...
+ public int getSavableVersion(Class<? extends Savable> desiredClass) {
+ if (classHierarchyVersions != null){
+ return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
+ classHierarchyVersions);
+ }else{
+ return 0;
+ }
}
private static String decodeString(String s) {
className = currentElem.getAttribute("class");
}
tmp = SavableClassUtil.fromName(className, null);
+
+
+ String versionsStr = currentElem.getAttribute("savable_versions");
+ if (versionsStr != null && !versionsStr.equals("")){
+ String[] versionStr = versionsStr.split(",");
+ classHierarchyVersions = new int[versionStr.length];
+ for (int i = 0; i < classHierarchyVersions.length; i++){
+ classHierarchyVersions[i] = Integer.parseInt(versionStr[i].trim());
+ }
+ }else{
+ classHierarchyVersions = null;
+ }
+
String refID = currentElem.getAttribute("reference_ID");
if (refID.length() < 1) refID = currentElem.getAttribute("id");
if (refID.length() > 0) referencedSavables.put(refID, tmp);
if (tmp != null) {
+ // Allows reading versions from this savable
+ savable = tmp;
tmp.read(importer);
ret = tmp;
}
sb.append(", ");
}
}
- el.setAttribute("savable_version", sb.toString());
+ el.setAttribute("savable_versions", sb.toString());
writtenSavables.put(object, el);
object.write(exporter);