def parse_xml_node(self, node): '''Parse an xml.dom Node object representing a component into this object. >>> c = Component() ''' self._reset() # Get the attributes self.id = node.getAttributeNS(RTS_NS, 'id') self.path_uri = node.getAttributeNS(RTS_NS, 'pathUri') if node.hasAttributeNS(RTS_NS, 'activeConfigurationSet'): self.active_configuration_set = node.getAttributeNS( RTS_NS, 'activeConfigurationSet') else: self.active_configuration_set = '' self.instance_name = node.getAttributeNS(RTS_NS, 'instanceName') self.compositeType = comp_type.from_string( node.getAttributeNS(RTS_NS, 'compositeType')) required = node.getAttributeNS(RTS_NS, 'isRequired') if required == 'true' or required == '1': self.is_required = True else: self.is_required = False self.comment = node.getAttributeNS(RTS_EXT_NS, 'comment') if node.hasAttributeNS(RTS_EXT_NS, 'visible'): visible = node.getAttributeNS(RTS_EXT_NS, 'visible') if visible.lower() == 'true' or visible == '1': self.visible = True else: self.visible = False # Get the children for c in node.getElementsByTagNameNS(RTS_NS, 'DataPorts'): self._data_ports.append(DataPort().parse_xml_node(c)) for c in node.getElementsByTagNameNS(RTS_NS, 'ServicePorts'): self._service_ports.append(ServicePort().parse_xml_node(c)) for c in node.getElementsByTagNameNS(RTS_NS, 'ConfigurationSets'): self._config_sets.append(ConfigurationSet().parse_xml_node(c)) for c in node.getElementsByTagNameNS(RTS_NS, 'ExecutionContexts'): self._exec_contexts.append(ExecutionContext().parse_xml_node(c)) for c in node.getElementsByTagNameNS(RTS_NS, 'Participants'): self._participants.append(Participant().parse_xml_node(c)) # Extended profile children c = node.getElementsByTagNameNS(RTS_EXT_NS, 'Location') if c.length > 0: if c.length > 1: raise InvalidRtsProfileNodeError('Location') self._location = Location().parse_xml_node(c[0]) for c in get_direct_child_elements_xml(node, prefix=RTS_EXT_NS, local_name='Properties'): name, value = parse_properties_xml(c) self._properties[name] = value return self
def parse_yaml(self, y): '''Parse a YAML specification of a component into this object.''' self._reset() self.id = y['id'] self.path_uri = y['pathUri'] if 'activeConfigurationSet' in y: self.active_configuration_set = y['activeConfigurationSet'] else: self.active_configuration_set = '' self.instance_name = y['instanceName'] self.compositeType = comp_type.from_string(y['compositeType']) required = y['isRequired'] if required == True or required == 'true' or required == '1': self.is_required = True else: self.is_required = False if RTS_EXT_NS_YAML + 'comment' in y: self.comment = y[RTS_EXT_NS_YAML + 'comment'] self.visible = False if RTS_EXT_NS_YAML + 'visible' in y: visible = y.get(RTS_EXT_NS_YAML + 'visible') if visible == True or visible == 'true' or visible == 'True': self.visible = True # Get the children if 'dataPorts' in y: for p in y.get('dataPorts'): self._data_ports.append(DataPort().parse_yaml(p)) if 'servicePorts' in y: for p in y.get('servicePorts'): self._service_ports.append(ServicePort().parse_yaml(p)) if 'configurationSets' in y: for p in y.get('configurationSets'): self._config_sets.append(ConfigurationSet().parse_yaml(p)) if 'executionContexts' in y: for p in y.get('executionContexts'): self._exec_contexts.append(ExecutionContext().parse_yaml(p)) if 'participants' in y: for p in y.get('participants'): self._participants.append(Participant().parse_yaml(p)) # Extended profile children if RTS_EXT_NS_YAML + 'location' in y: l = y[RTS_EXT_NS_YAML + 'location'] self._location = Location().parse_yaml(l) if RTS_EXT_NS_YAML + 'properties' in y: for p in y.get(RTS_EXT_NS_YAML + 'properties'): if 'value' in p: value = p['value'] else: value = None self._properties[p['name']] = value return self
def _reset(self): # Clears all values in the class in preparation for parsing an XML # file. # Attributes self._id = '' self._path_uri = '' self._active_config_set = '' self._instance_name = '' self._composite_type = comp_type.NONE self._is_required = False # Children self._data_ports = [] self._service_ports = [] self._config_sets = [] self._exec_contexts = [] self._participants = [] # Extended spec self._comment = '' self._visible = True self._location = Location() self._properties = {}
def __init__(self, id='', path_uri='', active_configuration_set='', instance_name='', composite_type=comp_type.NONE, is_required=False, comment='', visible=True, location=Location()): '''@param id Component ID. @type id str @param path_uri Path to the component. @type path_uri str @param active_configuration_set Name of the active configuration set. @type active_configuration_set str @param instance_name Component's instance name. @type instance_name str @param composite_type Type of composition the component is in. @type composite_type CompositeType @param is_required If the component is optional in the system. @type is_required bool @param comment A comment about the component. @type comment str @param visible If this component is visible in graphical displays. @type visible bool @param location The location of this component in graphical displays. @type location Location ''' self._reset() validate_attribute(id, 'component.id', expected_type=string_types(), required=False) self._id = id validate_attribute(path_uri, 'component.pathUri', expected_type=string_types(), required=False) self._path_uri = path_uri validate_attribute(active_configuration_set, 'component.activeConfigurationSet', expected_type=string_types(), required=False) self._active_config_set = active_configuration_set validate_attribute(instance_name, 'component.instanceName', expected_type=string_types(), required=False) self._instance_name = instance_name validate_attribute(composite_type, 'component.compositeType', expected_type=comp_type.const_type, required=False) self._composite_type = composite_type validate_attribute(is_required, 'component.isRequired', expected_type=bool) self._is_required = is_required validate_attribute(comment, 'component.ext.comment', expected_type=string_types(), required=False) self._comment = comment validate_attribute(visible, 'component.ext.visible', expected_type=bool, required=False) self._visible = visible validate_attribute(location, 'component.ext.Location', expected_type=Location, required=True) self._location = location