Revision: 19546 http://sourceforge.net/p/gate/code/19546 Author: ian_roberts Date: 2016-08-26 16:50:41 +0000 (Fri, 26 Aug 2016) Log Message: ----------- Removed special handling of collections when writing feature values, so they are now serialized as an ObjectWrapper the same as anything else. Among other things, this means that repositioning info is correctly preserved across saving and reloading of GATE XML (previously it would seem to reload OK but then fail at runtime when you try to call any of the RepositioningInfo.get*Pos methods).
The special *de*serialization logic is still there so existing XMLs with list-valued features will still work as before. Modified Paths: -------------- gate/trunk/src/main/gate/corpora/DocumentStaxUtils.java Modified: gate/trunk/src/main/gate/corpora/DocumentStaxUtils.java =================================================================== --- gate/trunk/src/main/gate/corpora/DocumentStaxUtils.java 2016-08-25 01:22:36 UTC (rev 19545) +++ gate/trunk/src/main/gate/corpora/DocumentStaxUtils.java 2016-08-26 16:50:41 UTC (rev 19546) @@ -618,6 +618,8 @@ return stringRep.toString(); } + // backwards compatibility only - newly serialized GATE documents will + // use an ObjectWrapper for Collection-valued features if(java.util.Collection.class.isAssignableFrom(theClass)) { Class<?> itemClass = null; Constructor<?> itemConstructor = null; @@ -1488,75 +1490,25 @@ String key2String = key.toString(); String value2String = value.toString(); Object item = null; - // Test key if it is String, Number or Collection + // Test key if it is String or Number if(key instanceof java.lang.String || - key instanceof java.lang.Number || - key instanceof java.util.Collection) { + key instanceof java.lang.Number) { keyClassName = key.getClass().getName(); } else { keyClassName = ObjectWrapper.class.getName(); key2String = new ObjectWrapper(key).toString(); } - // Test value if it is String, Number or Collection + // Test value if it is String, Number or Boolean if(value instanceof java.lang.String || value instanceof java.lang.Number - || value instanceof java.lang.Boolean - || value instanceof java.util.Collection){ + || value instanceof java.lang.Boolean){ valueClassName = value.getClass().getName(); } else { valueClassName = ObjectWrapper.class.getName(); value2String = new ObjectWrapper(value).toString(); } - // Features and values that are not Strings, Numbers, Booleans or - // collections - // will be discarded. - if(keyClassName == null || valueClassName == null) continue; - - // If key is collection serialize the collection in a specific - // format - if(key instanceof java.util.Collection) { - StringBuffer keyStrBuff = new StringBuffer(); - Iterator<?> iter = ((Collection<?>)key).iterator(); - if(iter.hasNext()) { - item = iter.next(); - if(item == null) continue FEATURES; - if(item instanceof java.lang.Number) - keyItemClassName = item.getClass().getName(); - else keyItemClassName = String.class.getName(); - keyStrBuff.append(item.toString()); - }// End if - while(iter.hasNext()) { - item = iter.next(); - if(item == null) continue FEATURES; - keyStrBuff.append(";").append(item.toString()); - }// End while - key2String = keyStrBuff.toString(); - }// End if - - // If key is collection serialize the colection in a specific - // format - if(value instanceof java.util.Collection) { - StringBuffer valueStrBuff = new StringBuffer(); - Iterator<?> iter = ((Collection<?>)value).iterator(); - if(iter.hasNext()) { - item = iter.next(); - if(item == null) continue FEATURES; - if(item instanceof java.lang.Number - || item instanceof java.lang.Boolean) - valueItemClassName = item.getClass().getName(); - else valueItemClassName = String.class.getName(); - valueStrBuff.append(item.toString()); - }// End if - while(iter.hasNext()) { - item = iter.next(); - if(item == null) continue FEATURES; - valueStrBuff.append(";").append(item.toString()); - }// End while - value2String = valueStrBuff.toString(); - }// End if - xsw.writeStartElement(namespaceURI, "Feature"); xsw.writeCharacters("\n "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ _______________________________________________ GATE-cvs mailing list GATE-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gate-cvs