src/core/net/sf/basedb/util/jep/JepRestrictionFunction.java

Code
Comments
Other
Rev Date Author Line
2399 20 Jun 06 nicklas 1 /*
2399 20 Jun 06 nicklas 2   $Id$
2399 20 Jun 06 nicklas 3
3675 16 Aug 07 jari 4   Copyright (C) 2006 Nicklas Nordborg
2399 20 Jun 06 nicklas 5
2399 20 Jun 06 nicklas 6   This file is part of BASE - BioArray Software Environment.
2399 20 Jun 06 nicklas 7   Available at http://base.thep.lu.se/
2399 20 Jun 06 nicklas 8
2399 20 Jun 06 nicklas 9   BASE is free software; you can redistribute it and/or
2399 20 Jun 06 nicklas 10   modify it under the terms of the GNU General Public License
4479 05 Sep 08 jari 11   as published by the Free Software Foundation; either version 3
2399 20 Jun 06 nicklas 12   of the License, or (at your option) any later version.
2399 20 Jun 06 nicklas 13
2399 20 Jun 06 nicklas 14   BASE is distributed in the hope that it will be useful,
2399 20 Jun 06 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
2399 20 Jun 06 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2399 20 Jun 06 nicklas 17   GNU General Public License for more details.
2399 20 Jun 06 nicklas 18
2399 20 Jun 06 nicklas 19   You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
2399 20 Jun 06 nicklas 21 */
2399 20 Jun 06 nicklas 22 package net.sf.basedb.util.jep;
2399 20 Jun 06 nicklas 23
2399 20 Jun 06 nicklas 24 import net.sf.basedb.core.query.Restriction;
2399 20 Jun 06 nicklas 25
2399 20 Jun 06 nicklas 26 import org.nfunk.jep.Node;
2399 20 Jun 06 nicklas 27
2399 20 Jun 06 nicklas 28 /**
2399 20 Jun 06 nicklas 29   This interface should be implemented by JEP functions
2399 20 Jun 06 nicklas 30   that can also be converted into a {@link Restriction} that
2399 20 Jun 06 nicklas 31   can be used in queries.
2399 20 Jun 06 nicklas 32
2399 20 Jun 06 nicklas 33   @author Nicklas
2399 20 Jun 06 nicklas 34   @version 2.0
2399 20 Jun 06 nicklas 35   @base.modified $Date$
2399 20 Jun 06 nicklas 36   @see Jep#formulaToRestriction(String, JepFunction[])
2399 20 Jun 06 nicklas 37 */
2399 20 Jun 06 nicklas 38 public interface JepRestrictionFunction
2399 20 Jun 06 nicklas 39   extends JepFunction
2399 20 Jun 06 nicklas 40 {
2399 20 Jun 06 nicklas 41
2399 20 Jun 06 nicklas 42   /**
2399 20 Jun 06 nicklas 43     Convert this function to a {@link Restriction} that can be used
2399 20 Jun 06 nicklas 44     in a query. The implementation must check that the node contains
2399 20 Jun 06 nicklas 45     the correct number of children (ie. arguments to the function)
2399 20 Jun 06 nicklas 46     and convert the arguments to whatever is suitable for the restriction.
5018 26 Jun 09 nicklas 47     Example from the {@link InReporterListFunction}: <code>inList(list-id)</code>
2399 20 Jun 06 nicklas 48     <pre class="code">
5018 26 Jun 09 nicklas 49 public Restriction toRestriction(Node node)
5018 26 Jun 09 nicklas 50 {
5018 26 Jun 09 nicklas 51   int numChildren = node.jjtGetNumChildren();
5018 26 Jun 09 nicklas 52   if (numChildren != 1)
5018 26 Jun 09 nicklas 53   {
5018 26 Jun 09 nicklas 54     throw new BaseException("Invalid number of expressions for 'inList' function: " + numChildren);
5018 26 Jun 09 nicklas 55   }
5018 26 Jun 09 nicklas 56   int reporterListId = Jep.nodeToInt(node.jjtGetChild(0));
5018 26 Jun 09 nicklas 57   ReporterList list = ReporterList.getById(dc, reporterListId);
5018 26 Jun 09 nicklas 58   return Dynamic.isPartOf(list);
5018 26 Jun 09 nicklas 59 }
2399 20 Jun 06 nicklas 60 </pre>
2399 20 Jun 06 nicklas 61
2399 20 Jun 06 nicklas 62     @param node The node representing this function
2399 20 Jun 06 nicklas 63     @return A <code>Restriction</code> object
2399 20 Jun 06 nicklas 64   */
2399 20 Jun 06 nicklas 65   public Restriction toRestriction(Node node);
2399 20 Jun 06 nicklas 66 }