comparison orpg/mapper/whiteboard_msg.py @ 20:072ffc1d466f traipse_dev

2nd attempt. Still untested.
author sirebral
date Sat, 25 Jul 2009 19:23:25 -0500
parents 78407d627cba
children 36919b8a3ef9
comparison
equal deleted inserted replaced
19:78407d627cba 20:072ffc1d466f
69 return map_element_msg_base.get_all_xml(self,action,output_action) 69 return map_element_msg_base.get_all_xml(self,action,output_action)
70 70
71 def get_changed_xml(self,action="update",output_action=1): 71 def get_changed_xml(self,action="update",output_action=1):
72 return map_element_msg_base.get_changed_xml(self,action,output_action) 72 return map_element_msg_base.get_changed_xml(self,action,output_action)
73 73
74
74 class whiteboard_msg(map_element_msg_base): 75 class whiteboard_msg(map_element_msg_base):
75 76
76 def __init__(self,reentrant_lock_object = None): 77 def __init__(self,reentrant_lock_object = None):
77 self.tagname = "whiteboard" 78 self.tagname = "whiteboard"
78 map_element_msg_base.__init__(self,reentrant_lock_object) 79 map_element_msg_base.__init__(self,reentrant_lock_object)
83 if xml_dom.getAttributeKeys(): 84 if xml_dom.getAttributeKeys():
84 for k in xml_dom.getAttributeKeys(): 85 for k in xml_dom.getAttributeKeys():
85 self.init_prop(k,xml_dom.getAttribute(k)) 86 self.init_prop(k,xml_dom.getAttribute(k))
86 for c in xml_dom._get_childNodes(): 87 for c in xml_dom._get_childNodes():
87 item = item_msg(self.p_lock,c._get_nodeName()) 88 item = item_msg(self.p_lock,c._get_nodeName())
88 try: 89 try: item.init_from_dom(c)
89 item.init_from_dom(c)
90 except Exception, e: 90 except Exception, e:
91 print e 91 print e
92 continue 92 continue
93 id = item.get_prop("id") 93 id = item.get_prop("id")
94 action = item.get_prop("action") 94 action = item.get_prop("action")
95 if action == "new": 95 if action == "new": self.children[id] = item
96 self.children[id] = item
97 elif action == "del": 96 elif action == "del":
98 if self.children.has_key(id): 97 if self.children.has_key(id):
99 self.children[id] = None 98 self.children[id] = None
100 del self.children[id] 99 del self.children[id]
101 elif action == "update": 100 elif action == "update":
102 if self.children.has_key(id): 101 if self.children.has_key(id): self.children[id].init_props(item.get_all_props())
103 self.children[id].init_props(item.get_all_props())
104 else: 102 else:
105 self.p_lock.release() 103 self.p_lock.release()
106 raise Exception, 104 raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element in whiteboard"
107 "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element in whiteboard"
108 self.p_lock.release() 105 self.p_lock.release()
109 106
110 def set_from_dom(self,xml_dom): 107 def set_from_dom(self,xml_dom):
111 self.p_lock.acquire() 108 self.p_lock.acquire()
112 if xml_dom.tagName == self.tagname: 109 if xml_dom.tagName == self.tagname:
113 if xml_dom.getAttributeKeys(): 110 if xml_dom.getAttributeKeys():
114 for k in xml_dom.getAttributeKeys(): 111 for k in xml_dom.getAttributeKeys():
115 self.set_prop(k,xml_dom.getAttribute(k)) 112 self.set_prop(k,xml_dom.getAttribute(k))
116 for c in xml_dom._get_childNodes(): 113 for c in xml_dom._get_childNodes():
117 item = item_msg(self.p_lock, c._get_nodeName()) 114 item = item_msg(self.p_lock, c._get_nodeName())
118 try: 115 try: item.set_from_dom(c)
119 item.set_from_dom(c)
120 except Exception, e: 116 except Exception, e:
121 print e 117 print e
122 continue 118 continue
123 id = item.get_prop("id") 119 id = item.get_prop("id")
124 action = item.get_prop("action") 120 action = item.get_prop("action")
125 if action == "new": 121 if action == "new": self.children[id] = item
126 self.children[id] = item
127 elif action == "del": 122 elif action == "del":
128 if self.children.has_key(id): 123 if self.children.has_key(id):
129 self.children[id] = None 124 self.children[id] = None
130 del self.children[id] 125 del self.children[id]
131 elif action == "update": 126 elif action == "update":
132 if self.children.has_key(id): 127 if self.children.has_key(id): self.children[id].set_props(item.get_all_props())
133 self.children[id].set_props(item.get_all_props())
134 else: 128 else:
135 self.p_lock.release() 129 self.p_lock.release()
136 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element" 130 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element"
137 self.p_lock.release() 131 self.p_lock.release()