public void writeHiddenClass( TreeMapConverter mapConverter, HierarchicalStreamWriter writer, MarshallingContext context) { if (Snapshot.getLocal().getFieldSetFromId(id) != null) { writer.startNode(nodeName); writer.addAttribute(XMLConstants.ID_ATTRIBUTE, id.toString()); writer.addAttribute(XMLConstants.FIELDSET_ATTRIBUTE, "true"); mapConverter.marshal(Snapshot.getLocal().getFieldSetFromId(id), writer, context); writer.endNode(); } }
// ---------------------------------------------------------- public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { if (source instanceof AbstractPersistentMap) { throw new IllegalArgumentException( "You cannot store an object that contains a reference to a " + source.getClass().getSimpleName()); } writer.addAttribute(XMLConstants.FIELDSET_ATTRIBUTE, "true"); Map<String, Object> fields = objectToFieldMap(source); // BUG: The persistence store will attempt to persist an inner class. // This is the same as storing an object that references the Application // class if (fields.containsKey("this$0")) { throw new IllegalArgumentException( "The class " + source.getClass().getName() + " cannot be persisted because the definition of this class is contained within the " + fields.get("this$0").getClass().getName() + " class. Move " + source.getClass().getName() + " to its own JAVA file."); } checkFields(source.getClass().getName(), fields); UUID id = Snapshot.lookupId(source, true); writer.addAttribute(XMLConstants.ID_ATTRIBUTE, id.toString()); Map<String, Object> updatedFieldSets = generateUpdatedFieldSet(Snapshot.getLocal(), Snapshot.getNewest(), source, fields); List<String> nulledKeys = new ArrayList<String>(); for (String key : updatedFieldSets.keySet()) { if (updatedFieldSets.get(key) instanceof NullableClass) { NullableClass nClass = (NullableClass) updatedFieldSets.get(key); nClass.writeHiddenClass(mapConverter, writer, context); // updatedFieldSets.remove( key ); nulledKeys.add(key); } } for (String key : nulledKeys) updatedFieldSets.remove(key); restoreObjectFromFieldMap(source, updatedFieldSets); Snapshot.getLocal().resolveObject(id, source, updatedFieldSets); mapConverter.marshal(updatedFieldSets, writer, context); }