1 |
| package org.drools.io; |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| import java.io.BufferedWriter; |
43 |
| import java.io.FileWriter; |
44 |
| import java.io.PrintWriter; |
45 |
| import java.util.HashSet; |
46 |
| |
47 |
| import org.drools.rule.Declaration; |
48 |
| import org.drools.rule.Rule; |
49 |
| import org.drools.smf.ConditionFactory; |
50 |
| import org.drools.smf.Configuration; |
51 |
| import org.drools.smf.FactoryException; |
52 |
| import org.drools.smf.SemanticModule; |
53 |
| import org.drools.spi.Condition; |
54 |
| import org.xml.sax.Attributes; |
55 |
| import org.xml.sax.SAXException; |
56 |
| import org.xml.sax.SAXParseException; |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| class ConditionHandler extends BaseAbstractHandler |
65 |
| implements |
66 |
| Handler |
67 |
| { |
68 |
66
| ConditionHandler(RuleSetReader ruleSetReader)
|
69 |
| { |
70 |
66
| this.ruleSetReader = ruleSetReader;
|
71 |
| |
72 |
66
| if ( (this.validParents == null) && (validPeers == null) )
|
73 |
| { |
74 |
66
| this.ruleSetReader = ruleSetReader;
|
75 |
66
| this.validParents = new HashSet( );
|
76 |
66
| this.validParents.add( Rule.class );
|
77 |
| |
78 |
66
| this.validPeers = new HashSet( );
|
79 |
66
| this.validPeers.add( Declaration.class );
|
80 |
66
| this.validPeers.add( Condition.class );
|
81 |
66
| this.validPeers.add( null );
|
82 |
| |
83 |
66
| this.allowNesting = false;
|
84 |
| } |
85 |
| } |
86 |
| |
87 |
104
| public Object start(String uri,
|
88 |
| String localName, |
89 |
| Attributes attrs) throws SAXException |
90 |
| { |
91 |
104
| ruleSetReader.startConfiguration( localName,
|
92 |
| attrs ); |
93 |
104
| return null;
|
94 |
| } |
95 |
| |
96 |
104
| public Object end(String uri,
|
97 |
| String localName) throws SAXException |
98 |
| { |
99 |
104
| Configuration config = this.ruleSetReader.endConfiguration( );
|
100 |
104
| SemanticModule module = this.ruleSetReader.lookupSemanticModule( uri,
|
101 |
| localName ); |
102 |
| |
103 |
104
| ConditionFactory factory = module.getConditionFactory( localName );
|
104 |
104
| Condition[] conditions;
|
105 |
104
| try
|
106 |
| { |
107 |
104
| Rule rule = (Rule) this.ruleSetReader.getParent( Rule.class );
|
108 |
104
| conditions = factory.newCondition( rule,
|
109 |
| this.ruleSetReader.getFactoryContext( ), |
110 |
| config ); |
111 |
| |
112 |
104
| for (int i = 0; i < conditions.length; i++)
|
113 |
| { |
114 |
104
| rule.addCondition( conditions[i] );
|
115 |
| } |
116 |
| } |
117 |
| catch ( FactoryException e ) |
118 |
| { |
119 |
0
| throw new SAXParseException( "error constructing condition",
|
120 |
| this.ruleSetReader.getLocator( ), |
121 |
| e ); |
122 |
| } |
123 |
104
| return conditions[conditions.length-1];
|
124 |
| } |
125 |
| |
126 |
208
| public Class generateNodeFor()
|
127 |
| { |
128 |
208
| return Condition.class;
|
129 |
| } |
130 |
| } |