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 Object representing a component in an RT system. 22 __version__ =
'$Revision: $' 26 from rtsprofile
import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
28 from rtsprofile
import composite_type
as comp_type
35 indent_string, parse_properties_xml, \
36 properties_to_xml, validate_attribute
43 '''Information about a component contained in an RT system.''' 45 def __init__(self, id='', path_uri='', active_configuration_set='',
46 instance_name=
'', composite_type=comp_type.NONE,
47 is_required=
False, comment=
'', visible=
True,
49 '''@param id Component ID. 51 @param path_uri Path to the component. 53 @param active_configuration_set Name of the active configuration set. 54 @type active_configuration_set str 55 @param instance_name Component's instance name. 56 @type instance_name str 57 @param composite_type Type of composition the component is in. 58 @type composite_type CompositeType 59 @param is_required If the component is optional in the system. 60 @type is_required bool 61 @param comment A comment about the component. 63 @param visible If this component is visible in graphical displays. 65 @param location The location of this component in graphical displays. 66 @type location Location 71 expected_type=[str, unicode], required=
False)
74 expected_type=[str, unicode], required=
False)
77 'component.activeConfigurationSet',
78 expected_type=[str, unicode], required=
False)
81 expected_type=[str, unicode], required=
False)
84 expected_type=comp_type.const_type, required=
False)
90 expected_type=[str, unicode], required=
False)
93 expected_type=bool, required=
False)
96 expected_type=Location, required=
True)
100 result =
'Instance name: {3}\n ID: {0}\n Path URI: {1}\n Active \ 101 configuration set: {2}\n Composite type: {4}\n Is required: {5}\n'.format(\
106 result +=
' Comment: {0}\n'.format(self.
comment)
107 result +=
' Visible: {0}\n'.format(self.
visible)
109 result +=
' Data ports:\n' 111 result +=
'{0}\n'.format(
indent_string(str(p), num_spaces=4))
113 result +=
' Service ports:\n' 115 result +=
'{0}\n'.format(
indent_string(str(p), num_spaces=4))
117 result +=
' Configuration sets:\n' 119 result +=
'{0}\n'.format(
indent_string(str(c), num_spaces=4))
121 result +=
' Execution contexts:\n' 123 result +=
'{0}\n'.format(
indent_string(str(e), num_spaces=4))
125 result +=
' Participants:\n' 131 result +=
' Properties:\n' 133 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
141 '''ID of this component in the RT system. 143 In case of the same RT Component specification being used to create 144 multiple RT Components within a single RT system, this ID is prepended 145 to the instance name attribute to distinguish individual components. 153 expected_type=[str, unicode], required=
True)
158 '''Path to where this component is registered in URI format.''' 164 expected_type=[str, unicode], required=
True)
169 '''The ID of the active configuration set of the component. 171 If no configuration set is active, this may be empty. 176 @active_configuration_set.setter
179 'component.activeConfigurationSet',
180 expected_type=[str, unicode], required=
False)
185 '''Instance name of the component in the RT system. 187 In case of the same RT Component specification being used to create 188 multiple RT Components within a single RT system, this instance name is 189 appended to the ID attribute to distinguish individual components. 194 @instance_name.setter
197 expected_type=[str, unicode], required=
True)
202 '''The type of composite component this component is involved in. 204 If this component is involved in a composite component, this attribute 205 specifies the type of composition. See @ref CompositeType for valid 211 @composite_type.setter
214 expected_type=comp_type.const_type, required=
True)
219 '''Specifies if this component is optional in the RT system. 221 Sometimes a component does not need to be present for an RT system to 222 function. If this component must be present for the RT system to 223 function, this attribute will be True. 236 '''Data ports owned by this component. 238 May be an empty list if this component has no data ports. Members are 239 of type @ref DataPort. 247 expected_type=list, required=
False)
252 '''Service ports owned by this component. 254 May be an empty list if this component has no service ports. Members 255 are of type @ref ServicePort. 260 @service_ports.setter
263 expected_type=list, required=
False)
268 '''The configuration sets in this component. 270 May be an empty list if this component has no configuration sets. 271 Members are of type @ref ConfigurationSet. 276 @configuration_sets.setter
279 expected_type=list, required=
False)
284 '''The execution contexts owned by this component. 286 May be an empty list if this component does not own any contexts. 287 Members are of type @ref ExecutionContext. 292 @execution_contexts.setter
295 expected_type=list, required=
False)
300 '''The list of participating components, if this component is a 303 Members are of type @ref Participant. 311 expected_type=list, required=
False)
316 '''Comment about the component. 318 A brief comment about the component. May or may not be displayed in 319 other tools. May be empty. 321 Part of the extended profile. 329 expected_type=[str, unicode], required=
False)
334 '''Display the component in graphical tools. 336 This value controls whether graphical tools will display this component 339 Part of the extended profile. 347 expected_type=bool, required=
False)
352 '''Specifies the position of the component in graphical tools. 354 Part of the extended profile. 362 expected_type=Location, required=
True)
367 '''Miscellaneous properties. 369 Stores key/value pair properties. 371 Part of the extended profile. 379 expected_type=dict, required=
False)
386 '''Finds a configuration set in the component by its ID. 388 @param id The ID of the configuration set to search for. 389 @return The ConfigurationSet object for the set, or None if it was not 402 '''Parse an xml.dom Node object representing a component into this 408 self.
id = node.getAttributeNS(RTS_NS,
'id')
409 self.
path_uri = node.getAttributeNS(RTS_NS,
'pathUri')
410 if node.hasAttributeNS(RTS_NS,
'activeConfigurationSet'):
412 'activeConfigurationSet')
418 required = node.getAttributeNS(RTS_NS,
'isRequired')
419 if required ==
'true' or required ==
'1':
423 self.
comment = node.getAttributeNS(RTS_EXT_NS,
'comment')
424 if node.hasAttributeNS(RTS_EXT_NS,
'visible'):
425 visible = node.getAttributeNS(RTS_EXT_NS,
'visible')
426 if visible.lower() ==
'true' or visible ==
'1':
432 for c
in node.getElementsByTagNameNS(RTS_NS,
'DataPorts'):
434 for c
in node.getElementsByTagNameNS(RTS_NS,
'ServicePorts'):
436 for c
in node.getElementsByTagNameNS(RTS_NS,
'ConfigurationSets'):
438 for c
in node.getElementsByTagNameNS(RTS_NS,
'ExecutionContexts'):
440 for c
in node.getElementsByTagNameNS(RTS_NS,
'Participants'):
443 c = node.getElementsByTagNameNS(RTS_EXT_NS,
'Location')
446 raise InvalidRtsProfileNodeError(
'Location')
449 local_name=
'Properties'):
456 '''Save this component into an xml.dom.Element object.''' 457 element.setAttributeNS(RTS_NS, RTS_NS_S +
'id', self.
id)
458 element.setAttributeNS(RTS_NS, RTS_NS_S +
'pathUri', self.
path_uri)
460 element.setAttributeNS(RTS_NS, RTS_NS_S +
'activeConfigurationSet',
462 element.setAttributeNS(RTS_NS, RTS_NS_S +
'instanceName',
464 element.setAttributeNS(RTS_NS, RTS_NS_S +
'compositeType',
466 element.setAttributeNS(RTS_NS, RTS_NS_S +
'isRequired',
469 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'comment',
471 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'visible',
474 new_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'DataPorts')
475 port.save_xml(doc, new_element)
476 element.appendChild(new_element)
478 new_element = doc.createElementNS(RTS_NS,
479 RTS_NS_S +
'ServicePorts')
480 port.save_xml(doc, new_element)
481 element.appendChild(new_element)
483 new_element = doc.createElementNS(RTS_NS,
484 RTS_NS_S +
'ConfigurationSets')
485 cs.save_xml(doc, new_element)
486 element.appendChild(new_element)
488 new_element = doc.createElementNS(RTS_NS,
489 RTS_NS_S +
'ExecutionContexts')
490 ec.save_xml(doc, new_element)
491 element.appendChild(new_element)
493 new_element = doc.createElementNS(RTS_NS,
494 RTS_NS_S +
'Participants')
495 p.save_xml(doc, new_element)
496 element.appendChild(new_element)
497 new_element = doc.createElementNS(RTS_EXT_NS,
498 RTS_EXT_NS_S +
'Location')
499 self._location.save_xml(doc, new_element)
500 element.appendChild(new_element)
502 new_prop_element = doc.createElementNS(RTS_EXT_NS,
503 RTS_EXT_NS_S +
'Properties')
505 element.appendChild(new_prop_element)
511 '''Parse a YAML specification of a component into this object.''' 515 if 'activeConfigurationSet' in y:
520 self.
compositeType = comp_type.from_string(y[
'compositeType'])
521 required = y[
'isRequired']
522 if required ==
'true' or required ==
'1':
526 if RTS_EXT_NS_YAML +
'comment' in y:
527 self.
comment = y[RTS_EXT_NS_YAML +
'comment']
529 if RTS_EXT_NS_YAML +
'visible' in y:
530 visible = y.get(RTS_EXT_NS_YAML +
'visible')
531 if visible ==
True or visible ==
'true' or visible ==
'True':
536 for p
in y.get(
'dataPorts'):
538 if 'servicePorts' in y:
539 for p
in y.get(
'servicePorts'):
541 if 'configurationSets' in y:
542 for p
in y.get(
'configurationSets'):
544 if 'executionContexts' in y:
545 for p
in y.get(
'executionContexts'):
547 if 'participants' in y:
548 for p
in y.get(
'participants'):
549 self._participants.append(Participant().
parse_yaml(p))
552 if RTS_EXT_NS_YAML +
'location' in y:
553 l = y[RTS_EXT_NS_YAML +
'location']
555 if RTS_EXT_NS_YAML +
'properties' in y:
556 for p
in y.get(RTS_EXT_NS_YAML +
'properties'):
571 RTS_EXT_NS_YAML +
'visible': str(self.
visible).lower()}
575 d[RTS_EXT_NS_YAML +
'comment'] = self.
comment 579 ports.append(p.to_dict())
581 d[
'dataPorts'] = ports
584 ports.append(p.to_dict())
586 d[
'servicePorts'] = ports
589 sets.append(cs.to_dict())
591 d[
'configurationSets'] = sets
594 ecs.append(ec.to_dict())
596 d[
'executionContexts'] = ecs
599 participants.append(p.to_dict())
601 d[
'participants'] = participants
603 d[RTS_EXT_NS_YAML +
'location'] = self._location.to_dict()
611 d[RTS_EXT_NS_YAML +
'properties'] = props
def parse_xml_node(self, node)
XML.
def _reset(self)
Internal functions.
def save_xml(self, doc, element)
def properties_to_xml(element, name, value=None)
def parse_properties_xml(node)
def execution_contexts(self)
def validate_attribute(attr, name, expected_type=None, required=False)
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
def __init__(self, id='', path_uri='', active_configuration_set='', instance_name='', composite_type=comp_type.NONE, is_required=False, comment='', visible=True, location=Location())
def parse_yaml(self, y)
YAML.
def indent_string(string, num_spaces=2)
def get_configuration_set_by_id(self, id)
API functions.
def configuration_sets(self)