participant.py
Go to the documentation of this file.
1 # -*- Python -*-
2 # -*- coding: utf-8 -*-
3 
4 '''rtsprofile
5 
6 Copyright (C) 2009-2010
7  Geoffrey Biggs
8  RT-Synthesis Research Group
9  Intelligent Systems Research Institute,
10  National Institute of Advanced Industrial Science and Technology (AIST),
11  Japan
12  All rights reserved.
13 Licensed under the Eclipse Public License -v 1.0 (EPL)
14 http://www.opensource.org/licenses/eclipse-1.0.txt
15 
16 File: participant.py
17 
18 Object representing a participating component.
19 
20 '''
21 
22 __version__ = '$Revision: $'
23 # $Source$
24 
25 
26 from rtsprofile import RTS_NS, RTS_NS_S
27 from rtsprofile.exceptions import InvalidParticipantNodeError
28 from rtsprofile.targets import TargetComponent
29 
30 
31 ##############################################################################
32 ## Participant object
33 
34 class Participant(object):
35  '''This object contains a reference to a component object that is part of a
36  composite component.
37 
38  '''
39 
40  def __init__(self, target_component=None):
41  '''Constructor.
42 
43  @param target_component The target component of this participant.
44  @type target_component TargetComponent
45 
46  '''
47  validate_attribute(target_component, 'participant.target_component',
48  expected_type=TargetComponent, required=False)
49  self._target_component = target_component
50 
51  def __str__(self):
52  return str(self.target_component)
53 
54  @property
55  def target_component(self):
56  '''The target component of this participant.'''
57  return self._target_component
58 
59  @target_component.setter
60  def target_component(self, target_component):
61  validate_attribute(target_component, 'participant.target_component',
62  expected_type=TargetComponent, required=True)
63  self._target_component = target_component
64 
65  def parse_xml_node(self, node):
66  '''Parse an xml.dom Node object representing a participant into this
67  object.
68 
69  '''
70  if node.getElementsByTagNameNS(RTS_NS, 'Participant').length != 1:
71  raise InvalidParticipantNodeError
73  node.getElementsByTagNameNS(RTS_NS, 'Participant')[0])
74  return self
75 
76  def parse_yaml_node(self, y):
77  '''Parse a YAML specification of a participant into this object.'''
78  if 'participant' not in y:
79  raise InvalidParticipantNodeError
80  self.target_component = TargetComponent().parse_yaml_node(y['participant'])
81  return self
82 
83  def save_xml(self, doc, element):
84  '''Save this participant into an xml.dom.Element object.'''
85  new_element = doc.createElementNS(RTS_NS, RTS_NS_S + 'Participant')
86  self.target_component.save_xml(doc, new_element)
87  element.appendChild(new_element)
88 
89  def to_dict(self):
90  '''Save this participant into a dictionary.'''
91  return {'participant': self.target_component.to_dict()}
92 
93 
94 # vim: tw=79
95 
TargetComponent object.
Definition: targets.py:37
def __init__(self, target_component=None)
Definition: participant.py:40
def validate_attribute(attr, name, expected_type=None, required=False)
Definition: utils.py:92
def save_xml(self, doc, element)
Definition: participant.py:83


rtsprofile
Author(s): Geoffrey Biggs
autogenerated on Fri Jun 7 2019 21:52:35