* 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
3.0
Sha..rd 13 years ago
parent 8bb467fbfa
commit 9dfe1b12f3
  1. 2
      engine/src/core-plugins/com/jme3/export/binary/BinaryInputCapsule.java
  2. 2
      engine/src/core/com/jme3/export/FormatVersion.java
  3. 33
      engine/src/core/com/jme3/export/SavableClassUtil.java
  4. 5
      engine/src/xml/com/jme3/export/xml/DOMInputCapsule.java
  5. 5
      engine/src/xml/com/jme3/export/xml/DOMOutputCapsule.java
  6. 22
      engine/src/xml/com/jme3/export/xml/XMLExporter.java
  7. 3
      engine/src/xml/com/jme3/export/xml/XMLImporter.java

@ -260,7 +260,7 @@ final class BinaryInputCapsule implements InputCapsule {
public int getSavableVersion(Class<? extends Savable> desiredClass){ public int getSavableVersion(Class<? extends Savable> desiredClass){
return SavableClassUtil.getSavedSavableVersion(savable, desiredClass, return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
cObj.classHierarchyVersions); cObj.classHierarchyVersions, importer.getFormatVersion());
} }
public BitSet readBitSet(String name, BitSet defVal) throws IOException { public BitSet readBitSet(String name, BitSet defVal) throws IOException {

@ -10,7 +10,7 @@ public final class FormatVersion {
/** /**
* Version number of the format * 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 * Signature of the format. Currently "JME3" as ASCII

@ -82,13 +82,8 @@ public class SavableClassUtil {
} }
public static boolean isImplementingSavable(Class clazz){ public static boolean isImplementingSavable(Class clazz){
Class[] interfaces = clazz.getInterfaces(); boolean result = Savable.class.isAssignableFrom(clazz);
for (Class interfaceClass : interfaces){ return result;
if (interfaceClass == Savable.class){
return true;
}
}
return false;
} }
public static int[] getSavableVersions(Class<? extends Savable> clazz) throws IOException{ 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{ public static int getSavableVersion(Class<? extends Savable> clazz) throws IOException{
try { try {
Field field = clazz.getField("SAVABLE_VERSION"); 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) { } catch (IllegalAccessException ex) {
IOException ioEx = new IOException(); IOException ioEx = new IOException();
ioEx.initCause(ex); 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(); Class thisClass = savable.getClass();
int count = 0; int count = 0;
while (true) { while (thisClass != desiredClass) {
thisClass = thisClass.getSuperclass(); thisClass = thisClass.getSuperclass();
if (thisClass != null && SavableClassUtil.isImplementingSavable(thisClass)){ if (thisClass != null && SavableClassUtil.isImplementingSavable(thisClass)){
count ++; count ++;
@ -139,10 +139,15 @@ public class SavableClassUtil {
" does not extend " + " does not extend " +
desiredClass.getName() + "!"); desiredClass.getName() + "!");
}else if (count >= versions.length){ }else if (count >= versions.length){
throw new IllegalArgumentException(savable.getClass().getName() + if (formatVersion <= 1){
" cannot access version of " + System.out.println("BUGGY J3O ALERT");
desiredClass.getName() + return 0; // for buggy versions of j3o
" because it doesn't implement Savable"); }else{
throw new IllegalArgumentException(savable.getClass().getName() +
" cannot access version of " +
desiredClass.getName() +
" because it doesn't implement Savable");
}
} }
return versions[count]; return versions[count];
} }

@ -70,12 +70,15 @@ public class DOMInputCapsule implements InputCapsule {
this.doc = doc; this.doc = doc;
this.importer = importer; this.importer = importer;
currentElem = doc.getDocumentElement(); currentElem = doc.getDocumentElement();
String version = currentElem.getAttribute("format_version");
importer.formatVersion = version.equals("") ? 0 : Integer.parseInt(version);
} }
public int getSavableVersion(Class<? extends Savable> desiredClass) { public int getSavableVersion(Class<? extends Savable> desiredClass) {
if (classHierarchyVersions != null){ if (classHierarchyVersions != null){
return SavableClassUtil.getSavedSavableVersion(savable, desiredClass, return SavableClassUtil.getSavedSavableVersion(savable, desiredClass,
classHierarchyVersions); classHierarchyVersions, importer.getFormatVersion());
}else{ }else{
return 0; return 0;
} }

@ -32,6 +32,7 @@
package com.jme3.export.xml; package com.jme3.export.xml;
import com.jme3.export.FormatVersion;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable; 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 * currentElement to be new Element, and returns the new Element as well
*/ */
private Element appendElement(String name) { private Element appendElement(String name) {
Element ret = null; Element ret = doc.createElement(name);
ret = doc.createElement(name);
if (currentElement == null) { if (currentElement == null) {
ret.setAttribute("format_version", Integer.toString(FormatVersion.VERSION));
doc.appendChild(ret); doc.appendChild(ret);
} else { } else {
currentElement.appendChild(ret); 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 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 * @author Doug Daniels (dougnukem) - adjustments for jME 2.0 and Java 1.5
*/ */
public class XMLExporter implements JmeExporter{ 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 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() { public XMLExporter() {
@ -85,8 +85,8 @@ public class XMLExporter implements JmeExporter{
return domOut; return domOut;
} }
public static XMLExporter getInstance() { public static XMLExporter getInstance() {
return new XMLExporter(); return new XMLExporter();
} }
} }

@ -54,12 +54,13 @@ public class XMLImporter implements JmeImporter {
private AssetManager assetManager; private AssetManager assetManager;
private DOMInputCapsule domIn; private DOMInputCapsule domIn;
int formatVersion = 0;
public XMLImporter() { public XMLImporter() {
} }
public int getFormatVersion() { public int getFormatVersion() {
return 0; return formatVersion;
} }
public AssetManager getAssetManager(){ public AssetManager getAssetManager(){

Loading…
Cancel
Save