View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  package org.mycore.access.facts.condition.combined;
19  
20  import java.util.HashSet;
21  import java.util.Set;
22  
23  import org.jdom2.Element;
24  import org.mycore.access.facts.MCRFactsAccessSystemHelper;
25  import org.mycore.access.facts.condition.MCRAbstractCondition;
26  import org.mycore.access.facts.model.MCRCombinedCondition;
27  import org.mycore.access.facts.model.MCRCondition;
28  
29  /**
30   * This is the base implementation for a combined condition.
31   * It can be used to create conditions for a boolean algebra (and, or, not)
32   * 
33   * @author Robert Stephan
34   *
35   */
36  public abstract class MCRAbstractCombinedCondition extends MCRAbstractCondition implements MCRCombinedCondition {
37  
38      protected Set<MCRCondition> conditions = new HashSet<MCRCondition>();
39  
40      public void add(MCRCondition condition) {
41          conditions.add(condition);
42      }
43  
44      public void parse(Element xml) {
45          super.parse(xml);
46          for (Element child : xml.getChildren()) {
47              conditions.add(MCRFactsAccessSystemHelper.parse(child));
48          }
49      }
50  
51      /**
52       * @return the conditions
53       */
54      public Set<MCRCondition> getChildConditions() {
55          return conditions;
56      }
57  
58      public void debugInfoForMatchingChildElement(MCRCondition c, boolean matches) {
59          if (isDebug()) {
60              Element el = c.getBoundElement();
61              if (el != null) {
62                  el.setAttribute("_matches", Boolean.toString(matches));
63              }
64          }
65      }
66  
67  }