2399 |
20 Jun 06 |
nicklas |
1 |
/* |
2399 |
20 Jun 06 |
nicklas |
$Id$ |
2399 |
20 Jun 06 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2006 Nicklas Nordborg |
2399 |
20 Jun 06 |
nicklas |
5 |
|
2399 |
20 Jun 06 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
2399 |
20 Jun 06 |
nicklas |
Available at http://base.thep.lu.se/ |
2399 |
20 Jun 06 |
nicklas |
8 |
|
2399 |
20 Jun 06 |
nicklas |
BASE is free software; you can redistribute it and/or |
2399 |
20 Jun 06 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
2399 |
20 Jun 06 |
nicklas |
of the License, or (at your option) any later version. |
2399 |
20 Jun 06 |
nicklas |
13 |
|
2399 |
20 Jun 06 |
nicklas |
BASE is distributed in the hope that it will be useful, |
2399 |
20 Jun 06 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2399 |
20 Jun 06 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2399 |
20 Jun 06 |
nicklas |
GNU General Public License for more details. |
2399 |
20 Jun 06 |
nicklas |
18 |
|
2399 |
20 Jun 06 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
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 |
This interface should be implemented by JEP functions |
2399 |
20 Jun 06 |
nicklas |
that can also be converted into a {@link Restriction} that |
2399 |
20 Jun 06 |
nicklas |
can be used in queries. |
2399 |
20 Jun 06 |
nicklas |
32 |
|
2399 |
20 Jun 06 |
nicklas |
@author Nicklas |
2399 |
20 Jun 06 |
nicklas |
@version 2.0 |
2399 |
20 Jun 06 |
nicklas |
@base.modified $Date$ |
2399 |
20 Jun 06 |
nicklas |
@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 |
Convert this function to a {@link Restriction} that can be used |
2399 |
20 Jun 06 |
nicklas |
in a query. The implementation must check that the node contains |
2399 |
20 Jun 06 |
nicklas |
the correct number of children (ie. arguments to the function) |
2399 |
20 Jun 06 |
nicklas |
and convert the arguments to whatever is suitable for the restriction. |
5018 |
26 Jun 09 |
nicklas |
Example from the {@link InReporterListFunction}: <code>inList(list-id)</code> |
2399 |
20 Jun 06 |
nicklas |
<pre class="code"> |
5018 |
26 Jun 09 |
nicklas |
public Restriction toRestriction(Node node) |
5018 |
26 Jun 09 |
nicklas |
50 |
{ |
5018 |
26 Jun 09 |
nicklas |
int numChildren = node.jjtGetNumChildren(); |
5018 |
26 Jun 09 |
nicklas |
if (numChildren != 1) |
5018 |
26 Jun 09 |
nicklas |
53 |
{ |
5018 |
26 Jun 09 |
nicklas |
throw new BaseException("Invalid number of expressions for 'inList' function: " + numChildren); |
5018 |
26 Jun 09 |
nicklas |
55 |
} |
5018 |
26 Jun 09 |
nicklas |
int reporterListId = Jep.nodeToInt(node.jjtGetChild(0)); |
5018 |
26 Jun 09 |
nicklas |
ReporterList list = ReporterList.getById(dc, reporterListId); |
5018 |
26 Jun 09 |
nicklas |
return Dynamic.isPartOf(list); |
5018 |
26 Jun 09 |
nicklas |
59 |
} |
2399 |
20 Jun 06 |
nicklas |
</pre> |
2399 |
20 Jun 06 |
nicklas |
61 |
|
2399 |
20 Jun 06 |
nicklas |
@param node The node representing this function |
2399 |
20 Jun 06 |
nicklas |
@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 |
} |