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

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

Adding parsing for Subject type and SubjectMatch? elements.

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                for subjElem in childElem:
42                    target.subjects.append(SubjectReader.parse(subjElem))
43                               
44            elif localName == cls.RESOURCES_ELEMENT_LOCAL_NAME:
45                for resourceElem in childElem:
46                    target.resources.append(ResourceReader.parse(resourceElem))
47               
48            elif localName == cls.ACTIONS_ELEMENT_LOCAL_NAME:
49                for targetElem in childElem:
50                    target.actions.append(ActionReader.parse(targetElem))
51               
52            elif localName == cls.ENVIRONMENTS_ELEMENT_LOCAL_NAME:
53                for environElem in childElem:
54                    target.environments.append(EnvironmentReader.parse(
55                                                                environElem))
56            else:
57                raise XMLParseError("XACML Target child element name %r not "
58                                    "recognised" % localName)
59               
60        return target
Note: See TracBrowser for help on using the repository browser.