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 java.util.Iterator;
23 import java.util.Map;
24
25
26
27
28
29
30
31 public class IteratorPropertyAccessor
32 extends ObjectPropertyAccessor
33 implements PropertyAccessor
34 {
35 @Override
36 public Object getProperty( Map<String, Object> context, Object target, Object name )
37 throws OgnlException
38 {
39 Object result;
40 Iterator<?> iterator = (Iterator<?>) target;
41
42 if ( name instanceof String )
43 {
44 if ( "next".equals( name ) )
45 {
46 result = iterator.next();
47 }
48 else
49 {
50 if ( "hasNext".equals( name ) )
51 {
52 result = iterator.hasNext() ? Boolean.TRUE : Boolean.FALSE;
53 }
54 else
55 {
56 result = super.getProperty( context, target, name );
57 }
58 }
59 }
60 else
61 {
62 result = super.getProperty( context, target, name );
63 }
64 return result;
65 }
66
67 @Override
68 public void setProperty( Map<String, Object> context, Object target, Object name, Object value )
69 throws OgnlException
70 {
71 throw new IllegalArgumentException( "can't set property " + name + " on Iterator" );
72 }
73 }