3 # This file is part of jack_mixer
5 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 class serialization_backend
:
21 '''Base class for serialization backends'''
22 def get_root_serialization_object(self
, name
):
23 '''Returns serialization object where properties of root object will be serialized to'''
24 return None # this method should never be called for the base class
26 def get_child_serialization_object(self
, name
, backend_object
):
27 return None # this method should never be called for the base class
29 class serialization_object_backend
:
30 '''Base class for serialization backend objects where real object properties will be serialized to or unserialized from.'''
31 def add_property(self
, name
, value
):
32 '''Serialize particular property'''
38 def get_properties(self
):
41 def serialization_name(self
):
44 class serialized_object
:
45 '''Base class for object supporting serialization'''
46 def serialization_name(self
):
49 def serialize(self
, object_backend
):
50 '''Serialize properties of called object into supplied serialization_object_backend'''
53 def serialization_get_childs(self
):
54 '''Get child objects tha required and support serialization'''
57 def unserialize_property(self
, name
, value
):
60 def unserialize_child(self
, name
):
67 def serialize(self
, root
, backend
):
68 self
.serialize_one(backend
, root
, backend
.get_root_serialization_object(root
.serialization_name()))
70 def unserialize(self
, root
, backend
):
71 backend_object
= backend
.get_root_unserialization_object(root
.serialization_name())
72 if backend_object
== None:
75 return self
.unserialize_one(backend
, root
, backend_object
)
77 def unserialize_one(self
, backend
, object, backend_object
):
78 #print "Unserializing " + repr(object)
79 properties
= backend_object
.get_properties()
80 for name
, value
in properties
.iteritems():
81 #print "%s = %s" % (name, value)
82 if not object.unserialize_property(name
, value
):
85 backend_childs
= backend_object
.get_childs()
86 for backend_child
in backend_childs
:
87 name
= backend_child
.serialization_name()
88 child
= object.unserialize_child(name
)
91 if not self
.unserialize_one(backend
, child
, backend_child
):
96 def serialize_one(self
, backend
, object, backend_object
):
97 object.serialize(backend_object
)
98 childs
= object.serialization_get_childs()
100 #print "serializing child " + repr(child)
101 self
.serialize_one(backend
, child
, backend
.get_child_serialization_object(child
.serialization_name(), backend_object
))