[BROOKLYN-183] Workaround use of private package in XmlMementoSerializer Copy bundle-private code from xstreams into XmlMementoSerializer
Temporarily until osgification is complete. Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/3f4c2ac2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/3f4c2ac2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/3f4c2ac2 Branch: refs/heads/master Commit: 3f4c2ac202a67e75bc32f56f55dc6ca5be134155 Parents: 06b186f Author: Ciprian Ciubotariu <[email protected]> Authored: Fri Oct 9 00:38:14 2015 +0300 Committer: Ciprian Ciubotariu <[email protected]> Committed: Sun Oct 25 01:04:51 2015 +0300 ---------------------------------------------------------------------- .../core/mgmt/persist/XmlMementoSerializer.java | 35 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3f4c2ac2/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java index ec7fb6f..6e1ac65 100644 --- a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java +++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java @@ -71,7 +71,6 @@ import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.reflection.ReflectionConverter; import com.thoughtworks.xstream.core.ReferencingMarshallingContext; -import com.thoughtworks.xstream.core.util.HierarchicalStreams; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.path.PathTrackingReader; @@ -335,7 +334,8 @@ public class XmlMementoSerializer<T> extends XmlSerializer<T> implements Memento @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { if (reader.hasMoreChildren()) { - Class<?> type = HierarchicalStreams.readClassType(reader, mapper); + Class<?> type = readClassType(reader, mapper); +// Class<?> type2 = context.getRequiredType(); reader.moveDown(); Object result = context.convertAnother(null, type); reader.moveUp(); @@ -345,7 +345,36 @@ public class XmlMementoSerializer<T> extends XmlSerializer<T> implements Memento } } } - + + // TODO: readClassType() and readClassAttribute() + // Temporarily copied until osgification is finished from bundle-private class + // com.thoughtworks.xstream.core.util.HierarchicalStreams + // Perhaps context.getRequiredType(); can be used instead? + // Other users of xstream (e.g. jenkinsci) manually check for resoved-to and class attributes + // for compatibility with older versions of xstream + public static Class readClassType(HierarchicalStreamReader reader, Mapper mapper) { + String classAttribute = readClassAttribute(reader, mapper); + Class type; + if (classAttribute == null) { + type = mapper.realClass(reader.getNodeName()); + } else { + type = mapper.realClass(classAttribute); + } + return type; + } + + public static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) { + String attributeName = mapper.aliasForSystemAttribute("resolves-to"); + String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName); + if (classAttribute == null) { + attributeName = mapper.aliasForSystemAttribute("class"); + if (attributeName != null) { + classAttribute = reader.getAttribute(attributeName); + } + } + return classAttribute; + } + public class ManagementContextConverter implements Converter { @Override public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
