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.util.HashSet; |
43 |
| |
44 |
| import org.drools.rule.Declaration; |
45 |
| import org.drools.rule.Rule; |
46 |
| import org.drools.smf.Configuration; |
47 |
| import org.drools.smf.DefaultConfiguration; |
48 |
| import org.drools.smf.FactoryException; |
49 |
| import org.drools.smf.ObjectTypeFactory; |
50 |
| import org.drools.smf.SemanticModule; |
51 |
| import org.drools.spi.ImportEntry; |
52 |
| import org.drools.spi.ObjectType; |
53 |
| import org.xml.sax.Attributes; |
54 |
| import org.xml.sax.SAXException; |
55 |
| import org.xml.sax.SAXParseException; |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| class ObjectTypeHandler extends BaseAbstractHandler |
61 |
| implements |
62 |
| Handler |
63 |
| { |
64 |
66
| ObjectTypeHandler(RuleSetReader ruleSetReader)
|
65 |
| { |
66 |
66
| this.ruleSetReader = ruleSetReader;
|
67 |
| |
68 |
66
| if ( this.validParents == null && this.validPeers == null )
|
69 |
| { |
70 |
66
| this.validParents = new HashSet( );
|
71 |
66
| this.validParents.add( Declaration.class );
|
72 |
| |
73 |
66
| this.validPeers = new HashSet( );
|
74 |
66
| this.validPeers.add( null );
|
75 |
| |
76 |
66
| this.allowNesting = false;
|
77 |
| } |
78 |
| } |
79 |
| |
80 |
164
| public Object start(String uri,
|
81 |
| String localName, |
82 |
| Attributes attrs) throws SAXException |
83 |
| { |
84 |
164
| this.ruleSetReader.startConfiguration( localName,
|
85 |
| attrs ); |
86 |
164
| return null;
|
87 |
| } |
88 |
| |
89 |
164
| public Object end(String uri,
|
90 |
| String localName) throws SAXException |
91 |
| { |
92 |
164
| Configuration config = this.ruleSetReader.endConfiguration( );
|
93 |
| |
94 |
164
| SemanticModule module = this.ruleSetReader.lookupSemanticModule( uri,
|
95 |
| localName ); |
96 |
| |
97 |
164
| ObjectTypeFactory factory = module.getObjectTypeFactory( localName );
|
98 |
| |
99 |
164
| try
|
100 |
| { |
101 |
164
| Rule rule = (Rule) this.ruleSetReader.getParent( Rule.class );
|
102 |
164
| Declaration declaration = (Declaration) this.ruleSetReader.getParent( Declaration.class );
|
103 |
164
| ((DefaultConfiguration) config).setAttribute( "identifier",
|
104 |
| declaration.getIdentifier( ) ); |
105 |
| |
106 |
164
| ObjectType objectType = factory.newObjectType( rule,
|
107 |
| this.ruleSetReader.getFactoryContext( ), |
108 |
| config ); |
109 |
| |
110 |
164
| declaration.setObjectType( objectType );
|
111 |
| } |
112 |
| catch ( FactoryException e ) |
113 |
| { |
114 |
0
| throw new SAXParseException( "error constructing object type",
|
115 |
| this.ruleSetReader.getLocator( ), |
116 |
| e ); |
117 |
| } |
118 |
164
| return null;
|
119 |
| } |
120 |
| |
121 |
328
| public Class generateNodeFor()
|
122 |
| { |
123 |
328
| return ImportEntry.class;
|
124 |
| } |
125 |
| } |