6 Copyright (C) 2009-2010 8 RT-Synthesis Research Group 9 Intelligent Systems Research Institute, 10 National Institute of Advanced Industrial Science and Technology (AIST), 13 Licensed under the Eclipse Public License -v 1.0 (EPL) 14 http://www.opensource.org/licenses/eclipse-1.0.txt 18 Objects representing ports in a component. 22 __version__ =
'$Revision: $' 26 from rtsprofile
import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
29 parse_properties_xml, validate_attribute
36 '''Represents a data port of a component, as specified in a 41 def __init__(self, name='', comment='', visible=True):
44 @param name Name of the port. 46 @param comment A comment about the port. 48 @param visible If this port is visible in graphical displays. 53 expected_type=[str, unicode], required=
False)
56 expected_type=[str, unicode], required=
False)
59 expected_type=bool, required=
False)
64 result =
'Name: {0}\n'.format(self.
name)
66 result +=
' Comment: {0}\n'.format(self.
comment)
67 result +=
' Visible: {0}\n'.format(self.
visible)
69 result +=
' Properties:\n' 71 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
76 '''The name of this data port. 78 This name is used in connector profiles to identify the port. 86 expected_type=[str, unicode], required=
True)
91 '''Comment about the data port. 93 A brief comment about the data port. May or may not be displayed in 94 other tools. May be empty. 96 Part of the extended profile. 104 expected_type=[str, unicode], required=
False)
109 '''Display the port in graphical tools. 111 This value controls whether graphical tools will display this port or 114 Part of the extended profile. 122 expected_type=bool, required=
False)
127 '''Miscellaneous properties. 129 Stores key/value pair properties. 131 Part of the extended profile. 139 expected_type=list, required=
False)
143 '''Parse an xml.dom Node object representing a data port into this 148 self.
name = node.getAttributeNS(RTS_NS,
'name')
149 self.
comment = node.getAttributeNS(RTS_EXT_NS,
'comment')
150 if node.hasAttributeNS(RTS_EXT_NS,
'visible'):
151 visible = node.getAttributeNS(RTS_EXT_NS,
'visible')
152 if visible.lower() ==
'true' or visible ==
'1':
157 local_name=
'Properties'):
163 '''Parse a YAML specification of a data port into this object.''' 164 self.
name = y[
'name']
165 if RTS_EXT_NS_YAML +
'comment' in y:
166 self.
comment = y[RTS_EXT_NS_YAML +
'comment']
168 if RTS_EXT_NS_YAML +
'visible' in y:
169 visible = y.get(RTS_EXT_NS_YAML +
'visible')
170 if visible ==
True or visible ==
'true' or visible ==
'True':
172 if RTS_EXT_NS_YAML +
'properties' in y:
173 for p
in y.get(RTS_EXT_NS_YAML +
'properties'):
182 '''Save this data port into an xml.dom.Element object.''' 183 element.setAttributeNS(RTS_NS, RTS_NS_S +
'name', self.
name)
185 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'comment',
187 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'visible',
190 new_prop_element = doc.createElementNS(RTS_EXT_NS,
191 RTS_EXT_NS_S +
'Properties')
193 element.appendChild(new_prop_element)
196 '''Save this data port into a dictionary.''' 197 d = {
'name': self.
name,
198 RTS_EXT_NS_YAML +
'visible': str(self.
visible).lower()}
200 d[RTS_EXT_NS_YAML +
'comment'] = self.
comment 208 d[RTS_EXT_NS_YAML +
'properties'] = props
216 '''Represents a service port of a component, as specified in a 221 def __init__(self, name='', comment='', visible=True):
224 @param name Name of the port. 226 @param comment A comment about the port. 228 @param visible If this port is visible in graphical displays. 233 expected_type=[str, unicode], required=
False)
236 expected_type=[str, unicode], required=
False)
239 expected_type=bool, required=
False)
244 result =
'Name: {0}\n'.format(self.
name)
246 result +=
' Comment: {0}\n'.format(self.
comment)
247 result +=
' Visible: {0}\n'.format(self.
visible)
249 result +=
' Properties:\n' 251 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
256 '''The name of this service port. 258 This name is used in connector profiles to identify the port. 266 expected_type=[str, unicode], required=
True)
271 '''Comment about the service port. 273 A brief comment about the service port. May or may not be displayed in 274 other tools. May be empty. 276 Part of the extended profile. 284 expected_type=[str, unicode], required=
False)
289 '''Display the port in graphical tools. 291 This value controls whether graphical tools will display this port or 294 Part of the extended profile. 302 expected_type=bool, required=
False)
307 '''Miscellaneous properties. 309 Stores key/value pair properties. 311 Part of the extended profile. 319 expected_type=list, required=
False)
323 '''Parse an xml.dom Node object representing a service port into this 328 self.
name = node.getAttributeNS(RTS_NS,
'name')
329 self.
comment = node.getAttributeNS(RTS_EXT_NS,
'comment')
330 if node.hasAttributeNS(RTS_EXT_NS,
'visible'):
331 visible = node.getAttributeNS(RTS_EXT_NS,
'visible')
332 if visible.lower() ==
'true' or visible ==
'1':
337 local_name=
'Properties'):
343 '''Parse a YAML specification of a service port into this object.''' 344 self.
name = y[
'name']
345 if RTS_EXT_NS_YAML +
'comment' in y:
346 self.
comment = y[RTS_EXT_NS_YAML +
'comment']
348 if RTS_EXT_NS_YAML +
'visible' in y:
349 visible = y.get(RTS_EXT_NS_YAML +
'visible')
350 if visible ==
True or visible ==
'true' or visible ==
'True':
352 if RTS_EXT_NS_YAML +
'properties' in y:
353 for p
in y.get(RTS_EXT_NS_YAML +
'properties'):
362 '''Save this service port into an xml.dom.Element object.''' 363 element.setAttributeNS(RTS_NS, RTS_NS_S +
'name', self.
name)
365 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'comment',
367 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'visible',
370 new_prop_element = doc.createElementNS(RTS_EXT_NS,
371 RTS_EXT_NS_S +
'Properties')
373 element.appendChild(new_prop_element)
376 '''Save this service port into a dictionary.''' 377 d = {
'name': self.
name,
378 RTS_EXT_NS_YAML +
'visible': str(self.
visible).lower()}
380 d[RTS_EXT_NS_YAML +
'comment'] = self.
comment 388 d[RTS_EXT_NS_YAML +
'properties'] = props
def save_xml(self, doc, element)
def __init__(self, name='', comment='', visible=True)
def __init__(self, name='', comment='', visible=True)
def save_xml(self, doc, element)
def parse_xml_node(self, node)
def properties_to_xml(element, name, value=None)
def parse_properties_xml(node)
def validate_attribute(attr, name, expected_type=None, required=False)
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
def parse_xml_node(self, node)