| 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.ExpressionCompiler; |
| 23 | |
import org.apache.commons.ognl.enhance.OrderedReturn; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public class ASTSequence |
| 31 | |
extends SimpleNode |
| 32 | |
implements NodeType, OrderedReturn |
| 33 | |
{ |
| 34 | |
private Class getterClass; |
| 35 | |
|
| 36 | |
private String lastExpression; |
| 37 | |
|
| 38 | |
private String coreExpression; |
| 39 | |
|
| 40 | |
public ASTSequence( int id ) |
| 41 | |
{ |
| 42 | 40 | super( id ); |
| 43 | 40 | } |
| 44 | |
|
| 45 | |
public ASTSequence( OgnlParser p, int id ) |
| 46 | |
{ |
| 47 | 0 | super( p, id ); |
| 48 | 0 | } |
| 49 | |
|
| 50 | |
public void jjtClose() |
| 51 | |
{ |
| 52 | 40 | flattenTree(); |
| 53 | 40 | } |
| 54 | |
|
| 55 | |
protected Object getValueBody( OgnlContext context, Object source ) |
| 56 | |
throws OgnlException |
| 57 | |
{ |
| 58 | 43 | Object result = null; |
| 59 | 134 | for ( int i = 0; i < children.length; ++i ) |
| 60 | |
{ |
| 61 | 91 | result = children[i].getValue( context, source ); |
| 62 | |
} |
| 63 | |
|
| 64 | 43 | return result; |
| 65 | |
} |
| 66 | |
|
| 67 | |
protected void setValueBody( OgnlContext context, Object target, Object value ) |
| 68 | |
throws OgnlException |
| 69 | |
{ |
| 70 | 2 | int last = children.length - 1; |
| 71 | 4 | for ( int i = 0; i < last; ++i ) |
| 72 | |
{ |
| 73 | 2 | children[i].getValue( context, target ); |
| 74 | |
} |
| 75 | 2 | children[last].setValue( context, target, value ); |
| 76 | 2 | } |
| 77 | |
|
| 78 | |
public Class getGetterClass() |
| 79 | |
{ |
| 80 | 3 | return getterClass; |
| 81 | |
} |
| 82 | |
|
| 83 | |
public Class getSetterClass() |
| 84 | |
{ |
| 85 | 2 | return null; |
| 86 | |
} |
| 87 | |
|
| 88 | |
public String getLastExpression() |
| 89 | |
{ |
| 90 | 6 | return lastExpression; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public String getCoreExpression() |
| 94 | |
{ |
| 95 | 3 | return coreExpression; |
| 96 | |
} |
| 97 | |
|
| 98 | |
public String toSetSourceString( OgnlContext context, Object target ) |
| 99 | |
{ |
| 100 | 13 | return ""; |
| 101 | |
} |
| 102 | |
|
| 103 | |
public String toGetSourceString( OgnlContext context, Object target ) |
| 104 | |
{ |
| 105 | 13 | String result = ""; |
| 106 | |
|
| 107 | 13 | NodeType lastType = null; |
| 108 | |
|
| 109 | 18 | for ( int i = 0; i < children.length; ++i ) |
| 110 | |
{ |
| 111 | |
|
| 112 | 16 | String seqValue = children[i].toGetSourceString( context, target ); |
| 113 | |
|
| 114 | 5 | if ( ( i + 1 ) < children.length && ASTOr.class.isInstance( children[i] ) ) |
| 115 | |
{ |
| 116 | 1 | seqValue = "(" + seqValue + ")"; |
| 117 | |
} |
| 118 | |
|
| 119 | 5 | if ( i > 0 && ASTProperty.class.isInstance( children[i] ) && seqValue != null |
| 120 | |
&& seqValue.trim().length() > 0 ) |
| 121 | |
{ |
| 122 | 2 | String pre = (String) context.get( "_currentChain" ); |
| 123 | 2 | if ( pre == null ) |
| 124 | |
{ |
| 125 | 1 | pre = ""; |
| 126 | |
} |
| 127 | |
|
| 128 | 2 | seqValue = |
| 129 | |
ExpressionCompiler.getRootExpression( children[i], context.getRoot(), context ) + pre + seqValue; |
| 130 | 2 | context.setCurrentAccessor( context.getRoot().getClass() ); |
| 131 | |
} |
| 132 | |
|
| 133 | 5 | if ( ( i + 1 ) >= children.length ) |
| 134 | |
{ |
| 135 | 2 | coreExpression = result; |
| 136 | 2 | lastExpression = seqValue; |
| 137 | |
} |
| 138 | |
|
| 139 | 5 | if ( seqValue != null && seqValue.trim().length() > 0 && ( i + 1 ) < children.length ) |
| 140 | |
{ |
| 141 | 1 | result += seqValue + ";"; |
| 142 | |
} |
| 143 | 4 | else if ( seqValue != null && seqValue.trim().length() > 0 ) |
| 144 | |
{ |
| 145 | 2 | result += seqValue; |
| 146 | |
} |
| 147 | |
|
| 148 | |
|
| 149 | 5 | if ( NodeType.class.isInstance( children[i] ) && ( (NodeType) children[i] ).getGetterClass() != null ) |
| 150 | |
{ |
| 151 | 2 | lastType = (NodeType) children[i]; |
| 152 | |
} |
| 153 | |
} |
| 154 | |
|
| 155 | 2 | if ( lastType != null ) |
| 156 | |
{ |
| 157 | 2 | getterClass = lastType.getGetterClass(); |
| 158 | |
} |
| 159 | |
|
| 160 | 2 | return result; |
| 161 | |
} |
| 162 | |
|
| 163 | |
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data ) |
| 164 | |
throws OgnlException |
| 165 | |
{ |
| 166 | 0 | return visitor.visit( this, data ); |
| 167 | |
} |
| 168 | |
} |