source: TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/parsers/etree/targetreader.py @ 6733

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/parsers/etree/targetreader.py@6733
Revision 6733, 1.8 KB checked in by pjkersha, 11 years ago (diff)

Rearranging parsing package structure.

Line 
1'''
2Created on 16 Mar 2010
3
4@author: pjkersha
5'''
6from ndg.security.common.authz.xacml import XMLParseError
7from ndg.security.common.authz.xacml.action import Action
8from ndg.security.common.authz.xacml.resource import Resource
9from ndg.security.common.authz.xacml.subject import Subject
10from ndg.security.common.authz.xacml.environment import Environment
11from ndg.security.common.authz.xacml.etree.reader import AbstractReader
12
13
14class TargetReader(AbstractReader):
15    """ElementTree based parser for XACML Target elements"""
16   
17    def __call__(self, obj):
18        elem = super(TargetReader, self)._parse(obj)
19       
20        target = Target()
21        cls = Target
22       
23        localName = QName.getLocalPart(elem.tag)
24        if localName != cls.ELEMENT_LOCAL_NAME:
25            raise XMLParseError('No "%s" element found' % 
26                                cls.ELEMENT_LOCAL_NAME)
27                   
28        # Parse sub-elements
29        for childElem in elem:
30            localName = QName.getLocalPart(childElem.tag)
31           
32            if localName == Subject.ELEMENT_LOCAL_NAME:
33                target.subjects.append(SubjectReader.parse(childElem))
34                               
35            elif localName == Resource.ELEMENT_LOCAL_NAME:
36                target.resources.append(ResourceReader.parse(childElem))
37               
38            elif localName == Action.ELEMENT_LOCAL_NAME:
39                target.actions.append(ActionReader.parse(childElem))
40               
41            elif localName == Environment.ELEMENT_LOCAL_NAME:
42                target.environments.append(EnvironmentReader.parse(childElem))
43               
44            else:
45                raise XMLParseError("XACML Target child element name %r not "
46                                    "recognised" % localName)       
Note: See TracBrowser for help on using the repository browser.