001: package org.drools.xml;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.HashSet;
020: import java.util.LinkedList;
021: import java.util.ListIterator;
022:
023: import org.drools.lang.descr.AndDescr;
024: import org.drools.lang.descr.ConditionalElementDescr;
025: import org.drools.lang.descr.EvalDescr;
026: import org.drools.lang.descr.ExistsDescr;
027: import org.drools.lang.descr.ForallDescr;
028: import org.drools.lang.descr.NotDescr;
029: import org.drools.lang.descr.OrDescr;
030: import org.drools.lang.descr.PatternDescr;
031: import org.xml.sax.Attributes;
032: import org.xml.sax.SAXException;
033:
034: /**
035: * @author fernandomeyer
036: *
037: */
038: public class ForallHandler extends BaseAbstractHandler implements
039: Handler {
040:
041: ForallHandler(final XmlPackageReader xmlPackageReader) {
042: this .xmlPackageReader = xmlPackageReader;
043:
044: if ((this .validParents == null) && (this .validPeers == null)) {
045: this .validParents = new HashSet();
046: this .validParents.add(AndDescr.class);
047:
048: this .validPeers = new HashSet();
049: this .validPeers.add(null);
050:
051: this .validPeers.add(AndDescr.class);
052: this .validPeers.add(OrDescr.class);
053: this .validPeers.add(NotDescr.class);
054: this .validPeers.add(ExistsDescr.class);
055: this .validPeers.add(EvalDescr.class);
056: this .validPeers.add(PatternDescr.class);
057: this .validPeers.add(ForallDescr.class);
058:
059: this .allowNesting = true;
060: }
061: }
062:
063: /* (non-Javadoc)
064: * @see org.drools.xml.Handler#end(java.lang.String, java.lang.String)
065: */
066: public Object end(final String uri, final String localName)
067: throws SAXException {
068: final Configuration config = this .xmlPackageReader
069: .endConfiguration();
070:
071: final ForallDescr forallDescr = (ForallDescr) this .xmlPackageReader
072: .getCurrent();
073:
074: final LinkedList parents = this .xmlPackageReader.getParents();
075: final ListIterator it = parents.listIterator(parents.size());
076: it.previous();
077: final Object parent = it.previous();
078:
079: final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
080: parentDescr.addDescr(forallDescr);
081:
082: return null;
083: }
084:
085: /* (non-Javadoc)
086: * @see org.drools.xml.Handler#generateNodeFor()
087: */
088: public Class generateNodeFor() {
089: return ForallDescr.class;
090: }
091:
092: /* (non-Javadoc)
093: * @see org.drools.xml.Handler#start(java.lang.String, java.lang.String, org.xml.sax.Attributes)
094: */
095: public Object start(final String uri, final String localName,
096: final Attributes attrs) throws SAXException {
097:
098: this .xmlPackageReader.startConfiguration(localName, attrs);
099:
100: final ForallDescr forallDescr = new ForallDescr();
101:
102: return forallDescr;
103: }
104:
105: }
|