01: package org.drools.xml;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.HashSet;
20: import java.util.LinkedList;
21: import java.util.ListIterator;
22:
23: import org.drools.lang.descr.ConditionalElementDescr;
24: import org.drools.lang.descr.FieldConstraintDescr;
25: import org.drools.lang.descr.FromDescr;
26: import org.drools.lang.descr.PatternDescr;
27: import org.xml.sax.Attributes;
28: import org.xml.sax.SAXException;
29:
30: /**
31: * @author fernandomeyer
32: *
33: */
34: public class FromHandler extends BaseAbstractHandler implements Handler {
35:
36: FromHandler(final XmlPackageReader xmlPackageReader) {
37: this .xmlPackageReader = xmlPackageReader;
38:
39: if ((this .validParents == null) && (this .validPeers == null)) {
40: this .validParents = new HashSet();
41: this .validParents.add(PatternDescr.class);
42:
43: this .validPeers = new HashSet();
44: this .validPeers.add(null);
45: this .validPeers.add(FieldConstraintDescr.class);
46: this .allowNesting = false;
47: }
48: }
49:
50: public Object start(final String uri, final String localName,
51: final Attributes attrs) throws SAXException {
52:
53: this .xmlPackageReader.startConfiguration(localName, attrs);
54:
55: final FromDescr fromDesctiptor = new FromDescr();
56: return fromDesctiptor;
57: }
58:
59: public Object end(final String uri, final String localName)
60: throws SAXException {
61:
62: final Configuration config = this .xmlPackageReader
63: .endConfiguration();
64:
65: final FromDescr fromDescr = (FromDescr) this .xmlPackageReader
66: .getCurrent();
67:
68: final LinkedList parents = this .xmlPackageReader.getParents();
69: final ListIterator it = parents.listIterator(parents.size());
70: it.previous();
71: Object parent = it.previous();
72:
73: final PatternDescr patternDescr = (PatternDescr) parent;
74:
75: final ConditionalElementDescr parentDescr = (ConditionalElementDescr) it
76: .previous();
77:
78: if ((config.getChild("expression") != null)) {
79: patternDescr.setSource(fromDescr);
80: }
81:
82: return null;
83: }
84:
85: public Class generateNodeFor() {
86: return FromDescr.class;
87: }
88:
89: }
|