Example #1
0
    def clone_object(self, mgr, tome, type_info):
        clone = tome.__class__(tome.name)

        # non-tome props
        my_basic_props = list(util.basic_props(tome))
        clone_basic_props = list(util.basic_props(clone))
        for ii in range(len(my_basic_props)):
            prop = my_basic_props[ii]
            clone_prop = clone_basic_props[ii]
            marshaller = mgr.require_data_marshaller(prop.value_type.clazz)
            clone_prop.value = marshaller.clone_data(mgr, prop.value, prop.value_type)

        # child tomes
        for child_tome in tome.values():
            marshaller = mgr.require_data_marshaller(child_tome.type_info.clazz)
            clone.add_tome(marshaller.clone_data(mgr, child_tome, child_tome.type_info))
        return clone
Example #2
0
    def write_tome(self, writer, tome):
        writer.write_string(Defs.TOME_TYPE_ATTR, util.tome_typename(tome.__class__))

        # TODO: template support

        # Write out non-Tome props
        for prop in (prop for prop in util.basic_props(tome) if prop.value is not None):
            marshaller = self.require_data_marshaller(prop.value_type.clazz)
            child_writer = writer if marshaller.is_simple else writer.add_child(prop.name)
            marshaller.write_value(self, child_writer, prop.value, prop.name, prop.value_type)

        # Write Tomes
        for tome in sorted(tome.values(), key=lambda tome: tome.name):
            self.write_tome(writer.add_child(tome.name), tome)
Example #3
0
    def resolve_refs(self, mgr, tome, type_info):
        # non-tome props
        for prop in (prop for prop in util.basic_props(tome) if prop.value is not None):
            try:
                marshaller = mgr.require_data_marshaller(prop.value_type.clazz)
                marshaller.resolve_refs(mgr, prop.value, prop.value_type)
            except ResolveRefError:
                raise
            except Exception as e:
                raise ResolveRefError("Failed to resolve ref [tome=%s]" % tome.id, cause=e)

        # child tomes
        for child_tome in tome.values():
            marshaller = mgr.require_data_marshaller(child_tome.type_info.clazz)
            marshaller.resolve_refs(mgr, child_tome, child_tome.type_info)