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