2.17.2: 2011-06-17

net.sf.basedb.util.jep
Class ReporterFunction

java.lang.Object
  extended by net.sf.basedb.util.jep.ReporterFunction
All Implemented Interfaces:
JepExpressionFunction, JepFunction, org.nfunk.jep.function.PostfixMathCommandI

public class ReporterFunction
extends Object
implements JepExpressionFunction

A JEP function class that adds a rep(string) function to a JEP expression parser. The function will look up the value of the reporter property with the given name. For example: rep('sequence')

To be able to use this function it must be registered with the JEP parser and, before the expression is evaluated, a reporter object must be set. For example we can evaluate an expression for every reporter object:

DbControl dc = ...
RawBioAssay assay = ...
String expression = "rep('sequence')";
ReporterFunction rep = new RepFunction();
JEP jep = JepUtil.newJep(expression, rep);
DataResultIterator<RawData> result = 
   assay.getRawData().iterate(dc);
while (result.hasNext())
{
   rep.setReporter(result.next().getReporter());
   String value = jep.getValue();
   // Do something with the value
}
result.close();

Version:
2.0
Author:
Nicklas
See Also:
Jep, BioAssaySetUtil.createJepExpression(DbControl, String, DynamicQuery)
Last modified
$Date: 2010-04-20 10:02:16 +0200 (Tue, 20 Apr 2010) $

Field Summary
private  DbControl dc
           
private  Metadata<ReporterData> metaData
           
private  int numParameters
           
private  ReporterData reporter
           
 
Constructor Summary
ReporterFunction()
          Create a new instance of this function.
ReporterFunction(DbControl dc, RawDataType rawDataType)
          Create a new instance of this function working with reporters.
 
Method Summary
 boolean checkNumberOfParameters(int n)
           
 String getFunctionName()
          Get the name of this function.
 int getNumberOfParameters()
           
 ReporterData getReporter()
          Get the current reporter object used when evaluating the JEP expression.
 Object raw(String propertyName)
          Get the value of the specified property of the current raw data object.
 void run(Stack stack)
           
 void setCurNumberOfParameters(int n)
           
 void setReporter(ReporterData reporter)
          Set a new reporter object that will be used the next time the JEP expression is evaluated.
 Expression toExpression(Node node)
          Use the Dynamic.reporter(String) method to create an expression referencing a reporter property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metaData

private final Metadata<ReporterData> metaData

dc

private final DbControl dc

numParameters

private int numParameters

reporter

private ReporterData reporter
Constructor Detail

ReporterFunction

public ReporterFunction()
Create a new instance of this function. The new instance cannot be used to dynamically evaluate expressions. It should only be used for converting JEP formulas to Expression:s.

See Also:
Jep.formulaToExpression(String, JepFunction[])

ReporterFunction

public ReporterFunction(DbControl dc,
                        RawDataType rawDataType)
Create a new instance of this function working with reporters.

Method Detail

getFunctionName

public String getFunctionName()
Description copied from interface: JepFunction
Get the name of this function. It is used when registering the function with a JEP parser.

Specified by:
getFunctionName in interface JepFunction
Returns:
The string "rep"
See Also:
JEP.addFunction(String, PostfixMathCommandI)

toExpression

public Expression toExpression(Node node)
Use the Dynamic.reporter(String) method to create an expression referencing a reporter property.

Specified by:
toExpression in interface JepExpressionFunction
Parameters:
node - The node representing this function
Returns:
An Expression object

getNumberOfParameters

public int getNumberOfParameters()
Specified by:
getNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
Returns:
Always 1

setCurNumberOfParameters

public void setCurNumberOfParameters(int n)
Specified by:
setCurNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

checkNumberOfParameters

public boolean checkNumberOfParameters(int n)
Specified by:
checkNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

run

public void run(Stack stack)
         throws ParseException
Specified by:
run in interface org.nfunk.jep.function.PostfixMathCommandI
Throws:
ParseException

setReporter

public void setReporter(ReporterData reporter)
Set a new reporter object that will be used the next time the JEP expression is evaluated.

Parameters:
reporter - The reporter object to use

getReporter

public ReporterData getReporter()
Get the current reporter object used when evaluating the JEP expression.


raw

public Object raw(String propertyName)
           throws ParseException
Get the value of the specified property of the current raw data object. This method uses Hibernate metadata to find the value.

Parameters:
propertyName - The name of the raw data property
Returns:
an java.lang.Object
Throws:
ParseException - If the argument is null or 'reporter' not specified.

2.17.2: 2011-06-17