public Object value(InternalContextAdapter context) throws MethodInvocationException {
/*
* get the two range ends
*/
Object left = jjtGetChild(0).value( context );
Object right = jjtGetChild(1).value( context );
/*
* if either is null, lets log and bail
*/
if (left == null || right == null)
{
log.error((left == null ? "Left" : "Right")
+ " side of range operator [n..m] has null value."
+ " Operation not possible. "
+ context.getCurrentTemplateName() + " [line " + getLine()
+ ", column " + getColumn() + "]");
return null;
}
/*
* if not an Integer, not much we can do either
*/
if ( !( left instanceof Integer ) || !( right instanceof Integer ))
{
log.error((!(left instanceof Integer) ? "Left" : "Right")
+ " side of range operator is not a valid type. "
+ "Currently only integers (1,2,3...) and Integer type is supported. "
+ context.getCurrentTemplateName() + " [line " + getLine()
+ ", column " + getColumn() + "]");
return null;
}
/*
* get the two integer values of the ends of the range
*/
int l = ( (Integer) left ).intValue() ;
int r = ( (Integer) right ).intValue();
/*
* find out how many there are
*/
int nbrElements = Math.abs( l - r );
nbrElements += 1;
/*
* Determine whether the increment is positive or negative.
*/
int delta = ( l >= r ) ? -1 : 1;
/*
* Fill the range with the appropriate values.
*/
List elements = new ArrayList(nbrElements);
int value = l;
for (int i = 0; i < nbrElements; i++)
{
// TODO: JDK 1.4+ - > valueOf()
elements.add(new Integer(value));
value += delta;
}
return elements;
}
does the real work. Creates an Vector of Integers with the
right value range |