* 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. 23
      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. 2
      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){
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");
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,11 +139,16 @@ public class SavableClassUtil {
" does not extend " +
desiredClass.getName() + "!");
}else if (count >= versions.length){
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);

@ -48,6 +48,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
* @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";
@ -56,7 +57,6 @@ public class XMLExporter implements JmeExporter{
private DOMOutputCapsule domOut;
public 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…
Cancel
Save