You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/14 15:18:36 UTC
svn commit: r1103095 [2/24] - in /incubator/ognl/trunk/src:
main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/
main/java/org/apache/commons/ognl/internal/
test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/t...
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java Sat May 14 13:18:29 2011
@@ -29,24 +29,27 @@ import java.lang.reflect.Array;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class ASTChain extends SimpleNode implements NodeType, OrderedReturn
+public class ASTChain
+ extends SimpleNode
+ implements NodeType, OrderedReturn
{
private Class _getterClass;
+
private Class _setterClass;
private String _lastExpression;
private String _coreExpression;
- public ASTChain(int id)
+ public ASTChain( int id )
{
- super(id);
+ super( id );
}
- public ASTChain(OgnlParser p, int id)
+ public ASTChain( OgnlParser p, int id )
{
- super(p, id);
+ super( p, id );
}
public String getLastExpression()
@@ -64,60 +67,73 @@ public class ASTChain extends SimpleNode
flattenTree();
}
- protected Object getValueBody(OgnlContext context, Object source)
- throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object result = source;
- for(int i = 0, ilast = _children.length - 1; i <= ilast; ++i)
+ for ( int i = 0, ilast = _children.length - 1; i <= ilast; ++i )
{
boolean handled = false;
- if (i < ilast) {
- if (_children[i] instanceof ASTProperty) {
+ if ( i < ilast )
+ {
+ if ( _children[i] instanceof ASTProperty )
+ {
ASTProperty propertyNode = (ASTProperty) _children[i];
- int indexType = propertyNode.getIndexedPropertyType(context, result);
+ int indexType = propertyNode.getIndexedPropertyType( context, result );
- if ((indexType != OgnlRuntime.INDEXED_PROPERTY_NONE) && (_children[i + 1] instanceof ASTProperty)) {
+ if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
+ && ( _children[i + 1] instanceof ASTProperty ) )
+ {
ASTProperty indexNode = (ASTProperty) _children[i + 1];
- if (indexNode.isIndexedAccess()) {
- Object index = indexNode.getProperty(context, result);
+ if ( indexNode.isIndexedAccess() )
+ {
+ Object index = indexNode.getProperty( context, result );
- if (index instanceof DynamicSubscript) {
- if (indexType == OgnlRuntime.INDEXED_PROPERTY_INT) {
- Object array = propertyNode.getValue(context, result);
- int len = Array.getLength(array);
+ if ( index instanceof DynamicSubscript )
+ {
+ if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
+ {
+ Object array = propertyNode.getValue( context, result );
+ int len = Array.getLength( array );
- switch(((DynamicSubscript) index).getFlag()) {
+ switch ( ( (DynamicSubscript) index ).getFlag() )
+ {
case DynamicSubscript.ALL:
- result = Array.newInstance(array.getClass().getComponentType(), len);
- System.arraycopy(array, 0, result, 0, len);
+ result = Array.newInstance( array.getClass().getComponentType(), len );
+ System.arraycopy( array, 0, result, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
- index = new Integer((len > 0) ? 0 : -1);
+ index = new Integer( ( len > 0 ) ? 0 : -1 );
break;
case DynamicSubscript.MID:
- index = new Integer((len > 0) ? (len / 2) : -1);
+ index = new Integer( ( len > 0 ) ? ( len / 2 ) : -1 );
break;
case DynamicSubscript.LAST:
- index = new Integer((len > 0) ? (len - 1) : -1);
+ index = new Integer( ( len > 0 ) ? ( len - 1 ) : -1 );
break;
}
- } else {
- if (indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT) { throw new OgnlException(
- "DynamicSubscript '" + indexNode
- + "' not allowed for object indexed property '" + propertyNode
- + "'"); }
+ }
+ else
+ {
+ if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
+ {
+ throw new OgnlException( "DynamicSubscript '" + indexNode
+ + "' not allowed for object indexed property '" + propertyNode + "'" );
+ }
}
}
- if (!handled)
+ if ( !handled )
{
- result = OgnlRuntime.getIndexedProperty(context, result,
- propertyNode.getProperty(context, result).toString(),
- index);
+ result =
+ OgnlRuntime.getIndexedProperty( context,
+ result,
+ propertyNode.getProperty( context, result ).toString(),
+ index );
handled = true;
i++;
}
@@ -125,80 +141,86 @@ public class ASTChain extends SimpleNode
}
}
}
- if (!handled)
+ if ( !handled )
{
- result = _children[i].getValue(context, result);
+ result = _children[i].getValue( context, result );
}
}
return result;
}
- protected void setValueBody(OgnlContext context, Object target, Object value)
- throws OgnlException
+ protected void setValueBody( OgnlContext context, Object target, Object value )
+ throws OgnlException
{
boolean handled = false;
- for(int i = 0, ilast = _children.length - 2; i <= ilast; ++i)
+ for ( int i = 0, ilast = _children.length - 2; i <= ilast; ++i )
{
- if (i <= ilast) {
- if (_children[i] instanceof ASTProperty)
+ if ( i <= ilast )
+ {
+ if ( _children[i] instanceof ASTProperty )
{
ASTProperty propertyNode = (ASTProperty) _children[i];
- int indexType = propertyNode.getIndexedPropertyType(context, target);
+ int indexType = propertyNode.getIndexedPropertyType( context, target );
- if ((indexType != OgnlRuntime.INDEXED_PROPERTY_NONE) && (_children[i + 1] instanceof ASTProperty))
+ if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
+ && ( _children[i + 1] instanceof ASTProperty ) )
{
ASTProperty indexNode = (ASTProperty) _children[i + 1];
- if (indexNode.isIndexedAccess())
+ if ( indexNode.isIndexedAccess() )
{
- Object index = indexNode.getProperty(context, target);
+ Object index = indexNode.getProperty( context, target );
- if (index instanceof DynamicSubscript)
+ if ( index instanceof DynamicSubscript )
{
- if (indexType == OgnlRuntime.INDEXED_PROPERTY_INT)
+ if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
- Object array = propertyNode.getValue(context, target);
- int len = Array.getLength(array);
+ Object array = propertyNode.getValue( context, target );
+ int len = Array.getLength( array );
- switch(((DynamicSubscript) index).getFlag())
+ switch ( ( (DynamicSubscript) index ).getFlag() )
{
case DynamicSubscript.ALL:
- System.arraycopy(target, 0, value, 0, len);
+ System.arraycopy( target, 0, value, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
- index = new Integer((len > 0) ? 0 : -1);
+ index = new Integer( ( len > 0 ) ? 0 : -1 );
break;
case DynamicSubscript.MID:
- index = new Integer((len > 0) ? (len / 2) : -1);
+ index = new Integer( ( len > 0 ) ? ( len / 2 ) : -1 );
break;
case DynamicSubscript.LAST:
- index = new Integer((len > 0) ? (len - 1) : -1);
+ index = new Integer( ( len > 0 ) ? ( len - 1 ) : -1 );
break;
}
- } else
+ }
+ else
{
- if (indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT)
+ if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
- throw new OgnlException("DynamicSubscript '" + indexNode
- + "' not allowed for object indexed property '" + propertyNode
- + "'");
+ throw new OgnlException( "DynamicSubscript '" + indexNode
+ + "' not allowed for object indexed property '" + propertyNode + "'" );
}
}
}
- if (!handled && i == ilast)
+ if ( !handled && i == ilast )
{
- OgnlRuntime.setIndexedProperty(context, target,
- propertyNode.getProperty(context, target).toString(),
- index, value);
+ OgnlRuntime.setIndexedProperty( context, target,
+ propertyNode.getProperty( context, target ).toString(),
+ index, value );
handled = true;
i++;
- } else if (!handled) {
- target = OgnlRuntime.getIndexedProperty(context, target,
- propertyNode.getProperty(context, target).toString(),
- index);
+ }
+ else if ( !handled )
+ {
+ target =
+ OgnlRuntime.getIndexedProperty( context,
+ target,
+ propertyNode.getProperty( context, target ).toString(),
+ index );
i++;
continue;
}
@@ -206,28 +228,33 @@ public class ASTChain extends SimpleNode
}
}
}
- if (!handled)
+ if ( !handled )
{
- target = _children[i].getValue(context, target);
+ target = _children[i].getValue( context, target );
}
}
- if (!handled)
+ if ( !handled )
{
- _children[_children.length - 1].setValue(context, target, value);
+ _children[_children.length - 1].setValue( context, target, value );
}
}
- public boolean isSimpleNavigationChain(OgnlContext context)
- throws OgnlException
+ public boolean isSimpleNavigationChain( OgnlContext context )
+ throws OgnlException
{
boolean result = false;
- if ((_children != null) && (_children.length > 0)) {
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
result = true;
- for(int i = 0; result && (i < _children.length); i++) {
- if (_children[i] instanceof SimpleNode) {
- result = ((SimpleNode) _children[i]).isSimpleProperty(context);
- } else {
+ for ( int i = 0; result && ( i < _children.length ); i++ )
+ {
+ if ( _children[i] instanceof SimpleNode )
+ {
+ result = ( (SimpleNode) _children[i] ).isSimpleProperty( context );
+ }
+ else
+ {
result = false;
}
}
@@ -247,206 +274,223 @@ public class ASTChain extends SimpleNode
public String toString()
{
- StringBuilder result = new StringBuilder("");
+ StringBuilder result = new StringBuilder( "" );
- if ((_children != null) && (_children.length > 0)) {
- for(int i = 0; i < _children.length; i++) {
- if (i > 0) {
- if (!(_children[i] instanceof ASTProperty) || !((ASTProperty) _children[i]).isIndexedAccess()) {
- result.append(".");
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
+ for ( int i = 0; i < _children.length; i++ )
+ {
+ if ( i > 0 )
+ {
+ if ( !( _children[i] instanceof ASTProperty ) || !( (ASTProperty) _children[i] ).isIndexedAccess() )
+ {
+ result.append( "." );
}
}
- result.append(_children[i].toString());
+ result.append( _children[i].toString() );
}
}
return result.toString();
}
- public String toGetSourceString(OgnlContext context, Object target)
+ public String toGetSourceString( OgnlContext context, Object target )
{
- String prevChain = (String)context.get("_currentChain");
+ String prevChain = (String) context.get( "_currentChain" );
- if (target != null)
+ if ( target != null )
{
- context.setCurrentObject(target);
- context.setCurrentType(target.getClass());
+ context.setCurrentObject( target );
+ context.setCurrentType( target.getClass() );
}
String result = "";
NodeType _lastType = null;
boolean ordered = false;
boolean constructor = false;
- try {
- if ((_children != null) && (_children.length > 0))
+ try
+ {
+ if ( ( _children != null ) && ( _children.length > 0 ) )
{
- for(int i = 0; i < _children.length; i++)
+ for ( int i = 0; i < _children.length; i++ )
{
- /* System.out.println("astchain child: " + _children[i].getClass().getName()
- + " with current object target " + context.getCurrentObject()
- + " current type: " + context.getCurrentType());*/
+ /*
+ * System.out.println("astchain child: " + _children[i].getClass().getName() +
+ * " with current object target " + context.getCurrentObject() + " current type: " +
+ * context.getCurrentType());
+ */
- String value = _children[i].toGetSourceString(context, context.getCurrentObject());
+ String value = _children[i].toGetSourceString( context, context.getCurrentObject() );
-// System.out.println("astchain child returned >> " + value + " <<");
+ // System.out.println("astchain child returned >> " + value + " <<");
- if (ASTCtor.class.isInstance(_children[i]))
+ if ( ASTCtor.class.isInstance( _children[i] ) )
constructor = true;
- if (NodeType.class.isInstance(_children[i])
- && ((NodeType)_children[i]).getGetterClass() != null)
+ if ( NodeType.class.isInstance( _children[i] )
+ && ( (NodeType) _children[i] ).getGetterClass() != null )
{
- _lastType = (NodeType)_children[i];
+ _lastType = (NodeType) _children[i];
}
-// System.out.println("Astchain i: " + i + " currentobj : " + context.getCurrentObject() + " and root: " + context.getRoot());
- if (!ASTVarRef.class.isInstance(_children[i]) && !constructor
- && !(OrderedReturn.class.isInstance(_children[i]) && ((OrderedReturn)_children[i]).getLastExpression() != null)
- && (_parent == null || !ASTSequence.class.isInstance(_parent)))
+ // System.out.println("Astchain i: " + i + " currentobj : " + context.getCurrentObject() +
+ // " and root: " + context.getRoot());
+ if ( !ASTVarRef.class.isInstance( _children[i] )
+ && !constructor
+ && !( OrderedReturn.class.isInstance( _children[i] ) && ( (OrderedReturn) _children[i] ).getLastExpression() != null )
+ && ( _parent == null || !ASTSequence.class.isInstance( _parent ) ) )
{
- value = OgnlRuntime.getCompiler().castExpression(context, _children[i], value);
+ value = OgnlRuntime.getCompiler().castExpression( context, _children[i], value );
}
- /*System.out.println("astchain value now : " + value + " with index " + i
- + " current type " + context.getCurrentType() + " current accessor " + context.getCurrentAccessor()
- + " prev type " + context.getPreviousType() + " prev accessor " + context.getPreviousAccessor());*/
+ /*
+ * System.out.println("astchain value now : " + value + " with index " + i + " current type " +
+ * context.getCurrentType() + " current accessor " + context.getCurrentAccessor() + " prev type " +
+ * context.getPreviousType() + " prev accessor " + context.getPreviousAccessor());
+ */
- if (OrderedReturn.class.isInstance(_children[i]) && ((OrderedReturn)_children[i]).getLastExpression() != null)
+ if ( OrderedReturn.class.isInstance( _children[i] )
+ && ( (OrderedReturn) _children[i] ).getLastExpression() != null )
{
ordered = true;
- OrderedReturn or = (OrderedReturn)_children[i];
+ OrderedReturn or = (OrderedReturn) _children[i];
- if (or.getCoreExpression() == null || or.getCoreExpression().trim().length() <= 0)
+ if ( or.getCoreExpression() == null || or.getCoreExpression().trim().length() <= 0 )
result = "";
else
result += or.getCoreExpression();
_lastExpression = or.getLastExpression();
- if (context.get(ExpressionCompiler.PRE_CAST) != null)
+ if ( context.get( ExpressionCompiler.PRE_CAST ) != null )
{
- _lastExpression = context.remove(ExpressionCompiler.PRE_CAST) + _lastExpression;
+ _lastExpression = context.remove( ExpressionCompiler.PRE_CAST ) + _lastExpression;
}
- } else if (ASTOr.class.isInstance(_children[i])
- || ASTAnd.class.isInstance(_children[i])
- || ASTCtor.class.isInstance(_children[i])
- || (ASTStaticField.class.isInstance(_children[i]) && _parent == null))
+ }
+ else if ( ASTOr.class.isInstance( _children[i] ) || ASTAnd.class.isInstance( _children[i] )
+ || ASTCtor.class.isInstance( _children[i] )
+ || ( ASTStaticField.class.isInstance( _children[i] ) && _parent == null ) )
{
- context.put("_noRoot", "true");
+ context.put( "_noRoot", "true" );
result = value;
- } else
+ }
+ else
{
result += value;
}
- context.put("_currentChain", result);
+ context.put( "_currentChain", result );
}
}
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
- if (_lastType != null)
+ if ( _lastType != null )
{
_getterClass = _lastType.getGetterClass();
_setterClass = _lastType.getSetterClass();
}
- if (ordered)
+ if ( ordered )
{
_coreExpression = result;
}
- context.put("_currentChain", prevChain);
+ context.put( "_currentChain", prevChain );
return result;
}
- public String toSetSourceString(OgnlContext context, Object target)
+ public String toSetSourceString( OgnlContext context, Object target )
{
- String prevChain = (String)context.get("_currentChain");
- String prevChild = (String)context.get("_lastChild");
+ String prevChain = (String) context.get( "_currentChain" );
+ String prevChild = (String) context.get( "_lastChild" );
- if (prevChain != null)
- throw new UnsupportedCompilationException("Can't compile nested chain expressions.");
+ if ( prevChain != null )
+ throw new UnsupportedCompilationException( "Can't compile nested chain expressions." );
- if (target != null)
+ if ( target != null )
{
- context.setCurrentObject(target);
- context.setCurrentType(target.getClass());
+ context.setCurrentObject( target );
+ context.setCurrentType( target.getClass() );
}
String result = "";
NodeType _lastType = null;
boolean constructor = false;
- try {
- if ((_children != null) && (_children.length > 0))
+ try
+ {
+ if ( ( _children != null ) && ( _children.length > 0 ) )
{
- if (ASTConst.class.isInstance(_children[0]))
+ if ( ASTConst.class.isInstance( _children[0] ) )
{
- throw new UnsupportedCompilationException("Can't modify constant values.");
+ throw new UnsupportedCompilationException( "Can't modify constant values." );
}
- for(int i = 0; i < _children.length; i++)
+ for ( int i = 0; i < _children.length; i++ )
{
-// System.out.println("astchain setsource child[" + i + "] : " + _children[i].getClass().getName());
+ // System.out.println("astchain setsource child[" + i + "] : " + _children[i].getClass().getName());
- if (i == (_children.length -1))
+ if ( i == ( _children.length - 1 ) )
{
- context.put("_lastChild", "true");
+ context.put( "_lastChild", "true" );
}
- String value = _children[i].toSetSourceString(context, context.getCurrentObject());
- //if (value == null || value.trim().length() <= 0)
- // return "";
+ String value = _children[i].toSetSourceString( context, context.getCurrentObject() );
+ // if (value == null || value.trim().length() <= 0)
+ // return "";
-// System.out.println("astchain setter child returned >> " + value + " <<");
+ // System.out.println("astchain setter child returned >> " + value + " <<");
- if (ASTCtor.class.isInstance(_children[i]))
+ if ( ASTCtor.class.isInstance( _children[i] ) )
constructor = true;
- if (NodeType.class.isInstance(_children[i])
- && ((NodeType)_children[i]).getGetterClass() != null)
+ if ( NodeType.class.isInstance( _children[i] )
+ && ( (NodeType) _children[i] ).getGetterClass() != null )
{
- _lastType = (NodeType)_children[i];
+ _lastType = (NodeType) _children[i];
}
- if (!ASTVarRef.class.isInstance(_children[i]) && !constructor
- && !(OrderedReturn.class.isInstance(_children[i]) && ((OrderedReturn)_children[i]).getLastExpression() != null)
- && (_parent == null || !ASTSequence.class.isInstance(_parent)))
+ if ( !ASTVarRef.class.isInstance( _children[i] )
+ && !constructor
+ && !( OrderedReturn.class.isInstance( _children[i] ) && ( (OrderedReturn) _children[i] ).getLastExpression() != null )
+ && ( _parent == null || !ASTSequence.class.isInstance( _parent ) ) )
{
- value = OgnlRuntime.getCompiler().castExpression(context, _children[i], value);
+ value = OgnlRuntime.getCompiler().castExpression( context, _children[i], value );
}
-// System.out.println("astchain setter after cast value is: " + value);
+ // System.out.println("astchain setter after cast value is: " + value);
- /*if (!constructor && !OrderedReturn.class.isInstance(_children[i])
- && (_parent == null || !ASTSequence.class.isInstance(_parent)))
- {
- value = OgnlRuntime.getCompiler().castExpression(context, _children[i], value);
- }*/
+ /*
+ * if (!constructor && !OrderedReturn.class.isInstance(_children[i]) && (_parent == null ||
+ * !ASTSequence.class.isInstance(_parent))) { value =
+ * OgnlRuntime.getCompiler().castExpression(context, _children[i], value); }
+ */
- if (ASTOr.class.isInstance(_children[i])
- || ASTAnd.class.isInstance(_children[i])
- || ASTCtor.class.isInstance(_children[i])
- || ASTStaticField.class.isInstance(_children[i])) {
- context.put("_noRoot", "true");
+ if ( ASTOr.class.isInstance( _children[i] ) || ASTAnd.class.isInstance( _children[i] )
+ || ASTCtor.class.isInstance( _children[i] ) || ASTStaticField.class.isInstance( _children[i] ) )
+ {
+ context.put( "_noRoot", "true" );
result = value;
- } else
+ }
+ else
result += value;
- context.put("_currentChain", result);
+ context.put( "_currentChain", result );
}
}
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
- context.put("_lastChild", prevChild);
- context.put("_currentChain", prevChain);
+ context.put( "_lastChild", prevChild );
+ context.put( "_currentChain", prevChain );
- if (_lastType != null)
+ if ( _lastType != null )
_setterClass = _lastType.getSetterClass();
return result;
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTConst.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTConst.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTConst.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTConst.java Sat May 14 13:18:29 2011
@@ -28,25 +28,27 @@ import java.math.BigInteger;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class ASTConst extends SimpleNode implements NodeType
+public class ASTConst
+ extends SimpleNode
+ implements NodeType
{
private Object value;
private Class _getterClass;
- public ASTConst(int id)
+ public ASTConst( int id )
{
- super(id);
+ super( id );
}
- public ASTConst(OgnlParser p, int id)
+ public ASTConst( OgnlParser p, int id )
{
- super(p, id);
+ super( p, id );
}
/** Called from parser actions. */
- public void setValue(Object value)
+ public void setValue( Object value )
{
this.value = value;
}
@@ -56,21 +58,21 @@ public class ASTConst extends SimpleNode
return value;
}
- protected Object getValueBody(OgnlContext context, Object source)
- throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
return this.value;
}
- public boolean isNodeConstant(OgnlContext context)
- throws OgnlException
+ public boolean isNodeConstant( OgnlContext context )
+ throws OgnlException
{
return true;
}
public Class getGetterClass()
{
- if (_getterClass == null)
+ if ( _getterClass == null )
return null;
return _getterClass;
@@ -85,38 +87,45 @@ public class ASTConst extends SimpleNode
{
String result;
- if (value == null)
+ if ( value == null )
{
result = "null";
- } else
+ }
+ else
{
- if (value instanceof String)
+ if ( value instanceof String )
+ {
+ result = '\"' + OgnlOps.getEscapeString( value.toString() ) + '\"';
+ }
+ else
{
- result = '\"' + OgnlOps.getEscapeString(value.toString()) + '\"';
- } else {
- if (value instanceof Character)
+ if ( value instanceof Character )
{
- result = '\'' + OgnlOps.getEscapedChar(((Character) value).charValue()) + '\'';
- } else
+ result = '\'' + OgnlOps.getEscapedChar( ( (Character) value ).charValue() ) + '\'';
+ }
+ else
{
result = value.toString();
- if (value instanceof Long)
+ if ( value instanceof Long )
{
result = result + "L";
- } else
+ }
+ else
{
- if (value instanceof BigDecimal)
+ if ( value instanceof BigDecimal )
{
result = result + "B";
- } else
+ }
+ else
{
- if (value instanceof BigInteger)
+ if ( value instanceof BigInteger )
{
result = result + "H";
- } else
+ }
+ else
{
- if (value instanceof Node)
+ if ( value instanceof Node )
{
result = ":[ " + result + " ]";
}
@@ -129,64 +138,67 @@ public class ASTConst extends SimpleNode
return result;
}
- public String toGetSourceString(OgnlContext context, Object target)
+ public String toGetSourceString( OgnlContext context, Object target )
{
- if (value == null && _parent != null && ExpressionNode.class.isInstance(_parent))
+ if ( value == null && _parent != null && ExpressionNode.class.isInstance( _parent ) )
{
- context.setCurrentType(null);
+ context.setCurrentType( null );
return "null";
- } else if (value == null)
+ }
+ else if ( value == null )
{
- context.setCurrentType(null);
+ context.setCurrentType( null );
return "";
}
_getterClass = value.getClass();
Object retval = value;
- if (_parent != null && ASTProperty.class.isInstance(_parent))
+ if ( _parent != null && ASTProperty.class.isInstance( _parent ) )
{
- context.setCurrentObject(value);
+ context.setCurrentObject( value );
return value.toString();
- } else if (value != null && Number.class.isAssignableFrom(value.getClass()))
+ }
+ else if ( value != null && Number.class.isAssignableFrom( value.getClass() ) )
{
- context.setCurrentType(OgnlRuntime.getPrimitiveWrapperClass(value.getClass()));
- context.setCurrentObject(value);
+ context.setCurrentType( OgnlRuntime.getPrimitiveWrapperClass( value.getClass() ) );
+ context.setCurrentObject( value );
return value.toString();
- } else if (!(_parent != null && value != null
- && NumericExpression.class.isAssignableFrom(_parent.getClass()))
- && String.class.isAssignableFrom(value.getClass()))
+ }
+ else if ( !( _parent != null && value != null && NumericExpression.class.isAssignableFrom( _parent.getClass() ) )
+ && String.class.isAssignableFrom( value.getClass() ) )
{
- context.setCurrentType(String.class);
+ context.setCurrentType( String.class );
- retval = '\"' + OgnlOps.getEscapeString(value.toString()) + '\"';
+ retval = '\"' + OgnlOps.getEscapeString( value.toString() ) + '\"';
- context.setCurrentObject(retval.toString());
+ context.setCurrentObject( retval.toString() );
return retval.toString();
- } else if (Character.class.isInstance(value))
+ }
+ else if ( Character.class.isInstance( value ) )
{
- Character val = (Character)value;
+ Character val = (Character) value;
- context.setCurrentType(Character.class);
+ context.setCurrentType( Character.class );
- if (Character.isLetterOrDigit(val.charValue()))
- retval = "'" + ((Character) value).charValue() + "'";
+ if ( Character.isLetterOrDigit( val.charValue() ) )
+ retval = "'" + ( (Character) value ).charValue() + "'";
else
- retval = "'" + OgnlOps.getEscapedChar(((Character) value).charValue()) + "'";
+ retval = "'" + OgnlOps.getEscapedChar( ( (Character) value ).charValue() ) + "'";
- context.setCurrentObject(retval);
+ context.setCurrentObject( retval );
return retval.toString();
}
- if (Boolean.class.isAssignableFrom(value.getClass()))
+ if ( Boolean.class.isAssignableFrom( value.getClass() ) )
{
_getterClass = Boolean.TYPE;
- context.setCurrentType(Boolean.TYPE);
- context.setCurrentObject(value);
+ context.setCurrentType( Boolean.TYPE );
+ context.setCurrentObject( value );
return value.toString();
}
@@ -194,11 +206,11 @@ public class ASTConst extends SimpleNode
return value.toString();
}
- public String toSetSourceString(OgnlContext context, Object target)
+ public String toSetSourceString( OgnlContext context, Object target )
{
- if (_parent == null)
- throw new UnsupportedCompilationException("Can't modify constant values.");
-
- return toGetSourceString(context, target);
+ if ( _parent == null )
+ throw new UnsupportedCompilationException( "Can't modify constant values." );
+
+ return toGetSourceString( context, target );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java Sat May 14 13:18:29 2011
@@ -29,29 +29,31 @@ import java.util.List;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class ASTCtor extends SimpleNode
+public class ASTCtor
+ extends SimpleNode
{
private String className;
+
private boolean isArray;
- public ASTCtor(int id)
+ public ASTCtor( int id )
{
- super(id);
+ super( id );
}
- public ASTCtor(OgnlParser p, int id)
+ public ASTCtor( OgnlParser p, int id )
{
- super(p, id);
+ super( p, id );
}
/** Called from parser action. */
- void setClassName(String className)
+ void setClassName( String className )
{
this.className = className;
}
- void setArray(boolean value)
+ void setArray( boolean value )
{
isArray = value;
}
@@ -61,163 +63,209 @@ public class ASTCtor extends SimpleNode
return isArray;
}
- protected Object getValueBody(OgnlContext context, Object source)
- throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object result, root = context.getRoot();
int count = jjtGetNumChildren();
- Object[] args = OgnlRuntime.getObjectArrayPool().create(count);
+ Object[] args = OgnlRuntime.getObjectArrayPool().create( count );
- try {
- for(int i = 0; i < count; ++i) {
- args[i] = _children[i].getValue(context, root);
+ try
+ {
+ for ( int i = 0; i < count; ++i )
+ {
+ args[i] = _children[i].getValue( context, root );
}
- if (isArray) {
- if (args.length == 1) {
- try {
- Class componentClass = OgnlRuntime.classForName(context, className);
+ if ( isArray )
+ {
+ if ( args.length == 1 )
+ {
+ try
+ {
+ Class componentClass = OgnlRuntime.classForName( context, className );
List sourceList = null;
int size;
- if (args[0] instanceof List) {
+ if ( args[0] instanceof List )
+ {
sourceList = (List) args[0];
size = sourceList.size();
- } else {
- size = (int) OgnlOps.longValue(args[0]);
}
- result = Array.newInstance(componentClass, size);
- if (sourceList != null) {
+ else
+ {
+ size = (int) OgnlOps.longValue( args[0] );
+ }
+ result = Array.newInstance( componentClass, size );
+ if ( sourceList != null )
+ {
TypeConverter converter = context.getTypeConverter();
- for(int i = 0, icount = sourceList.size(); i < icount; i++) {
- Object o = sourceList.get(i);
-
- if ((o == null) || componentClass.isInstance(o)) {
- Array.set(result, i, o);
- } else {
- Array.set(result, i, converter.convertValue(context, null, null, null, o,
- componentClass));
+ for ( int i = 0, icount = sourceList.size(); i < icount; i++ )
+ {
+ Object o = sourceList.get( i );
+
+ if ( ( o == null ) || componentClass.isInstance( o ) )
+ {
+ Array.set( result, i, o );
+ }
+ else
+ {
+ Array.set( result, i,
+ converter.convertValue( context, null, null, null, o, componentClass ) );
}
}
}
- } catch (ClassNotFoundException ex) {
- throw new OgnlException("array component class '" + className + "' not found", ex);
}
- } else {
- throw new OgnlException("only expect array size or fixed initializer list");
+ catch ( ClassNotFoundException ex )
+ {
+ throw new OgnlException( "array component class '" + className + "' not found", ex );
+ }
}
- } else {
- result = OgnlRuntime.callConstructor(context, className, args);
+ else
+ {
+ throw new OgnlException( "only expect array size or fixed initializer list" );
+ }
+ }
+ else
+ {
+ result = OgnlRuntime.callConstructor( context, className, args );
}
return result;
- } finally {
- OgnlRuntime.getObjectArrayPool().recycle(args);
+ }
+ finally
+ {
+ OgnlRuntime.getObjectArrayPool().recycle( args );
}
}
public String toString()
{
- StringBuilder result = new StringBuilder("new ").append(className);
+ StringBuilder result = new StringBuilder( "new " ).append( className );
- if (isArray) {
- if (_children[0] instanceof ASTConst) {
- result.append("[").append(_children[0]).append("]");
- } else {
- result.append("[] ").append(_children[0]);
+ if ( isArray )
+ {
+ if ( _children[0] instanceof ASTConst )
+ {
+ result.append( "[" ).append( _children[0] ).append( "]" );
+ }
+ else
+ {
+ result.append( "[] " ).append( _children[0] );
}
- } else {
- result.append("(");
- if ((_children != null) && (_children.length > 0)) {
- for(int i = 0; i < _children.length; i++) {
- if (i > 0) {
- result.append(", ");
+ }
+ else
+ {
+ result.append( "(" );
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
+ for ( int i = 0; i < _children.length; i++ )
+ {
+ if ( i > 0 )
+ {
+ result.append( ", " );
}
- result.append(_children[i]);
+ result.append( _children[i] );
}
}
- result.append(")");
+ result.append( ")" );
}
return result.toString();
}
- public String toGetSourceString(OgnlContext context, Object target)
+ public String toGetSourceString( OgnlContext context, Object target )
{
String result = "new " + className;
Class clazz = null;
Object ctorValue = null;
- try {
+ try
+ {
+
+ clazz = OgnlRuntime.classForName( context, className );
+
+ ctorValue = this.getValueBody( context, target );
+ context.setCurrentObject( ctorValue );
- clazz = OgnlRuntime.classForName(context, className);
-
- ctorValue = this.getValueBody(context, target);
- context.setCurrentObject(ctorValue);
-
- if (clazz != null && ctorValue != null) {
-
- context.setCurrentType(ctorValue.getClass());
- context.setCurrentAccessor(ctorValue.getClass());
+ if ( clazz != null && ctorValue != null )
+ {
+
+ context.setCurrentType( ctorValue.getClass() );
+ context.setCurrentAccessor( ctorValue.getClass() );
}
- if (isArray)
- context.put("_ctorClass", clazz);
+ if ( isArray )
+ context.put( "_ctorClass", clazz );
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
- try {
+ try
+ {
+
+ if ( isArray )
+ {
+ if ( _children[0] instanceof ASTConst )
+ {
+
+ result = result + "[" + _children[0].toGetSourceString( context, target ) + "]";
+ }
+ else if ( ASTProperty.class.isInstance( _children[0] ) )
+ {
- if (isArray) {
- if (_children[0] instanceof ASTConst) {
-
- result = result + "[" + _children[0].toGetSourceString(context, target) + "]";
- } else if (ASTProperty.class.isInstance(_children[0])) {
-
- result = result + "["
- + ExpressionCompiler.getRootExpression(_children[0], target, context)
- + _children[0].toGetSourceString(context, target)
- + "]";
- } else if (ASTChain.class.isInstance(_children[0])) {
+ result =
+ result + "[" + ExpressionCompiler.getRootExpression( _children[0], target, context )
+ + _children[0].toGetSourceString( context, target ) + "]";
+ }
+ else if ( ASTChain.class.isInstance( _children[0] ) )
+ {
- result = result + "[" + _children[0].toGetSourceString(context, target) + "]";
- } else {
+ result = result + "[" + _children[0].toGetSourceString( context, target ) + "]";
+ }
+ else
+ {
- result = result + "[] "+ _children[0].toGetSourceString(context, target);
+ result = result + "[] " + _children[0].toGetSourceString( context, target );
}
- } else {
+ }
+ else
+ {
result = result + "(";
- if ((_children != null) && (_children.length > 0)) {
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
Object[] values = new Object[_children.length];
String[] expressions = new String[_children.length];
Class[] types = new Class[_children.length];
// first populate arrays with child values
-
- for(int i = 0; i < _children.length; i++) {
-
- Object objValue = _children[i].getValue(context, context.getRoot());
- String value = _children[i].toGetSourceString(context, target);
- if (!ASTRootVarRef.class.isInstance(_children[i]))
+ for ( int i = 0; i < _children.length; i++ )
+ {
+
+ Object objValue = _children[i].getValue( context, context.getRoot() );
+ String value = _children[i].toGetSourceString( context, target );
+
+ if ( !ASTRootVarRef.class.isInstance( _children[i] ) )
{
- value = ExpressionCompiler.getRootExpression(_children[i], target, context) + value;
+ value = ExpressionCompiler.getRootExpression( _children[i], target, context ) + value;
}
String cast = "";
- if (ExpressionCompiler.shouldCast(_children[i])) {
+ if ( ExpressionCompiler.shouldCast( _children[i] ) )
+ {
- cast = (String)context.remove(ExpressionCompiler.PRE_CAST);
+ cast = (String) context.remove( ExpressionCompiler.PRE_CAST );
}
- if (cast == null)
+ if ( cast == null )
cast = "";
- if (!ASTConst.class.isInstance(_children[i]))
+ if ( !ASTConst.class.isInstance( _children[i] ) )
value = cast + value;
values[i] = objValue;
@@ -226,58 +274,75 @@ public class ASTCtor extends SimpleNode
}
// now try and find a matching constructor
-
+
Constructor[] cons = clazz.getConstructors();
Constructor ctor = null;
Class[] ctorParamTypes = null;
-
- for (int i=0; i < cons.length; i++)
+
+ for ( int i = 0; i < cons.length; i++ )
{
Class[] ctorTypes = cons[i].getParameterTypes();
- if (OgnlRuntime.areArgsCompatible(values, ctorTypes)
- && (ctor == null || OgnlRuntime.isMoreSpecific(ctorTypes, ctorParamTypes))) {
+ if ( OgnlRuntime.areArgsCompatible( values, ctorTypes )
+ && ( ctor == null || OgnlRuntime.isMoreSpecific( ctorTypes, ctorParamTypes ) ) )
+ {
ctor = cons[i];
ctorParamTypes = ctorTypes;
}
}
- if (ctor == null)
- ctor = OgnlRuntime.getConvertedConstructorAndArgs(context, clazz, OgnlRuntime.getConstructors(clazz), values, new Object[values.length]);
-
- if (ctor == null)
- throw new NoSuchMethodException("Unable to find constructor appropriate for arguments in class: " + clazz);
+ if ( ctor == null )
+ ctor =
+ OgnlRuntime.getConvertedConstructorAndArgs( context, clazz,
+ OgnlRuntime.getConstructors( clazz ), values,
+ new Object[values.length] );
+
+ if ( ctor == null )
+ throw new NoSuchMethodException(
+ "Unable to find constructor appropriate for arguments in class: "
+ + clazz );
ctorParamTypes = ctor.getParameterTypes();
// now loop over child values again and build up the actual source string
- for(int i = 0; i < _children.length; i++) {
- if (i > 0) {
+ for ( int i = 0; i < _children.length; i++ )
+ {
+ if ( i > 0 )
+ {
result = result + ", ";
}
String value = expressions[i];
- if (types[i].isPrimitive()) {
+ if ( types[i].isPrimitive() )
+ {
- String literal = OgnlRuntime.getNumericLiteral(types[i]);
- if (literal != null)
+ String literal = OgnlRuntime.getNumericLiteral( types[i] );
+ if ( literal != null )
value += literal;
}
- if (ctorParamTypes[i] != types[i]) {
+ if ( ctorParamTypes[i] != types[i] )
+ {
- if (values[i] != null && !types[i].isPrimitive()
- && !values[i].getClass().isArray() && !ASTConst.class.isInstance(_children[i])) {
-
- value = "(" + OgnlRuntime.getCompiler().getInterfaceClass(values[i].getClass()).getName() + ")" + value;
- } else if (!ASTConst.class.isInstance(_children[i])
- || (ASTConst.class.isInstance(_children[i]) && !types[i].isPrimitive())) {
-
- if (!types[i].isArray()
- && types[i].isPrimitive() && !ctorParamTypes[i].isPrimitive())
- value = "new " + ExpressionCompiler.getCastString(OgnlRuntime.getPrimitiveWrapperClass(types[i])) + "(" + value + ")";
+ if ( values[i] != null && !types[i].isPrimitive() && !values[i].getClass().isArray()
+ && !ASTConst.class.isInstance( _children[i] ) )
+ {
+
+ value =
+ "(" + OgnlRuntime.getCompiler().getInterfaceClass( values[i].getClass() ).getName()
+ + ")" + value;
+ }
+ else if ( !ASTConst.class.isInstance( _children[i] )
+ || ( ASTConst.class.isInstance( _children[i] ) && !types[i].isPrimitive() ) )
+ {
+
+ if ( !types[i].isArray() && types[i].isPrimitive() && !ctorParamTypes[i].isPrimitive() )
+ value =
+ "new "
+ + ExpressionCompiler.getCastString( OgnlRuntime.getPrimitiveWrapperClass( types[i] ) )
+ + "(" + value + ")";
else
value = " ($w) " + value;
}
@@ -290,21 +355,22 @@ public class ASTCtor extends SimpleNode
result = result + ")";
}
- context.setCurrentType(ctorValue != null ? ctorValue.getClass() : clazz);
- context.setCurrentAccessor(clazz);
- context.setCurrentObject(ctorValue);
+ context.setCurrentType( ctorValue != null ? ctorValue.getClass() : clazz );
+ context.setCurrentAccessor( clazz );
+ context.setCurrentObject( ctorValue );
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
- context.remove("_ctorClass");
+ context.remove( "_ctorClass" );
return result;
}
- public String toSetSourceString(OgnlContext context, Object target)
+ public String toSetSourceString( OgnlContext context, Object target )
{
return "";
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTDivide.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTDivide.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTDivide.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTDivide.java Sat May 14 13:18:29 2011
@@ -23,26 +23,30 @@ package org.apache.commons.ognl;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTDivide extends NumericExpression
+class ASTDivide
+ extends NumericExpression
{
- public ASTDivide(int id) {
- super(id);
+ public ASTDivide( int id )
+ {
+ super( id );
}
- public ASTDivide(OgnlParser p, int id) {
- super(p, id);
+ public ASTDivide( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
Object v2 = _children[1].getValue( context, source );
return OgnlOps.divide( v1, v2 );
}
- public String getExpressionOperator(int index)
+ public String getExpressionOperator( int index )
{
return "/";
}
-
+
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEq.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEq.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEq.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEq.java Sat May 14 13:18:29 2011
@@ -19,33 +19,36 @@
*/
package org.apache.commons.ognl;
-
/**
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTEq extends ComparisonExpression
+class ASTEq
+ extends ComparisonExpression
{
- public ASTEq(int id) {
- super(id);
+ public ASTEq( int id )
+ {
+ super( id );
}
- public ASTEq(OgnlParser p, int id) {
- super(p, id);
+ public ASTEq( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
Object v2 = _children[1].getValue( context, source );
- return OgnlOps.equal( v1, v2 )? Boolean.TRUE : Boolean.FALSE;
+ return OgnlOps.equal( v1, v2 ) ? Boolean.TRUE : Boolean.FALSE;
}
-
- public String getExpressionOperator(int index)
+
+ public String getExpressionOperator( int index )
{
return "==";
}
-
+
public String getComparisonFunction()
{
return "org.apache.commons.ognl.OgnlOps.equal";
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEval.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEval.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEval.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTEval.java Sat May 14 13:18:29 2011
@@ -25,49 +25,56 @@ import org.apache.commons.ognl.enhance.U
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTEval extends SimpleNode
+class ASTEval
+ extends SimpleNode
{
- public ASTEval(int id)
+ public ASTEval( int id )
{
- super(id);
+ super( id );
}
- public ASTEval(OgnlParser p, int id)
+ public ASTEval( OgnlParser p, int id )
{
- super(p, id);
+ super( p, id );
}
- protected Object getValueBody(OgnlContext context, Object source)
+ protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
- Object result, expr = _children[0].getValue(context, source), previousRoot = context.getRoot();
+ Object result, expr = _children[0].getValue( context, source ), previousRoot = context.getRoot();
Node node;
- source = _children[1].getValue(context, source);
- node = (expr instanceof Node) ? (Node) expr : (Node) Ognl.parseExpression(expr.toString());
- try {
- context.setRoot(source);
- result = node.getValue(context, source);
- } finally {
- context.setRoot(previousRoot);
+ source = _children[1].getValue( context, source );
+ node = ( expr instanceof Node ) ? (Node) expr : (Node) Ognl.parseExpression( expr.toString() );
+ try
+ {
+ context.setRoot( source );
+ result = node.getValue( context, source );
+ }
+ finally
+ {
+ context.setRoot( previousRoot );
}
return result;
}
- protected void setValueBody(OgnlContext context, Object target, Object value)
+ protected void setValueBody( OgnlContext context, Object target, Object value )
throws OgnlException
{
- Object expr = _children[0].getValue(context, target), previousRoot = context.getRoot();
+ Object expr = _children[0].getValue( context, target ), previousRoot = context.getRoot();
Node node;
- target = _children[1].getValue(context, target);
- node = (expr instanceof Node) ? (Node) expr : (Node) Ognl.parseExpression(expr.toString());
- try {
- context.setRoot(target);
- node.setValue(context, target, value);
- } finally {
- context.setRoot(previousRoot);
+ target = _children[1].getValue( context, target );
+ node = ( expr instanceof Node ) ? (Node) expr : (Node) Ognl.parseExpression( expr.toString() );
+ try
+ {
+ context.setRoot( target );
+ node.setValue( context, target, value );
+ }
+ finally
+ {
+ context.setRoot( previousRoot );
}
}
@@ -75,14 +82,14 @@ class ASTEval extends SimpleNode
{
return "(" + _children[0] + ")(" + _children[1] + ")";
}
-
- public String toGetSourceString(OgnlContext context, Object target)
+
+ public String toGetSourceString( OgnlContext context, Object target )
{
- throw new UnsupportedCompilationException("Eval expressions not supported as native java yet.");
+ throw new UnsupportedCompilationException( "Eval expressions not supported as native java yet." );
}
-
- public String toSetSourceString(OgnlContext context, Object target)
+
+ public String toSetSourceString( OgnlContext context, Object target )
{
- throw new UnsupportedCompilationException("Map expressions not supported as native java yet.");
+ throw new UnsupportedCompilationException( "Map expressions not supported as native java yet." );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreater.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreater.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreater.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreater.java Sat May 14 13:18:29 2011
@@ -19,34 +19,37 @@
*/
package org.apache.commons.ognl;
-
/**
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTGreater extends ComparisonExpression
+class ASTGreater
+ extends ComparisonExpression
{
- public ASTGreater(int id) {
- super(id);
+ public ASTGreater( int id )
+ {
+ super( id );
}
- public ASTGreater(OgnlParser p, int id) {
- super(p, id);
+ public ASTGreater( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
Object v2 = _children[1].getValue( context, source );
-
- return OgnlOps.greater( v1, v2 )? Boolean.TRUE : Boolean.FALSE;
+
+ return OgnlOps.greater( v1, v2 ) ? Boolean.TRUE : Boolean.FALSE;
}
- public String getExpressionOperator(int index)
+ public String getExpressionOperator( int index )
{
return ">";
}
-
+
public String getComparisonFunction()
{
return "org.apache.commons.ognl.OgnlOps.greater";
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreaterEq.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreaterEq.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreaterEq.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTGreaterEq.java Sat May 14 13:18:29 2011
@@ -19,33 +19,36 @@
*/
package org.apache.commons.ognl;
-
/**
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTGreaterEq extends ComparisonExpression
+class ASTGreaterEq
+ extends ComparisonExpression
{
- public ASTGreaterEq(int id) {
- super(id);
+ public ASTGreaterEq( int id )
+ {
+ super( id );
}
- public ASTGreaterEq(OgnlParser p, int id) {
- super(p, id);
+ public ASTGreaterEq( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
Object v2 = _children[1].getValue( context, source );
- return OgnlOps.less( v1, v2 )? Boolean.FALSE : Boolean.TRUE;
+ return OgnlOps.less( v1, v2 ) ? Boolean.FALSE : Boolean.TRUE;
}
- public String getExpressionOperator(int index)
+ public String getExpressionOperator( int index )
{
return ">=";
}
-
+
public String getComparisonFunction()
{
return "!org.apache.commons.ognl.OgnlOps.less";
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTIn.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTIn.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTIn.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTIn.java Sat May 14 13:18:29 2011
@@ -25,66 +25,76 @@ import org.apache.commons.ognl.enhance.U
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTIn extends SimpleNode implements NodeType
+class ASTIn
+ extends SimpleNode
+ implements NodeType
{
- public ASTIn(int id) {
- super(id);
+ public ASTIn( int id )
+ {
+ super( id );
}
- public ASTIn(OgnlParser p, int id) {
- super(p, id);
+ public ASTIn( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source )
- throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
Object v2 = _children[1].getValue( context, source );
- return OgnlOps.in( v1, v2 )? Boolean.TRUE : Boolean.FALSE;
+ return OgnlOps.in( v1, v2 ) ? Boolean.TRUE : Boolean.FALSE;
}
public String toString()
{
return _children[0] + " in " + _children[1];
}
-
+
public Class getGetterClass()
{
return Boolean.TYPE;
}
-
+
public Class getSetterClass()
{
return null;
}
-
- public String toGetSourceString(OgnlContext context, Object target)
+
+ public String toGetSourceString( OgnlContext context, Object target )
{
- try {
+ try
+ {
String result = "org.apache.commons.ognl.OgnlOps.in( ($w) ";
-
- result += OgnlRuntime.getChildSource(context, target, _children[0]) + ", ($w) " + OgnlRuntime.getChildSource(context, target, _children[1]);
-
+
+ result +=
+ OgnlRuntime.getChildSource( context, target, _children[0] ) + ", ($w) "
+ + OgnlRuntime.getChildSource( context, target, _children[1] );
+
result += ")";
- context.setCurrentType(Boolean.TYPE);
+ context.setCurrentType( Boolean.TYPE );
return result;
- } catch (NullPointerException e) {
-
+ }
+ catch ( NullPointerException e )
+ {
+
// expected to happen in some instances
e.printStackTrace();
-
- throw new UnsupportedCompilationException("evaluation resulted in null expression.");
- } catch (Throwable t)
+
+ throw new UnsupportedCompilationException( "evaluation resulted in null expression." );
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
}
-
- public String toSetSourceString(OgnlContext context, Object target)
+
+ public String toSetSourceString( OgnlContext context, Object target )
{
- throw new UnsupportedCompilationException("Map expressions not supported as native java yet.");
+ throw new UnsupportedCompilationException( "Map expressions not supported as native java yet." );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java Sat May 14 13:18:29 2011
@@ -23,66 +23,74 @@ package org.apache.commons.ognl;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class ASTInstanceof extends SimpleNode implements NodeType
+public class ASTInstanceof
+ extends SimpleNode
+ implements NodeType
{
private String targetType;
- public ASTInstanceof(int id) {
- super(id);
+ public ASTInstanceof( int id )
+ {
+ super( id );
}
- public ASTInstanceof(OgnlParser p, int id) {
- super(p, id);
+ public ASTInstanceof( OgnlParser p, int id )
+ {
+ super( p, id );
}
- void setTargetType( String targetType ) {
+ void setTargetType( String targetType )
+ {
this.targetType = targetType;
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object value = _children[0].getValue( context, source );
- return OgnlRuntime.isInstance(context, value, targetType) ? Boolean.TRUE : Boolean.FALSE;
+ return OgnlRuntime.isInstance( context, value, targetType ) ? Boolean.TRUE : Boolean.FALSE;
}
public String toString()
{
return _children[0] + " instanceof " + targetType;
}
-
+
public Class getGetterClass()
{
return boolean.class;
}
-
+
public Class getSetterClass()
{
return null;
}
-
- public String toGetSourceString(OgnlContext context, Object target)
+
+ public String toGetSourceString( OgnlContext context, Object target )
{
- try {
+ try
+ {
String ret = "";
- if (ASTConst.class.isInstance(_children[0]))
- ret = ((Boolean)getValueBody(context, target)).toString();
+ if ( ASTConst.class.isInstance( _children[0] ) )
+ ret = ( (Boolean) getValueBody( context, target ) ).toString();
else
- ret = _children[0].toGetSourceString(context, target) + " instanceof " + targetType;
-
- context.setCurrentType(Boolean.TYPE);
+ ret = _children[0].toGetSourceString( context, target ) + " instanceof " + targetType;
+
+ context.setCurrentType( Boolean.TYPE );
return ret;
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
}
-
- public String toSetSourceString(OgnlContext context, Object target)
+
+ public String toSetSourceString( OgnlContext context, Object target )
{
- return toGetSourceString(context, target);
+ return toGetSourceString( context, target );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTKeyValue.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTKeyValue.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTKeyValue.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTKeyValue.java Sat May 14 13:18:29 2011
@@ -23,14 +23,17 @@ package org.apache.commons.ognl;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTKeyValue extends SimpleNode
+class ASTKeyValue
+ extends SimpleNode
{
- public ASTKeyValue(int id) {
- super(id);
+ public ASTKeyValue( int id )
+ {
+ super( id );
}
- public ASTKeyValue(OgnlParser p, int id) {
- super(p, id);
+ public ASTKeyValue( OgnlParser p, int id )
+ {
+ super( p, id );
}
protected Node getKey()
@@ -40,13 +43,14 @@ class ASTKeyValue extends SimpleNode
protected Node getValue()
{
- return (jjtGetNumChildren() > 1) ? _children[1] : null;
+ return ( jjtGetNumChildren() > 1 ) ? _children[1] : null;
}
/**
- Returns null because this is a parser construct and does not evaluate
+ * Returns null because this is a parser construct and does not evaluate
*/
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
return null;
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLess.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLess.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLess.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLess.java Sat May 14 13:18:29 2011
@@ -19,34 +19,37 @@
*/
package org.apache.commons.ognl;
-
/**
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTLess extends ComparisonExpression
+class ASTLess
+ extends ComparisonExpression
{
- public ASTLess(int id) {
- super(id);
+ public ASTLess( int id )
+ {
+ super( id );
}
- public ASTLess(OgnlParser p, int id) {
- super(p, id);
+ public ASTLess( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
-
+
Object v2 = _children[1].getValue( context, source );
- return OgnlOps.less( v1, v2 )? Boolean.TRUE : Boolean.FALSE;
+ return OgnlOps.less( v1, v2 ) ? Boolean.TRUE : Boolean.FALSE;
}
- public String getExpressionOperator(int index)
+ public String getExpressionOperator( int index )
{
return "<";
}
-
+
public String getComparisonFunction()
{
return "org.apache.commons.ognl.OgnlOps.less";
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLessEq.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLessEq.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLessEq.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTLessEq.java Sat May 14 13:18:29 2011
@@ -19,36 +19,39 @@
*/
package org.apache.commons.ognl;
-
/**
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-class ASTLessEq extends ComparisonExpression
-{
- public ASTLessEq(int id) {
- super(id);
+class ASTLessEq
+ extends ComparisonExpression
+{
+ public ASTLessEq( int id )
+ {
+ super( id );
}
- public ASTLessEq(OgnlParser p, int id) {
- super(p, id);
+ public ASTLessEq( OgnlParser p, int id )
+ {
+ super( p, id );
}
- protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
+ protected Object getValueBody( OgnlContext context, Object source )
+ throws OgnlException
{
Object v1 = _children[0].getValue( context, source );
Object v2 = _children[1].getValue( context, source );
- return OgnlOps.greater( v1, v2 )? Boolean.FALSE : Boolean.TRUE;
+ return OgnlOps.greater( v1, v2 ) ? Boolean.FALSE : Boolean.TRUE;
}
-
- public String getExpressionOperator(int index)
+
+ public String getExpressionOperator( int index )
{
return "<=";
}
-
+
public String getComparisonFunction()
{
return "!org.apache.commons.ognl.OgnlOps.greater";
}
-
+
}