port_connectors.py
Go to the documentation of this file.
1 # -*- Python -*- # -*- coding: utf-8 -*-
2 
3 '''rtsprofile
4 
5 Copyright (C) 2009-2010
6  Geoffrey Biggs
7  RT-Synthesis Research Group
8  Intelligent Systems Research Institute,
9  National Institute of Advanced Industrial Science and Technology (AIST),
10  Japan
11  All rights reserved.
12 Licensed under the Eclipse Public License -v 1.0 (EPL)
13 http://www.opensource.org/licenses/eclipse-1.0.txt
14 
15 File: data_port_connector.py
16 
17 Objects representing connections between data and service ports.
18 
19 '''
20 
21 __version__ = '$Revision: $'
22 # $Source$
23 
24 
25 from rtsprofile import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
26  RTS_EXT_NS_YAML
27 from rtsprofile.exceptions import InvalidDataPortConnectorNodeError, \
28  InvalidServicePortConnectorNodeError
29 from rtsprofile.targets import TargetPort
30 from rtsprofile.utils import get_direct_child_elements_xml, \
31  indent_string, parse_properties_xml, \
32  properties_to_xml, validate_attribute
33 
34 
35 ##############################################################################
36 ## DataPortConnector object
37 
38 class DataPortConnector(object):
39  '''Represents a connection between data ports.'''
40 
41  def __init__(self, connector_id='', name='', data_type='',
42  interface_type='', data_flow_type='', subscription_type='',
43  push_interval=0.0, source_data_port=TargetPort(),
44  target_data_port=TargetPort(), comment='', visible=True):
45  '''Constructor.
46 
47  @param connector_id ID of the connector.
48  @type connector_id str
49  @param name Name of the connector.
50  @type name str
51  @param data_type Data type that this connector transports.
52  @type data_type str
53  @param interface_type Interface type of the connected ports.
54  @type interface_type str
55  @param data_flow_type Type of data flow between the ports.
56  @type data_flow_type str
57  @param subscription_type Type of subscription between the ports.
58  @type subscription_type str
59  @param push_interval Rate at which data is sent between the ports.
60  @type push_interval float
61  @param source_data_port The source port in the connection.
62  @type source_data_port TargetPort
63  @param target_data_port The target port in the connection.
64  @type target_data_port TargetPort
65  @param comment A comment about the port connector.
66  @type comment str
67  @param visible If this connector is visible in graphical displays.
68  @type visible bool
69 
70  '''
71  validate_attribute(connector_id, 'dataport_connector.connectorID',
72  expected_type=[str, unicode], required=False)
73  self._connector_id = connector_id
74  validate_attribute(name, 'dataport_connector.name',
75  expected_type=[str, unicode], required=False)
76  self._name = name
77  validate_attribute(data_type, 'dataport_connector.dataType',
78  expected_type=[str, unicode], required=False)
79  self._data_type = data_type
80  validate_attribute(interface_type, 'dataport_connector.interfaceType',
81  expected_type=[str, unicode], required=False)
82  self._interface_type = interface_type
83  validate_attribute(data_flow_type, 'dataport_connector.dataflowType',
84  expected_type=[str, unicode], required=False)
85  self._data_flow_type = data_flow_type
86  validate_attribute(subscription_type,
87  'dataport_connector.subscriptionType',
88  expected_type=[str, unicode], required=False)
89  self._subscription_type = subscription_type
90  validate_attribute(push_interval, 'dataport_connector.pushInterval',
91  expected_type=[int, float], required=False)
92  self._push_interval = push_interval
93  validate_attribute(source_data_port,
94  'dataport_connector.sourceDataPort',
95  expected_type=TargetPort, required=False)
96  self._source_data_port = source_data_port
97  validate_attribute(target_data_port,
98  'dataport_connector.targetDataPort',
99  expected_type=TargetPort, required=False)
100  self._target_data_port = target_data_port
101  validate_attribute(comment, 'component.ext.comment',
102  expected_type=[str, unicode], required=False)
103  self._comment = comment
104  validate_attribute(visible, 'component.ext.visible',
105  expected_type=bool, required=False)
106  self._visible = visible
107  self._properties = {}
108 
109  def __str__(self):
110  result = 'Name: {1}\n Connector ID: {0}\n Data type: {2}\n \
111 Interface type: {3}\n Data flow type: {4}\n Subscription type: {5}\n Push \
112 interval: {6}\n Source data port:\n{7}\n Target data port:\n{8}\n'.format(\
113  self.connector_id, self.name, self.data_type, self.interface_type,
115  indent_string(str(self.source_data_port), num_spaces=4),
116  indent_string(str(self.target_data_port), num_spaces=4))
117  if self.comment:
118  result += 'Comment: {0}\n'.format(self.comment)
119  result += 'Visible: {0}\n'.format(self.visible)
120  if self.properties:
121  result += 'Properties:\n'
122  for p in self.properties:
123  result += ' {0}: {1}\n'.format(p, self.properties[p])
124  return result[:-1] # Lop off the last new line
125 
126  @property
127  def connector_id(self):
128  '''The ID of the connector used to distinguish it in the RT system.'''
129  return self._connector_id
130 
131  @connector_id.setter
132  def connector_id(self, connector_id):
133  validate_attribute(connector_id, 'dataport_connector.connectorID',
134  expected_type=[str, unicode], required=True)
135  self._connector_id = connector_id
136 
137  @property
138  def name(self):
139  '''The name of the connector.'''
140  return self._name
141 
142  @name.setter
143  def name(self, name):
144  validate_attribute(name, 'dataport_connector.name',
145  expected_type=[str, unicode], required=True)
146  self._name = name
147 
148  @property
149  def data_type(self):
150  '''Data type that this connector transports.'''
151  return self._data_type
152 
153  @data_type.setter
154  def data_type(self, data_type):
155  validate_attribute(data_type, 'dataport_connector.dataType',
156  expected_type=[str, unicode], required=True)
157  self._data_type = data_type
158 
159  @property
160  def interface_type(self):
161  '''Interface type of the connection.
162 
163  As specified when the RT system is created. Dependent on what the RT
164  Middleware used to execute the RT system supports.
165 
166  '''
167  return self._interface_type
168 
169  @interface_type.setter
170  def interface_type(self, interface_type):
171  validate_attribute(interface_type, 'dataport_connector.interfaceType',
172  expected_type=[str, unicode], required=True)
173  self._interface_type = interface_type
174 
175  @property
176  def data_flow_type(self):
177  '''Type of data flow between the ports.
178 
179  As specified when the RT system is created. Dependent on what the RT
180  Middleware used to execute the RT system supports.
181 
182  '''
183  return self._data_flow_type
184 
185  @data_flow_type.setter
186  def data_flow_type(self, data_flow_type):
187  validate_attribute(data_flow_type, 'dataport_connector.dataflowType',
188  expected_type=[str, unicode], required=True)
189  self._data_flow_type = data_flow_type
190 
191  @property
192  def subscription_type(self):
193  '''Type of the subscription between the ports.
194 
195  As specified when the RT system is created. Only used when @ref
196  data_flow_type is set to PUSH. Dependent on what the RT Middleware used
197  to execute the RT system supports.
198 
199  '''
200  return self._subscription_type
201 
202  @subscription_type.setter
203  def subscription_type(self, subscription_type):
204  validate_attribute(subscription_type,
205  'dataport_connector.subscriptionType',
206  expected_type=[str, unicode], required=False)
207  self._subscription_type = subscription_type
208 
209  @property
210  def push_interval(self):
211  '''Rate at which data is sent between ports.
212 
213  As specified when the RT system is created.
214 
215  '''
216  return self._push_interval
217 
218  @push_interval.setter
219  def push_interval(self, push_interval):
220  validate_attribute(push_interval, 'dataport_connector.pushInterval',
221  expected_type=[int, float], required=False)
222  self._push_interval = push_interval
223 
224  @property
225  def source_data_port(self):
226  '''The source port in the connection.'''
227  return self._source_data_port
228 
229  @source_data_port.setter
230  def source_data_port(self, source_data_port):
231  validate_attribute(source_data_port,
232  'dataport_connector.sourceDataPort',
233  expected_type=TargetPort, required=True)
234  self._source_data_port = source_data_port
235 
236  @property
237  def target_data_port(self):
238  '''The target port in the connection.'''
239  return self._target_data_port
240 
241  @target_data_port.setter
242  def target_data_port(self, target_data_port):
243  validate_attribute(target_data_port,
244  'dataport_connector.targetDataPort',
245  expected_type=TargetPort, required=True)
246  self._target_data_port = target_data_port
247 
248  @property
249  def comment(self):
250  '''Comment about the connector.
251 
252  A brief comment about the connector. May or may not be displayed in
253  other tools. May be empty.
254 
255  Part of the extended profile.
256 
257  '''
258  return self._comment
259 
260  @comment.setter
261  def comment(self, comment):
262  validate_attribute(comment, 'dataport_connector.ext.comment',
263  expected_type=[str, unicode], required=False)
264  self._comment = comment
265 
266  @property
267  def visible(self):
268  '''Display the connector in graphical tools.
269 
270  This value controls whether graphical tools will display this connector
271  or not.
272 
273  Part of the extended profile.
274 
275  '''
276  return self._visible
277 
278  @visible.setter
279  def visible(self, visible):
280  validate_attribute(visible, 'dataport_connector.ext.visible',
281  expected_type=bool, required=False)
282  self._visible = visible
283 
284  @property
285  def properties(self):
286  '''Miscellaneous properties.
287 
288  Stores key/value pair properties.
289 
290  Part of the extended profile.
291 
292  '''
293  return self._properties
294 
295  @properties.setter
296  def properties(self, properties):
297  validate_attribute(properties, 'dataport_connector.ext.Properties',
298  expected_type=dict, required=False)
299  self._properties = properties
300 
301  def parse_xml_node(self, node):
302  '''Parse an xml.dom Node object representing a data connector into this
303  object.
304 
305  '''
306  self.connector_id = node.getAttributeNS(RTS_NS, 'connectorId')
307  self.name = node.getAttributeNS(RTS_NS, 'name')
308  self.data_type = node.getAttributeNS(RTS_NS, 'dataType')
309  self.interface_type = node.getAttributeNS(RTS_NS, 'interfaceType')
310  self.data_flow_type = node.getAttributeNS(RTS_NS, 'dataflowType')
311  if node.hasAttributeNS(RTS_NS, 'subscriptionType'):
312  self.subscription_type = node.getAttributeNS(RTS_NS,
313  'subscriptionType')
314  else:
315  self.subscription_type = ''
316  if node.hasAttributeNS(RTS_NS, 'pushInterval'):
317  self.push_interval = float(node.getAttributeNS(RTS_NS,
318  'pushInterval'))
319  else:
320  self.push_interval = 0.0
321  self.comment = node.getAttributeNS(RTS_EXT_NS, 'comment')
322  if node.hasAttributeNS(RTS_EXT_NS, 'visible'):
323  visible = node.getAttributeNS(RTS_EXT_NS, 'visible')
324  if visible == 'true' or visible == '1':
325  self.visible = True
326  else:
327  self.visible = False
328 
329  if node.getElementsByTagNameNS(RTS_NS, 'sourceDataPort').length != 1:
330  raise InvalidDataPortConnectorNodeError
332  node.getElementsByTagNameNS(RTS_NS, 'sourceDataPort')[0])
333  if node.getElementsByTagNameNS(RTS_NS, 'targetDataPort').length != 1:
334  raise InvalidDataPortConnectorNodeError
336  node.getElementsByTagNameNS(RTS_NS, 'targetDataPort')[0])
337  for c in get_direct_child_elements_xml(node, prefix=RTS_EXT_NS,
338  local_name='Properties'):
339  name, value = parse_properties_xml(c)
340  self._properties[name] = value
341  return self
342 
343  def parse_yaml(self, y):
344  '''Parse a YAML specification of a data port connector into this
345  object.
346 
347  '''
348  self.connector_id = y['connectorId']
349  self.name = y['name']
350  self.data_type = y['dataType']
351  self.interface_type = y['interfaceType']
352  self.data_flow_type = y['dataflowType']
353  if 'subscriptionType' in y:
354  self.subscription_type = y['subscriptionType']
355  else:
356  self.subscription_type = ''
357  if 'pushInterval' in y:
358  self.push_interval = float(y['pushInterval'])
359  else:
360  self.push_interval = 0.0
361  if RTS_EXT_NS_YAML + 'comment' in y:
362  self.comment = y[RTS_EXT_NS_YAML + 'comment']
363  else:
364  self.comment = ''
365  self.visible = False
366  if RTS_EXT_NS_YAML + 'visible' in y:
367  visible = y[RTS_EXT_NS_YAML + 'visible']
368  if visible == 'true' or visible == '1':
369  self.visible = True
370  if not 'sourceDataPort' in y:
371  raise InvalidDataPortConnectorNodeError
372  self.source_data_port = \
373  TargetPort().parse_yaml(y['sourceDataPort'])
374  if not 'targetDataPort' in y:
375  raise InvalidDataPortConnectorNodeError
376  self.target_data_port = \
377  TargetPort().parse_yaml(y['targetDataPort'])
378  if RTS_EXT_NS_YAML + 'properties' in y:
379  for p in y[RTS_EXT_NS_YAML + 'properties']:
380  if 'value' in p:
381  value = p['value']
382  else:
383  value = None
384  self._properties[p['name']] = value
385  return self
386 
387  def save_xml(self, doc, element):
388  '''Save this data port into an xml.dom.Element object.'''
389  element.setAttributeNS(RTS_NS, RTS_NS_S + 'connectorId',
390  self.connector_id)
391  element.setAttributeNS(RTS_NS, RTS_NS_S + 'name', self.name)
392  element.setAttributeNS(RTS_NS, RTS_NS_S + 'dataType', self.data_type)
393  element.setAttributeNS(RTS_NS, RTS_NS_S + 'interfaceType',
394  self.interface_type)
395  element.setAttributeNS(RTS_NS, RTS_NS_S + 'dataflowType',
396  self.data_flow_type)
397  if self.subscription_type:
398  element.setAttributeNS(RTS_NS, RTS_NS_S + 'subscriptionType',
399  self.subscription_type)
400  element.setAttributeNS(RTS_NS, RTS_NS_S + 'pushInterval',
401  str(self.push_interval))
402  if self.comment:
403  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'comment',
404  self.comment)
405  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'visible',
406  str(self.visible).lower())
407  new_element = doc.createElementNS(RTS_NS, RTS_NS_S + 'sourceDataPort')
408  self.source_data_port.save_xml(doc, new_element)
409  element.appendChild(new_element)
410  new_element = doc.createElementNS(RTS_NS, RTS_NS_S + 'targetDataPort')
411  self.target_data_port.save_xml(doc, new_element)
412  element.appendChild(new_element)
413  for p in self.properties:
414  new_prop_element = doc.createElementNS(RTS_EXT_NS,
415  RTS_EXT_NS + 'Properties')
416  properties_to_xml(new_prop_element, p, self.properties[p])
417  element.appendChild(new_prop_element)
418 
419  def to_dict(self):
420  '''Save this data port connector into a dictionary.'''
421  d = {'connectorId': self.connector_id,
422  'name': self.name,
423  'dataType': self.data_type,
424  'interfaceType': self.interface_type,
425  'dataflowType': self.data_flow_type,
426  RTS_EXT_NS_YAML + 'visible': str(self.visible).lower(),
427  'sourceDataPort': self.source_data_port.to_dict(),
428  'targetDataPort': self.target_data_port.to_dict()}
429  if self.subscription_type:
430  d['subscriptionType'] = self.subscription_type
431  if self.push_interval:
432  d['pushInterval'] = self.push_interval
433  if self.comment:
434  d[RTS_EXT_NS_YAML + 'comment'] = self.comment
435  props = []
436  for name in self.properties:
437  p = {'name': name}
438  if self.properties[name]:
439  p['value'] = str(self.properties[name])
440  props.append(p)
441  if props:
442  d[RTS_EXT_NS_YAML + 'properties'] = props
443  return d
444 
445 
446 ##############################################################################
447 ## ServicePortConnector object
448 
449 class ServicePortConnector(object):
450  '''Represents a connection between service ports.'''
451 
452  def __init__(self, connector_id='', name='', trans_method='',
453  source_service_port=TargetPort(),
454  target_service_port=TargetPort(), comment='', visible=True):
455  '''Constructor.
456 
457  @param connector_id ID of the connector.
458  @type connector_id str
459  @param name Name of the connector.
460  @type name str
461  @param trans_method Transport method used by the ports.
462  @type trans_method str
463  @param source_service_port The source port in the connection.
464  @type source_service_port TargetPort
465  @param target_service_port The target port in the connection.
466  @type target_service_port TargetPort
467  @param comment A comment about the port connector.
468  @type comment str
469  @param visible If this connector is visible in graphical displays.
470  @type visible bool
471 
472  '''
473  validate_attribute(connector_id, 'serviceport_connector.connectorID',
474  expected_type=[str, unicode], required=False)
475  self._connector_id = connector_id
476  validate_attribute(name, 'serviceport_connector.name',
477  expected_type=[str, unicode], required=False)
478  self._name = name
479  validate_attribute(trans_method, 'serviceport_connector.transMethod',
480  expected_type=[str, unicode], required=False)
481  self._trans_method = trans_method
482  validate_attribute(source_service_port,
483  'serviceport_connector.sourceServicePort',
484  expected_type=TargetPort, required=True)
485  self._source_service_port = source_service_port
486  validate_attribute(target_service_port,
487  'serviceport_connector.targetServicePort',
488  expected_type=TargetPort, required=True)
489  self._target_service_port = target_service_port
490  validate_attribute(comment, 'component.ext.comment',
491  expected_type=[str, unicode], required=False)
492  self._comment = comment
493  validate_attribute(visible, 'component.ext.visible',
494  expected_type=bool, required=False)
495  self._visible = visible
496  self._properties = {}
497 
498 
499  def __str__(self):
500  result = 'Name: {1}\n Connector ID: {0}\n Trans method: {2}\n \
501 Source data port:\n{3}\n Target data port:\n{4}'.format(self.connector_id,
502  self.name, self.trans_method,
503  indent_string(str(self.source_service_port), num_spaces=4),
504  indent_string(str(self.target_service_port), num_spaces=4))
505  if self.comment:
506  result += 'Comment: {0}\n'.format(self.comment)
507  result += 'Visible: {0}\n'.format(self.visible)
508  if self.properties:
509  result += 'Properties:\n'
510  for p in self.properties:
511  result += ' {0}: {1}\n'.format(p, self.properties[p])
512  return result[:-1] # Lop off the last new line
513 
514  @property
515  def connector_id(self):
516  '''The ID of the connector used to distinguish it in the RT system.'''
517  return self._connector_id
518 
519  @connector_id.setter
520  def connector_id(self, connector_id):
521  validate_attribute(connector_id, 'serviceport_connector.connectorID',
522  expected_type=[str, unicode], required=True)
523  self._connector_id = connector_id
524 
525  @property
526  def name(self):
527  '''The name of the connector.'''
528  return self._name
529 
530  @name.setter
531  def name(self, name):
532  validate_attribute(name, 'serviceport_connector.name',
533  expected_type=[str, unicode], required=True)
534  self._name = name
535 
536  @property
537  def trans_method(self):
538  '''Transport method used by the ports.
539 
540  As specified when the RT system is created. Dependent on what the RT
541  Middleware used to execute the RT system supports.
542 
543  '''
544  return self._trans_method
545 
546  @trans_method.setter
547  def trans_method(self, trans_method):
548  validate_attribute(trans_method, 'serviceport_connector.transMethod',
549  expected_type=[str, unicode], required=False)
550  self._trans_method = trans_method
551 
552  @property
554  '''The source port in the connection.'''
555  return self._source_service_port
556 
557  @source_service_port.setter
558  def source_service_port(self, source_service_port):
559  validate_attribute(source_service_port,
560  'serviceport_connector.sourceServicePort',
561  expected_type=TargetPort, required=True)
562  self._source_service_port = source_service_port
563 
564  @property
566  '''The target port in the connection.'''
567  return self._target_service_port
568 
569  @target_service_port.setter
570  def target_service_port(self, target_service_port):
571  validate_attribute(target_service_port,
572  'serviceport_connector.targetServicePort',
573  expected_type=TargetPort, required=True)
574  self._target_service_port = target_service_port
575 
576  @property
577  def comment(self):
578  '''Comment about the connector.
579 
580  A brief comment about the connector. May or may not be displayed in
581  other tools. May be empty.
582 
583  Part of the extended profile.
584 
585  '''
586  return self._comment
587 
588  @comment.setter
589  def comment(self, comment):
590  validate_attribute(comment, 'serviceport_connector.ext.comment',
591  expected_type=[str, unicode], required=False)
592  self._comment = comment
593 
594  @property
595  def visible(self):
596  '''Display the connector in graphical tools.
597 
598  This value controls whether graphical tools will display this connector
599  or not.
600 
601  Part of the extended profile.
602 
603  '''
604  return self._visible
605 
606  @visible.setter
607  def visible(self, visible):
608  validate_attribute(visible, 'serviceport_connector.ext.visible',
609  expected_type=bool, required=False)
610  self._visible = visible
611 
612  @property
613  def properties(self):
614  '''Miscellaneous properties.
615 
616  Stores key/value pair properties.
617 
618  Part of the extended profile.
619 
620  '''
621  return self._properties
622 
623  @properties.setter
624  def properties(self, properties):
625  validate_attribute(properties, 'serviceport_connector.ext.Properties',
626  expected_type=dict, required=False)
627  self._properties = properties
628 
629  def parse_xml_node(self, node):
630  '''Parse an xml.dom Node object representing a service port connector into
631  this object.
632 
633  '''
634  self.connector_id = node.getAttributeNS(RTS_NS, 'connectorId')
635  self.name = node.getAttributeNS(RTS_NS, 'name')
636  if node.hasAttributeNS(RTS_NS, 'transMethod'):
637  self.trans_method = node.getAttributeNS(RTS_NS,
638  'transMethod')
639  else:
640  self.trans_method = ''
641  self.comment = node.getAttributeNS(RTS_EXT_NS, 'comment')
642  if node.hasAttributeNS(RTS_EXT_NS, 'visible'):
643  visible = node.getAttributeNS(RTS_EXT_NS, 'visible')
644  if visible == 'true' or visible == '1':
645  self.visible = True
646  else:
647  self.visible = False
648 
649  if node.getElementsByTagNameNS(RTS_NS, 'sourceServicePort').length != 1:
650  raise InvalidServicePortConnectorNodeError
652  node.getElementsByTagNameNS(RTS_NS, 'sourceServicePort')[0])
653  if node.getElementsByTagNameNS(RTS_NS, 'targetServicePort').length != 1:
654  raise InvalidServicePortConnectorNodeError
656  node.getElementsByTagNameNS(RTS_NS, 'targetServicePort')[0])
657  for c in get_direct_child_elements_xml(node, prefix=RTS_EXT_NS,
658  local_name='Properties'):
659  name, value = parse_properties_xml(c)
660  self._properties[name] = value
661  return self
662 
663  def parse_yaml(self, y):
664  '''Parse a YAML specification of a service port connector into this
665  object.
666 
667  '''
668  self.connector_id = y['connectorId']
669  self.name = y['name']
670  if 'transMethod' in y:
671  self.trans_method = y['transMethod']
672  else:
673  self.trans_method = ''
674  if RTS_EXT_NS_YAML + 'comment' in y:
675  self.comment = y[RTS_EXT_NS_YAML + 'comment']
676  else:
677  self.comment = ''
678  self.visible = False
679  if RTS_EXT_NS_YAML + 'visible' in y:
680  visible = y[RTS_EXT_NS_YAML + 'visible']
681  if visible == 'true' or visible == '1':
682  self.visible = True
683  if 'sourceServicePort' not in y:
684  raise InvalidServicePortConnectorNodeError
685  self.source_service_port = \
686  TargetPort().parse_yaml(y['sourceServicePort'])
687  if 'targetServicePort' not in y:
688  raise InvalidServicePortConnectorNodeError
689  self.target_service_port = \
690  TargetPort().parse_yaml(y['targetServicePort'])
691  if RTS_EXT_NS_YAML + 'properties' in y:
692  for p in y[RTS_EXT_NS_YAML + 'properties']:
693  if 'value' in p:
694  value = p['value']
695  else:
696  value = None
697  self._properties[p['name']] = value
698  return self
699 
700  def save_xml(self, doc, element):
701  '''Save this service port into an xml.dom.Element object.'''
702  element.setAttributeNS(RTS_NS, RTS_NS_S + 'connectorId',
703  self.connector_id)
704  element.setAttributeNS(RTS_NS, RTS_NS_S + 'name', self.name)
705  if self.trans_method:
706  element.setAttributeNS(RTS_NS, RTS_NS_S + 'transMethod',
707  self.trans_method)
708  if self.comment:
709  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'comment',
710  self.comment)
711  element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S + 'visible',
712  str(self.visible).lower())
713  new_element = doc.createElementNS(RTS_NS,
714  RTS_NS_S + 'sourceServicePort')
715  self.source_service_port.save_xml(doc, new_element)
716  element.appendChild(new_element)
717  new_element = doc.createElementNS(RTS_NS,
718  RTS_NS_S + 'targetServicePort')
719  self.target_service_port.save_xml(doc, new_element)
720  element.appendChild(new_element)
721  for p in self.properties:
722  new_prop_element = doc.createElementNS(RTS_EXT_NS,
723  RTS_EXT_NS_S + 'Properties')
724  properties_to_xml(new_prop_element, p, self.properties[p])
725  element.appendChild(new_prop_element)
726 
727  def to_dict(self):
728  '''Save this service port connector into a dictionary.'''
729  d = {'connectorId': self.connector_id,
730  'name': self.name,
731  RTS_EXT_NS_YAML + 'visible': str(self.visible).lower(),
732  'sourceServicePort': self.source_service_port.to_dict(),
733  'targetServicePort': self.target_service_port.to_dict()}
734  if self.trans_method:
735  d['transMethod'] = self.trans_method
736  if self.comment:
737  d[RTS_EXT_NS_YAML + 'comment'] = self.comment
738  props = []
739  for name in self.properties:
740  p = {'name': name}
741  if self.properties[name]:
742  p['value'] = str(self.properties[name])
743  props.append(p)
744  if props:
745  d[RTS_EXT_NS_YAML + 'properties'] = props
746  return d
747 
748 
749 # vim: tw=79
750 
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)
def __init__(self, connector_id='', name='', trans_method='', source_service_port=TargetPort(), target_service_port=TargetPort(), comment='', visible=True)
def properties_to_xml(element, name, value=None)
Definition: utils.py:86
def parse_properties_xml(node)
Definition: utils.py:77
def validate_attribute(attr, name, expected_type=None, required=False)
Definition: utils.py:92
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
Definition: utils.py:50
TargetPort object.
Definition: targets.py:178
def indent_string(string, num_spaces=2)
Definition: utils.py:65


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