|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Observable jimm.datavision.Expression jimm.datavision.Formula
public class Formula
A formula is a Bean Scripting Framework (BSF) script evaluated at runtime. It may contain database column values, other formulas, special values, and aggregates.
Before being evaluated, the following substitutions are made withing the evaluation string of a formula:
Field Summary | |
---|---|
protected java.lang.Object |
cachedEvalResult
|
protected java.lang.String |
language
|
protected boolean |
shouldEvaluate
|
protected boolean |
showException
|
protected boolean |
useCache
|
Fields inherited from class jimm.datavision.Expression |
---|
exceptAfter, expr, id, name, observedContents, report |
Constructor Summary | |
---|---|
Formula(java.lang.Long id,
Report report,
java.lang.String name)
Constructor. |
|
Formula(java.lang.Long id,
Report report,
java.lang.String name,
java.lang.String evalString)
Constructor. |
Method Summary | |
---|---|
java.lang.String |
designLabel()
|
java.lang.String |
dragString()
Returns the string used to identify the object when dragging it. |
java.lang.Object |
eval()
Evaluate this formula and return the result as either a String or a Double . |
java.lang.Object |
eval(Field formulaField)
Evaluate this formula and return the result. |
protected java.lang.Object |
evaluate(Field formulaField)
Modifies the formula text so it is ready to evaluate, then gives it to the report to evaluate and returns the result. |
java.lang.String |
formulaString()
|
java.lang.String |
getLanguage()
Returns the scripting language this formula uses. |
protected java.lang.String |
quoted(java.lang.Object obj)
Returns a string representation of an object enclosed in double quotes. |
void |
setExpression(java.lang.String newExpression)
Sets the eval string. |
void |
setLanguage(java.lang.String newLang)
|
void |
shouldEvaluate()
Tells this formula to evaluate the BSF script the next time eval is called. |
java.lang.Object |
unquoted(java.lang.Object obj)
If obj is a String and it is surrounded by
double quotes, return an unquoted copy. |
void |
useCache()
Tells this formula to evaluate only when shouldEvaluate is true and to return the cached value otherwise. |
protected void |
writeAdditionalAttributes(XMLWriter out)
Writes additional attributes. |
void |
writeXML(XMLWriter out)
Writes this expression as an XML tag. |
Methods inherited from class jimm.datavision.Expression |
---|
columnsUsed, displayToExpression, expressionToDisplay, finalize, getEditableExpression, getExpression, getId, getName, refersTo, refersTo, refersTo, setEditableExpression, setName, startObservingContents, stopObservingContents, update, userColumnsUsed, writeXML |
Methods inherited from class java.util.Observable |
---|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String language
protected java.lang.Object cachedEvalResult
protected boolean useCache
protected boolean shouldEvaluate
protected boolean showException
Constructor Detail |
---|
public Formula(java.lang.Long id, Report report, java.lang.String name)
id
- the unique identifier for the new formula; if null
,
generate a new idreport
- the report containing this formulaname
- the formula namepublic Formula(java.lang.Long id, Report report, java.lang.String name, java.lang.String evalString)
null
, generates a new id number.
This number is one higher than any previously-seen id number. This does
not guarantee that no later formula will be created manually with
the same id number.
id
- the unique identifier for the new formula; if null
,
generate a new idreport
- the report containing this formulaname
- the formula nameevalString
- the string to evaulate at runtime.Method Detail |
---|
public java.lang.String dragString()
Draggable
dragString
in interface Draggable
dragString
in class Expression
public java.lang.String designLabel()
designLabel
in class Expression
public java.lang.String formulaString()
formulaString
in class Expression
public void useCache()
true
and to return the cached value otherwise.
public void shouldEvaluate()
eval
is called.
public void setExpression(java.lang.String newExpression)
Expression
setExpression
in class Expression
newExpression
- the new eval stringpublic java.lang.Object eval()
String
or a Double
. Before evaluation, special
fields, formulas, and column references are subtituted with their
values.
After substitution, if the formula contains a null
anywhere
then null
is returned.
String
or a Double
; possibly null
public java.lang.Object eval(Field formulaField)
null
values are replaced by "nil".
After substitution, if the formula contains a null
anywhere
then null
is returned. If the BSF script throws an exception,
then null
is returned.
During substitution, we take care not to replace "#{...}" Ruby string substition operators.
The formulaField is used when the formula contains a "group.count" special field.
formulaField
- the field containing this formula; may be
null
null
protected java.lang.Object evaluate(Field formulaField)
eval()
calls this method
and stores the return value into cachedEvalResult.
formulaField
- the field that is using this formula, used to
evaluate any special fields in the formula; may be null
null
SpecialField.value(jimm.datavision.field.Field, java.lang.String, jimm.datavision.Report)
public java.lang.String getLanguage()
public void setLanguage(java.lang.String newLang)
protected java.lang.String quoted(java.lang.Object obj)
obj
- any object
public java.lang.Object unquoted(java.lang.Object obj)
String
and it is surrounded by
double quotes, return an unquoted copy. All doubled double quotes
are turned into single double quotes.
obj
- any object
String
, an unquoted
copy if it is a String
public void writeXML(XMLWriter out)
Expression
writeXML
in interface Writeable
writeXML
in class Expression
out
- a writer that knows how to write XMLprotected void writeAdditionalAttributes(XMLWriter out)
Expression
writeAdditionalAttributes
in class Expression
out
- a writer that knows how to write XML
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |