Trying to add some error checking to matches and targets
[sfa.git] / sfatables / xmlextension.py
1 # Matches and targets are specified using XML files.
2 # They provide the following information:
3 #   - The context required by the match
4 #   - The processor that actually implements the match or target
5 #   - The parameters that the processor needs to evaluate the context
6
7 import libxml2
8 from sfatables.globals import *
9
10 class Xmlextension:
11     context = ""
12     processor = ""
13     operand = "VALUE"
14     arguments = []
15
16     def __init__(self, dir, component_name):
17         filename = dir+"/"+component_name+".xml"
18         import pdb
19         pdb.set_trace()
20         self.xmldoc = libxml2.parseFile(filename)
21
22         # TODO: Check xmldoc against a schema
23         p = self.xmldoc.xpathNewContext()
24
25         # <context select="..."/>
26         # <rule><argument param="..."/></rule>
27         # <processor name="..."/>
28
29         context = p.xpathEval('//context/@select')
30         self.context = context[0].content
31
32         processor = p.xpathEval('//processor/@filename')
33         self.context = processor[0].content
34
35         name = p.xpathEval('//rule/argument/name')
36         help = p.xpathEval('//rule/argument/help')
37         target = p.xpathEval('//rule/argument/operand')
38
39         self.arguments = map(lambda (name,help,target):{'name':name.content,'help':help.content,'target':target.content}, zip(name,help,target))
40         
41         p.xpathFreeContext()
42         self.xmldoc.freeDoc()
43
44         return
45