source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/targetreader.py @ 6746

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/targetreader.py@6746
Revision 6746, 2.2 KB checked in by pjkersha, 10 years ago (diff)

Added more !ETree readers for the different types.

Line 
1"""NDG XACML ElementTree based Target Element reader
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "16/03/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__contact__ = "Philip.Kershaw@stfc.ac.uk"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id: $"
12from ndg.xacml.core.target import Target
13from ndg.xacml.parsers import XMLParseError
14from ndg.xacml.parsers.etree import QName
15from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
16from ndg.xacml.parsers.etree.subjectreader import SubjectReader
17from ndg.xacml.parsers.etree.actionreader import ActionReader
18from ndg.xacml.parsers.etree.resourcereader import ResourceReader
19from ndg.xacml.parsers.etree.environmentreader import EnvironmentReader
20
21
22class TargetReader(ETreeAbstractReader):
23    """ElementTree based parser for XACML Target elements"""
24   
25    def __call__(self, obj):
26        elem = super(TargetReader, self)._parse(obj)
27       
28        target = Target()
29        cls = Target
30       
31        localName = QName.getLocalPart(elem.tag)
32        if localName != cls.ELEMENT_LOCAL_NAME:
33            raise XMLParseError('No "%s" element found' % 
34                                cls.ELEMENT_LOCAL_NAME)
35                   
36        # Parse sub-elements
37        for childElem in elem:
38            localName = QName.getLocalPart(childElem.tag)
39           
40            if localName == cls.SUBJECTS_ELEMENT_LOCAL_NAME:
41                target.subjects.append(SubjectReader.parse(childElem))
42                               
43            elif localName == cls.RESOURCES_ELEMENT_LOCAL_NAME:
44                target.resources.append(ResourceReader.parse(childElem))
45               
46            elif localName == cls.ACTIONS_ELEMENT_LOCAL_NAME:
47                target.actions.append(ActionReader.parse(childElem))
48               
49            elif localName == cls.ENVIRONMENTS_ELEMENT_LOCAL_NAME:
50                target.environments.append(EnvironmentReader.parse(childElem))
51               
52            else:
53                raise XMLParseError("XACML Target child element name %r not "
54                                    "recognised" % localName)
55               
56        return target
Note: See TracBrowser for help on using the repository browser.