| 1 | |
package org.apache.commons.ognl; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.commons.ognl.enhance.UnsupportedCompilationException; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
public abstract class ComparisonExpression |
| 28 | |
extends BooleanExpression |
| 29 | |
{ |
| 30 | |
|
| 31 | |
private static final long serialVersionUID = -5945855000509930682L; |
| 32 | |
|
| 33 | |
public ComparisonExpression( int id ) |
| 34 | |
{ |
| 35 | 175 | super( id ); |
| 36 | 175 | } |
| 37 | |
|
| 38 | |
public ComparisonExpression( OgnlParser p, int id ) |
| 39 | |
{ |
| 40 | 0 | super( p, id ); |
| 41 | 0 | } |
| 42 | |
|
| 43 | |
public abstract String getComparisonFunction(); |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
@Override |
| 49 | |
public String toGetSourceString( OgnlContext context, Object target ) |
| 50 | |
{ |
| 51 | 78 | if ( target == null ) |
| 52 | |
{ |
| 53 | 48 | throw new UnsupportedCompilationException( "Current target is null, can't compile." ); |
| 54 | |
} |
| 55 | |
|
| 56 | |
try |
| 57 | |
{ |
| 58 | |
|
| 59 | 30 | Object value = getValueBody( context, target ); |
| 60 | |
|
| 61 | 29 | if ( value != null && Boolean.class.isAssignableFrom( value.getClass() ) ) |
| 62 | |
{ |
| 63 | 29 | getterClass = Boolean.TYPE; |
| 64 | |
} |
| 65 | 0 | else if ( value != null ) |
| 66 | |
{ |
| 67 | 0 | getterClass = value.getClass(); |
| 68 | |
} |
| 69 | |
else |
| 70 | |
{ |
| 71 | 0 | getterClass = Boolean.TYPE; |
| 72 | |
} |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | 29 | OgnlRuntime.getChildSource( context, target, children[0] ); |
| 77 | 28 | OgnlRuntime.getChildSource( context, target, children[1] ); |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | 28 | boolean conversion = OgnlRuntime.shouldConvertNumericTypes( context ); |
| 83 | |
|
| 84 | 28 | StringBuilder result = new StringBuilder( "(" ); |
| 85 | 28 | if ( conversion ) |
| 86 | |
{ |
| 87 | 19 | result.append( getComparisonFunction() ).append( "( ($w) (" ); |
| 88 | |
} |
| 89 | |
|
| 90 | 28 | result.append( OgnlRuntime.getChildSource( context, target, children[0], conversion ) ) |
| 91 | |
.append( " " ); |
| 92 | |
|
| 93 | 28 | if ( conversion ) |
| 94 | |
{ |
| 95 | 19 | result.append( "), ($w) " ); |
| 96 | |
} |
| 97 | |
else |
| 98 | |
{ |
| 99 | 9 | result.append( getExpressionOperator( 0 ) ); |
| 100 | |
} |
| 101 | |
|
| 102 | 28 | result.append( "" ).append( OgnlRuntime.getChildSource( context, target, children[1], conversion ) ); |
| 103 | |
|
| 104 | 28 | if ( conversion ) |
| 105 | |
{ |
| 106 | 19 | result.append( ")" ); |
| 107 | |
} |
| 108 | |
|
| 109 | 28 | context.setCurrentType( Boolean.TYPE ); |
| 110 | |
|
| 111 | 28 | result.append( ")" ); |
| 112 | |
|
| 113 | 28 | return result.toString(); |
| 114 | |
} |
| 115 | 1 | catch ( NullPointerException e ) |
| 116 | |
{ |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | 1 | throw new UnsupportedCompilationException( "evaluation resulted in null expression." ); |
| 121 | |
} |
| 122 | 1 | catch ( Throwable t ) |
| 123 | |
{ |
| 124 | 1 | throw OgnlOps.castToRuntime( t ); |
| 125 | |
} |
| 126 | |
} |
| 127 | |
} |