View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2004, DERI Innsbruck
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  package org.deri.wsmo4j.logicalexpression;
17  
18  
19  import java.util.*;
20  
21  import org.deri.wsmo4j.logicalexpression.util.*;
22  
23  import org.omwg.logicalexpression.*;
24  import org.omwg.ontology.*;
25  
26  
27  /**
28   * This abstract class reunites all quantified logical expressions
29   * (e.g qfier {Term} LogExpr)
30   * @author DERI Innsbruck, reto.krummenacher@deri.org
31   * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
32   * @see org.omwg.logicalexpression.Quantified
33   */
34  public abstract class QuantifiedImpl
35          extends UnaryImpl
36          implements Quantified {
37  
38      protected Set <Variable> variables;
39  
40      /**
41       * @param variables the set of variables that are quantified for the expression
42       * @param expr the logical expression
43       * @throws IllegalArgumentException
44       * <p>in case the operator is different from EXISTS or FORALL</p>
45       * <p>in case the logical expression contains a nested CONSTRAINT</p>
46       * <p>in case the Set of variables is null</p>
47       * <p>in case the arguments of the list aren't all of Type Variable</p>
48       */
49      public QuantifiedImpl(Set <Variable> variables, LogicalExpression expr)
50              throws IllegalArgumentException {
51          super(expr);
52          setVariables(variables);
53  
54      }
55  
56      /**
57       * @return the set of variables that are quantified for the expression
58       * @see org.omwg.logicalexpression.Quantified#listVariables()
59       */
60      public Set <Variable> listVariables() {
61          return variables;
62      }
63  
64      /**
65       * @see org.omwg.logicalexpression.LogicalExpression#accept(org.omwg.logicalexpression.Visitor)
66       */
67      public abstract void accept(Visitor v);
68  
69      /* (non-Javadoc)
70       * @see org.omwg.logicalexpression.Quantified#setVariables(java.util.Set)
71       */
72      public void setVariables(Set <Variable> variables) {
73          if (variables == null) {
74              throw new IllegalArgumentException("Quantified Expression must have at least one Variable");
75          }
76          if (!SetUtil.allOfType(variables, Variable.class)) {
77              throw new IllegalArgumentException("Set variables may only contain org.omwg.logicalexpression.variables");
78          }
79          this.variables = Collections.unmodifiableSet(variables);        
80      }
81  
82  }