1 # PyOpenSG is (C) Copyright 2005-2009 by Allen Bierbaum
3 # This file is part of PyOpenSG.
5 # PyOpenSG is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; either version 2 of the License, or (at your option)
10 # PyOpenSG is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Simple wrapper for FCD XML data in field type
23 import xml
.etree
.ElementTree
as ET
25 import elementtree
.ElementTree
as ET
27 class FcdReflector(object):
28 def __init__(self
, fctype
, mergeParents
=False):
30 @param mergeParents: If true, merge in the parent's fields.
33 xml_data
= fctype
.getFcdXML()
34 if xml_data
and xml_data
!= "":
35 self
.element
= ET
.fromstring(xml_data
)
39 if self
.element
and mergeParents
:
40 fc_type
= fctype
.getParent()
42 xml_data
= fc_type
.getFcdXML()
43 if xml_data
and xml_data
!= "":
44 new_elt
= ET
.fromstring(xml_data
)
47 self
.element
.append(n
)
48 fc_type
= fc_type
.getParent()
52 """ Return true if we wrap XML data successfully.
53 Note: Some object types may not have an fcd file as a backend so they
56 return self
.element
!= None
59 """ return wrappers for all child fields. """
60 if len(self
.element
) == 0:
63 return [FieldReflector(f
,self
) for f
in self
.element
.findall("Field")]
65 def getField(self
, name
):
66 """ Return a wrapper around the first field named name. """
67 for f
in self
.element
.findall("Field"):
68 if name
== f
.attrib
["name"]:
69 return FieldReflector(f
,self
)
73 return self
.element
.attrib
74 attrib
= property(getAttrib
, doc
='Return the element.attrib property')
77 return self
.element
.get("name")
79 return self
.element
.get("type")
81 def getDocumentation(self
):
82 return self
.element
.text
83 def getCardinality(self
):
84 return self
.element
.get("cardinality")
85 def getVisibility(self
):
86 return self
.element
.get("visibility")
88 return self
.element
.get("access")
91 class FieldReflector(FcdReflector
):
92 def __init__(self
, fieldElement
, parent
):
94 self
.element
= fieldElement