예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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