brooklyncentral/brooklyn — pull request #1393 by aledsage (2014-05-19 22:42:24+00:00)
Title: Fix: rebind first-pass doesn't use xstream

- There is a two-phase deserialisation to reconstitute the entities and locations.
1. find the entity ids + types to instantiate them all
2. deserialise, so that any entity ref can be resolved during deserialisation

- Previously, the first phase used dummy-objects to represent entities/locations, an used xstream with with ignoring the real entity cross-references. The dummy-object would be a dynamic proxy implementing Entity, and the type of the field where it was to be assigned.

However, this failed if the same entity was referenced in the same file multiple times, but in fields of different types.

For example, if the first time the entity reference was encountered it was with a field of type `Entity` then that is how the object would be deserialised. The second time, e.g. for a field of type Group, it would share the same reference. But the dynamic proxy created for the first field didn’t implement Group, so it caused a `ClassCastException`.

- Solution is to do a lighter weight parsing of the mementos to produce a “BrooklynMementoManifest” that just says the ids + types. From that, we create the entities/locations; and then we’re ready for the second phase.