source: TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/targetchildreader.py @ 7109

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML ElementTree based Generic Target Child Element reader - for
2Reosurce, Subject, Action and Environment
3
4NERC DataGrid
5"""
6__author__ = "P J Kershaw"
7__date__ = "18/03/10"
8__copyright__ = "(C) 2010 Science and Technology Facilities Council"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__license__ = "BSD - see LICENSE file in top-level directory"
11__contact__ = "Philip.Kershaw@stfc.ac.uk"
12__revision__ = "$Id$"
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.factory import ReaderFactory
17
18
19class TargetChildReader(ETreeAbstractReader):
20    '''ElementTree based XACML generic target child element parser
21    @cvar TYPE: XACML type to instantiate from parsed object
22    @type TYPE: type
23    '''
24
25    def __call__(self, obj):
26        """Parse target child element object
27       
28        @param obj: input object to parse
29        @type obj: ElementTree Element, or stream object
30        @return: new XACML expression instance
31        @rtype: ndg.xacml.core.TargetChildBase derived type
32        @raise XMLParseError: error reading element               
33        """
34        elem = super(TargetChildReader, self)._parse(obj)
35       
36        xacmlType = self.__class__.TYPE
37        targetChild = xacmlType()
38       
39        localName = QName.getLocalPart(elem.tag)
40        if localName != xacmlType.ELEMENT_LOCAL_NAME:
41            raise XMLParseError("No \"%s\" element found" % 
42                                xacmlType.ELEMENT_LOCAL_NAME)
43           
44        # Parse match elements
45        for childElem in elem:
46            localName = QName.getLocalPart(childElem.tag)
47           
48            if localName == xacmlType.MATCH_TYPE.ELEMENT_LOCAL_NAME:
49                # Get reader for the match type
50                matchReader = ReaderFactory.getReader(xacmlType.MATCH_TYPE)
51                targetChild.matches.append(matchReader.parse(childElem))
52           
53            else:
54                raise XMLParseError("XACML %r child element name %r not "
55                                    "recognised" % (xacmlType.ELEMENT_LOCAL_NAME, 
56                                                    localName))
57                       
58        return targetChild
Note: See TracBrowser for help on using the repository browser.