def parse_xml_node(self, node): '''Parse an xml.dom Node object representing a service port connector into this object. ''' self.connector_id = node.getAttributeNS(RTS_NS, 'connectorId') self.name = node.getAttributeNS(RTS_NS, 'name') if node.hasAttributeNS(RTS_NS, 'transMethod'): self.trans_method = node.getAttributeNS(RTS_NS, 'transMethod') else: self.trans_method = '' self.comment = node.getAttributeNS(RTS_EXT_NS, 'comment') if node.hasAttributeNS(RTS_EXT_NS, 'visible'): visible = node.getAttributeNS(RTS_EXT_NS, 'visible') if visible == 'true' or visible == '1': self.visible = True else: self.visible = False if node.getElementsByTagNameNS(RTS_NS, 'sourceServicePort').length != 1: raise InvalidServicePortConnectorNodeError self.source_service_port = TargetPort().parse_xml_node(\ node.getElementsByTagNameNS(RTS_NS, 'sourceServicePort')[0]) if node.getElementsByTagNameNS(RTS_NS, 'targetServicePort').length != 1: raise InvalidServicePortConnectorNodeError self.target_service_port = TargetPort().parse_xml_node(\ node.getElementsByTagNameNS(RTS_NS, 'targetServicePort')[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 __init__(self, connector_id='', name='', trans_method='', source_service_port=TargetPort(), target_service_port=TargetPort(), comment='', visible=True): '''Constructor. @param connector_id ID of the connector. @type connector_id str @param name Name of the connector. @type name str @param trans_method Transport method used by the ports. @type trans_method str @param source_service_port The source port in the connection. @type source_service_port TargetPort @param target_service_port The target port in the connection. @type target_service_port TargetPort @param comment A comment about the port connector. @type comment str @param visible If this connector is visible in graphical displays. @type visible bool ''' validate_attribute(connector_id, 'serviceport_connector.connectorID', expected_type=string_types(), required=False) self._connector_id = connector_id validate_attribute(name, 'serviceport_connector.name', expected_type=string_types(), required=False) self._name = name validate_attribute(trans_method, 'serviceport_connector.transMethod', expected_type=string_types(), required=False) self._trans_method = trans_method validate_attribute(source_service_port, 'serviceport_connector.sourceServicePort', expected_type=TargetPort, required=True) self._source_service_port = source_service_port validate_attribute(target_service_port, 'serviceport_connector.targetServicePort', expected_type=TargetPort, required=True) self._target_service_port = target_service_port 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 self._properties = {}
def parse_yaml(self, y): '''Parse a YAML specification of a data port connector into this object. ''' self.connector_id = y['connectorId'] self.name = y['name'] self.data_type = y['dataType'] self.interface_type = y['interfaceType'] self.data_flow_type = y['dataflowType'] if 'subscriptionType' in y: self.subscription_type = y['subscriptionType'] else: self.subscription_type = '' if 'pushInterval' in y: self.push_interval = float(y['pushInterval']) else: self.push_interval = 0.0 if RTS_EXT_NS_YAML + 'comment' in y: self.comment = y[RTS_EXT_NS_YAML + 'comment'] else: self.comment = '' if RTS_EXT_NS_YAML + 'visible' in y: visible = y[RTS_EXT_NS_YAML + 'visible'] if visible == True or visible == 'true' or visible == '1': self.visible = True else: self.visible = False if not 'sourceDataPort' in y: raise InvalidDataPortConnectorNodeError self.source_data_port = \ TargetPort().parse_yaml(y['sourceDataPort']) if not 'targetDataPort' in y: raise InvalidDataPortConnectorNodeError self.target_data_port = \ TargetPort().parse_yaml(y['targetDataPort']) if RTS_EXT_NS_YAML + 'properties' in y: for p in y[RTS_EXT_NS_YAML + 'properties']: if 'value' in p: value = p['value'] else: value = None self._properties[p['name']] = value return self
def parse_xml_node(self, node): '''Parse an xml.dom Node object representing a data connector into this object. ''' self.connector_id = node.getAttributeNS(RTS_NS, 'connectorId') self.name = node.getAttributeNS(RTS_NS, 'name') self.data_type = node.getAttributeNS(RTS_NS, 'dataType') self.interface_type = node.getAttributeNS(RTS_NS, 'interfaceType') self.data_flow_type = node.getAttributeNS(RTS_NS, 'dataflowType') if node.hasAttributeNS(RTS_NS, 'subscriptionType'): self.subscription_type = node.getAttributeNS(RTS_NS, 'subscriptionType') else: self.subscription_type = '' if node.hasAttributeNS(RTS_NS, 'pushInterval'): self.push_interval = float(node.getAttributeNS(RTS_NS, 'pushInterval')) else: self.push_interval = 0.0 self.comment = node.getAttributeNS(RTS_EXT_NS, 'comment') if node.hasAttributeNS(RTS_EXT_NS, 'visible'): visible = node.getAttributeNS(RTS_EXT_NS, 'visible') if visible == 'true' or visible == '1': self.visible = True else: self.visible = False if node.getElementsByTagNameNS(RTS_NS, 'sourceDataPort').length != 1: raise InvalidDataPortConnectorNodeError self.source_data_port = TargetPort().parse_xml_node(\ node.getElementsByTagNameNS(RTS_NS, 'sourceDataPort')[0]) if node.getElementsByTagNameNS(RTS_NS, 'targetDataPort').length != 1: raise InvalidDataPortConnectorNodeError self.target_data_port = TargetPort().parse_xml_node(\ node.getElementsByTagNameNS(RTS_NS, 'targetDataPort')[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 service port connector into this object. ''' self.connector_id = y['connectorId'] self.name = y['name'] if 'transMethod' in y: self.trans_method = y['transMethod'] else: self.trans_method = '' if RTS_EXT_NS_YAML + 'comment' in y: self.comment = y[RTS_EXT_NS_YAML + 'comment'] else: self.comment = '' if RTS_EXT_NS_YAML + 'visible' in y: visible = y[RTS_EXT_NS_YAML + 'visible'] if visible == True or visible == 'true' or visible == '1': self.visible = True else: self.visible = False if 'sourceServicePort' not in y: raise InvalidServicePortConnectorNodeError self.source_service_port = \ TargetPort().parse_yaml(y['sourceServicePort']) if 'targetServicePort' not in y: raise InvalidServicePortConnectorNodeError self.target_service_port = \ TargetPort().parse_yaml(y['targetServicePort']) if RTS_EXT_NS_YAML + 'properties' in y: for p in y[RTS_EXT_NS_YAML + 'properties']: if 'value' in p: value = p['value'] else: value = None self._properties[p['name']] = value return self
def __init__(self, connector_id='', name='', data_type='', interface_type='', data_flow_type='', subscription_type='', push_interval=0.0, source_data_port=TargetPort(), target_data_port=TargetPort(), comment='', visible=True): '''Constructor. @param connector_id ID of the connector. @type connector_id str @param name Name of the connector. @type name str @param data_type Data type that this connector transports. @type data_type str @param interface_type Interface type of the connected ports. @type interface_type str @param data_flow_type Type of data flow between the ports. @type data_flow_type str @param subscription_type Type of subscription between the ports. @type subscription_type str @param push_interval Rate at which data is sent between the ports. @type push_interval float @param source_data_port The source port in the connection. @type source_data_port TargetPort @param target_data_port The target port in the connection. @type target_data_port TargetPort @param comment A comment about the port connector. @type comment str @param visible If this connector is visible in graphical displays. @type visible bool ''' validate_attribute(connector_id, 'dataport_connector.connectorID', expected_type=string_types(), required=False) self._connector_id = connector_id validate_attribute(name, 'dataport_connector.name', expected_type=string_types(), required=False) self._name = name validate_attribute(data_type, 'dataport_connector.dataType', expected_type=string_types(), required=False) self._data_type = data_type validate_attribute(interface_type, 'dataport_connector.interfaceType', expected_type=string_types(), required=False) self._interface_type = interface_type validate_attribute(data_flow_type, 'dataport_connector.dataflowType', expected_type=string_types(), required=False) self._data_flow_type = data_flow_type validate_attribute(subscription_type, 'dataport_connector.subscriptionType', expected_type=string_types(), required=False) self._subscription_type = subscription_type validate_attribute(push_interval, 'dataport_connector.pushInterval', expected_type=[int, float], required=False) self._push_interval = push_interval validate_attribute(source_data_port, 'dataport_connector.sourceDataPort', expected_type=TargetPort, required=False) self._source_data_port = source_data_port validate_attribute(target_data_port, 'dataport_connector.targetDataPort', expected_type=TargetPort, required=False) self._target_data_port = target_data_port 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 self._properties = {}