participant.py
Go to the documentation of this file.
00001 # -*- Python -*-
00002 # -*- coding: utf-8 -*-
00003 
00004 '''rtsprofile
00005 
00006 Copyright (C) 2009-2010
00007     Geoffrey Biggs
00008     RT-Synthesis Research Group
00009     Intelligent Systems Research Institute,
00010     National Institute of Advanced Industrial Science and Technology (AIST),
00011     Japan
00012     All rights reserved.
00013 Licensed under the Eclipse Public License -v 1.0 (EPL)
00014 http://www.opensource.org/licenses/eclipse-1.0.txt
00015 
00016 File: participant.py
00017 
00018 Object representing a participating component.
00019 
00020 '''
00021 
00022 __version__ = '$Revision: $'
00023 # $Source$
00024 
00025 
00026 from rtsprofile import RTS_NS, RTS_NS_S
00027 from rtsprofile.exceptions import InvalidParticipantNodeError
00028 from rtsprofile.targets import TargetComponent
00029 
00030 
00031 ##############################################################################
00032 ## Participant object
00033 
00034 class Participant(object):
00035     '''This object contains a reference to a component object that is part of a
00036     composite component.
00037 
00038     '''
00039 
00040     def __init__(self, target_component=None):
00041         '''Constructor.
00042 
00043         @param target_component The target component of this participant.
00044         @type target_component TargetComponent
00045 
00046         '''
00047         validate_attribute(target_component, 'participant.target_component',
00048                            expected_type=TargetComponent, required=False)
00049         self._target_component = target_component
00050 
00051     def __str__(self):
00052         return str(self.target_component)
00053 
00054     @property
00055     def target_component(self):
00056         '''The target component of this participant.'''
00057         return self._target_component
00058 
00059     @target_component.setter
00060     def target_component(self, target_component):
00061         validate_attribute(target_component, 'participant.target_component',
00062                            expected_type=TargetComponent, required=True)
00063         self._target_component = target_component
00064 
00065     def parse_xml_node(self, node):
00066         '''Parse an xml.dom Node object representing a participant into this
00067         object.
00068 
00069         '''
00070         if node.getElementsByTagNameNS(RTS_NS, 'Participant').length != 1:
00071             raise InvalidParticipantNodeError
00072         self.target_component = TargetComponent().parse_xml_node(\
00073                 node.getElementsByTagNameNS(RTS_NS, 'Participant')[0])
00074         return self
00075 
00076     def parse_yaml_node(self, y):
00077         '''Parse a YAML specification of a participant into this object.'''
00078         if 'participant' not in y:
00079             raise InvalidParticipantNodeError
00080         self.target_component = TargetComponent().parse_yaml_node(y['participant'])
00081         return self
00082 
00083     def save_xml(self, doc, element):
00084         '''Save this participant into an xml.dom.Element object.'''
00085         new_element = doc.createElementNS(RTS_NS, RTS_NS_S + 'Participant')
00086         self.target_component.save_xml(doc, new_element)
00087         element.appendChild(new_element)
00088 
00089     def to_dict(self):
00090         '''Save this participant into a dictionary.'''
00091         return {'participant': self.target_component.to_dict()}
00092 
00093 
00094 # vim: tw=79
00095 


rtsprofile
Author(s): Geoffrey Biggs
autogenerated on Sun Mar 26 2017 03:39:43