* XMLImporter can now read version numbers from XML J3O
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7736 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
030edabc80
commit
826c285551
@ -34,6 +34,7 @@ package com.jme3.export.binary;
|
|||||||
|
|
||||||
import com.jme3.export.InputCapsule;
|
import com.jme3.export.InputCapsule;
|
||||||
import com.jme3.export.Savable;
|
import com.jme3.export.Savable;
|
||||||
|
import com.jme3.export.SavableClassUtil;
|
||||||
import com.jme3.util.BufferUtils;
|
import com.jme3.util.BufferUtils;
|
||||||
import com.jme3.util.IntMap;
|
import com.jme3.util.IntMap;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -258,23 +259,8 @@ final class BinaryInputCapsule implements InputCapsule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSavableVersion(Class<? extends Savable> desiredClass){
|
public int getSavableVersion(Class<? extends Savable> desiredClass){
|
||||||
Class thisClass = savable.getClass();
|
return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
|
||||||
int count = 0;
|
cObj.classHierarchyVersions);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitSet readBitSet(String name, BitSet defVal) throws IOException {
|
public BitSet readBitSet(String name, BitSet defVal) throws IOException {
|
||||||
|
@ -124,6 +124,26 @@ public class SavableClassUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
* 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
|
* are checked to handle special cases, if the modules do not handle the class name, the
|
||||||
|
@ -72,14 +72,22 @@ public class DOMInputCapsule implements InputCapsule {
|
|||||||
private boolean isAtRoot = true;
|
private boolean isAtRoot = true;
|
||||||
private Map<String, Savable> referencedSavables = new HashMap<String, Savable>();
|
private Map<String, Savable> referencedSavables = new HashMap<String, Savable>();
|
||||||
|
|
||||||
|
private int[] classHierarchyVersions;
|
||||||
|
private Savable savable;
|
||||||
|
|
||||||
public DOMInputCapsule(Document doc, XMLImporter importer) {
|
public DOMInputCapsule(Document doc, XMLImporter importer) {
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
this.importer = importer;
|
this.importer = importer;
|
||||||
currentElem = doc.getDocumentElement();
|
currentElem = doc.getDocumentElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSavableVersion(Class<? extends Savable> clazz) {
|
public int getSavableVersion(Class<? extends Savable> desiredClass) {
|
||||||
return 0; // TODO: figure this out ...
|
if (classHierarchyVersions != null){
|
||||||
|
return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
|
||||||
|
classHierarchyVersions);
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String decodeString(String s) {
|
private static String decodeString(String s) {
|
||||||
@ -978,10 +986,25 @@ public class DOMInputCapsule implements InputCapsule {
|
|||||||
className = currentElem.getAttribute("class");
|
className = currentElem.getAttribute("class");
|
||||||
}
|
}
|
||||||
tmp = SavableClassUtil.fromName(className, null);
|
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");
|
String refID = currentElem.getAttribute("reference_ID");
|
||||||
if (refID.length() < 1) refID = currentElem.getAttribute("id");
|
if (refID.length() < 1) refID = currentElem.getAttribute("id");
|
||||||
if (refID.length() > 0) referencedSavables.put(refID, tmp);
|
if (refID.length() > 0) referencedSavables.put(refID, tmp);
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
|
// Allows reading versions from this savable
|
||||||
|
savable = tmp;
|
||||||
tmp.read(importer);
|
tmp.read(importer);
|
||||||
ret = tmp;
|
ret = tmp;
|
||||||
}
|
}
|
||||||
|
@ -495,7 +495,7 @@ public class DOMOutputCapsule implements OutputCapsule {
|
|||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
el.setAttribute("savable_version", sb.toString());
|
el.setAttribute("savable_versions", sb.toString());
|
||||||
|
|
||||||
writtenSavables.put(object, el);
|
writtenSavables.put(object, el);
|
||||||
object.write(exporter);
|
object.write(exporter);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user