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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/targetreader.py@7109
Revision 7109, 3.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 Target Element reader
2
3NERC DataGrid
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.core.subject import Subject
14from ndg.xacml.core.resource import Resource
15from ndg.xacml.core.action import Action
16from ndg.xacml.core.environment import Environment
17from ndg.xacml.parsers import XMLParseError
18from ndg.xacml.parsers.etree import QName
19from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
20from ndg.xacml.parsers.etree.factory import ReaderFactory
21
22
23class TargetReader(ETreeAbstractReader):
24    """ElementTree based parser for XACML Target elements
25   
26    @cvar TYPE: XACML type to instantiate from parsed object
27    @type TYPE: type
28    """
29    TYPE = Target
30   
31    def __call__(self, obj):
32        """Parse Target object
33       
34        @param obj: input object to parse
35        @type obj: ElementTree Element, or stream object
36        @return: new XACML expression instance
37        @rtype: ndg.xacml.core.target.Target derived type
38        @raise XMLParseError: error reading element               
39        """
40        elem = super(TargetReader, self)._parse(obj)
41       
42        xacmlType = TargetReader.TYPE
43        target = xacmlType()
44       
45        localName = QName.getLocalPart(elem.tag)
46        if localName != xacmlType.ELEMENT_LOCAL_NAME:
47            raise XMLParseError('No "%s" element found' % 
48                                xacmlType.ELEMENT_LOCAL_NAME)
49       
50        # Parse sub-elements
51        for childElem in elem:
52            localName = QName.getLocalPart(childElem.tag)
53           
54            if localName == xacmlType.SUBJECTS_ELEMENT_LOCAL_NAME:
55                for subjElem in childElem:
56                    SubjectReader = ReaderFactory.getReader(Subject)
57                    target.subjects.append(SubjectReader.parse(subjElem))
58                               
59            elif localName == xacmlType.RESOURCES_ELEMENT_LOCAL_NAME:
60                for resourceElem in childElem:
61                    ResourceReader = ReaderFactory.getReader(Resource)
62                    target.resources.append(ResourceReader.parse(resourceElem))
63               
64            elif localName == xacmlType.ACTIONS_ELEMENT_LOCAL_NAME:
65                for targetElem in childElem:
66                    ActionReader = ReaderFactory.getReader(Action)
67                    target.actions.append(ActionReader.parse(targetElem))
68               
69            elif localName == xacmlType.ENVIRONMENTS_ELEMENT_LOCAL_NAME:
70                for environElem in childElem:
71                    EnvironmentReader = ReaderFactory.getReader(Environment)
72                    target.environments.append(EnvironmentReader.parse(
73                                                                environElem))
74            else:
75                raise XMLParseError("XACML Target child element name %r not "
76                                    "recognised" % localName)
77               
78        return target
Note: See TracBrowser for help on using the repository browser.