* New J3O format version: fixed incorrect serialization of savable versions for certain class hierarchies
* XML import/export now supports global format version git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9070 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
8bb467fbfa
commit
9dfe1b12f3
@ -260,7 +260,7 @@ final class BinaryInputCapsule implements InputCapsule {
|
||||
|
||||
public int getSavableVersion(Class<? extends Savable> desiredClass){
|
||||
return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
|
||||
cObj.classHierarchyVersions);
|
||||
cObj.classHierarchyVersions, importer.getFormatVersion());
|
||||
}
|
||||
|
||||
public BitSet readBitSet(String name, BitSet defVal) throws IOException {
|
||||
|
@ -10,7 +10,7 @@ public final class FormatVersion {
|
||||
/**
|
||||
* Version number of the format
|
||||
*/
|
||||
public static final int VERSION = 1;
|
||||
public static final int VERSION = 2;
|
||||
|
||||
/**
|
||||
* Signature of the format. Currently "JME3" as ASCII
|
||||
|
@ -82,13 +82,8 @@ public class SavableClassUtil {
|
||||
}
|
||||
|
||||
public static boolean isImplementingSavable(Class clazz){
|
||||
Class[] interfaces = clazz.getInterfaces();
|
||||
for (Class interfaceClass : interfaces){
|
||||
if (interfaceClass == Savable.class){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
boolean result = Savable.class.isAssignableFrom(clazz);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int[] getSavableVersions(Class<? extends Savable> clazz) throws IOException{
|
||||
@ -109,7 +104,12 @@ public class SavableClassUtil {
|
||||
public static int getSavableVersion(Class<? extends Savable> clazz) throws IOException{
|
||||
try {
|
||||
Field field = clazz.getField("SAVABLE_VERSION");
|
||||
return field.getInt(null);
|
||||
Class<? extends Savable> declaringClass = (Class<? extends Savable>) field.getDeclaringClass();
|
||||
if (declaringClass == clazz){
|
||||
return field.getInt(null);
|
||||
}else{
|
||||
return 0; // This class doesn't declare this field, e.g. version == 0
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
IOException ioEx = new IOException();
|
||||
ioEx.initCause(ex);
|
||||
@ -121,11 +121,11 @@ public class SavableClassUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getSavedSavableVersion(Object savable, Class<? extends Savable> desiredClass, int[] versions){
|
||||
public static int getSavedSavableVersion(Object savable, Class<? extends Savable> desiredClass, int[] versions, int formatVersion){
|
||||
Class thisClass = savable.getClass();
|
||||
int count = 0;
|
||||
|
||||
while (true) {
|
||||
while (thisClass != desiredClass) {
|
||||
thisClass = thisClass.getSuperclass();
|
||||
if (thisClass != null && SavableClassUtil.isImplementingSavable(thisClass)){
|
||||
count ++;
|
||||
@ -139,10 +139,15 @@ public class SavableClassUtil {
|
||||
" 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");
|
||||
if (formatVersion <= 1){
|
||||
System.out.println("BUGGY J3O ALERT");
|
||||
return 0; // for buggy versions of j3o
|
||||
}else{
|
||||
throw new IllegalArgumentException(savable.getClass().getName() +
|
||||
" cannot access version of " +
|
||||
desiredClass.getName() +
|
||||
" because it doesn't implement Savable");
|
||||
}
|
||||
}
|
||||
return versions[count];
|
||||
}
|
||||
|
@ -70,12 +70,15 @@ public class DOMInputCapsule implements InputCapsule {
|
||||
this.doc = doc;
|
||||
this.importer = importer;
|
||||
currentElem = doc.getDocumentElement();
|
||||
|
||||
String version = currentElem.getAttribute("format_version");
|
||||
importer.formatVersion = version.equals("") ? 0 : Integer.parseInt(version);
|
||||
}
|
||||
|
||||
public int getSavableVersion(Class<? extends Savable> desiredClass) {
|
||||
if (classHierarchyVersions != null){
|
||||
return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
|
||||
classHierarchyVersions);
|
||||
classHierarchyVersions, importer.getFormatVersion());
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
package com.jme3.export.xml;
|
||||
|
||||
import com.jme3.export.FormatVersion;
|
||||
import com.jme3.export.JmeExporter;
|
||||
import com.jme3.export.OutputCapsule;
|
||||
import com.jme3.export.Savable;
|
||||
@ -77,9 +78,9 @@ public class DOMOutputCapsule implements OutputCapsule {
|
||||
* currentElement to be new Element, and returns the new Element as well
|
||||
*/
|
||||
private Element appendElement(String name) {
|
||||
Element ret = null;
|
||||
ret = doc.createElement(name);
|
||||
Element ret = doc.createElement(name);
|
||||
if (currentElement == null) {
|
||||
ret.setAttribute("format_version", Integer.toString(FormatVersion.VERSION));
|
||||
doc.appendChild(ret);
|
||||
} else {
|
||||
currentElement.appendChild(ret);
|
||||
|
@ -47,15 +47,15 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
* @author Kai Rabien (hevee) - original author of the code.google.com jmexml project
|
||||
* @author Doug Daniels (dougnukem) - adjustments for jME 2.0 and Java 1.5
|
||||
*/
|
||||
public class XMLExporter implements JmeExporter{
|
||||
public static final String ELEMENT_MAPENTRY = "MapEntry";
|
||||
public static final String ELEMENT_KEY = "Key";
|
||||
public static final String ELEMENT_VALUE = "Value";
|
||||
public static final String ELEMENT_FLOATBUFFER = "FloatBuffer";
|
||||
public static final String ATTRIBUTE_SIZE = "size";
|
||||
|
||||
private DOMOutputCapsule domOut;
|
||||
public class XMLExporter implements JmeExporter {
|
||||
|
||||
public static final String ELEMENT_MAPENTRY = "MapEntry";
|
||||
public static final String ELEMENT_KEY = "Key";
|
||||
public static final String ELEMENT_VALUE = "Value";
|
||||
public static final String ELEMENT_FLOATBUFFER = "FloatBuffer";
|
||||
public static final String ATTRIBUTE_SIZE = "size";
|
||||
|
||||
private DOMOutputCapsule domOut;
|
||||
|
||||
public XMLExporter() {
|
||||
|
||||
@ -85,8 +85,8 @@ public class XMLExporter implements JmeExporter{
|
||||
return domOut;
|
||||
}
|
||||
|
||||
public static XMLExporter getInstance() {
|
||||
return new XMLExporter();
|
||||
}
|
||||
public static XMLExporter getInstance() {
|
||||
return new XMLExporter();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,12 +54,13 @@ public class XMLImporter implements JmeImporter {
|
||||
|
||||
private AssetManager assetManager;
|
||||
private DOMInputCapsule domIn;
|
||||
int formatVersion = 0;
|
||||
|
||||
public XMLImporter() {
|
||||
}
|
||||
|
||||
public int getFormatVersion() {
|
||||
return 0;
|
||||
return formatVersion;
|
||||
}
|
||||
|
||||
public AssetManager getAssetManager(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user