1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.reflection.property;
17
18 import java.util.Iterator;
19
20
21
22
23 public class PropertyTokenizer implements Iterator<PropertyTokenizer> {
24 private String name;
25 private final String indexedName;
26 private String index;
27 private final String children;
28
29 public PropertyTokenizer(String fullname) {
30 int delim = fullname.indexOf('.');
31 if (delim > -1) {
32 name = fullname.substring(0, delim);
33 children = fullname.substring(delim + 1);
34 } else {
35 name = fullname;
36 children = null;
37 }
38 indexedName = name;
39 delim = name.indexOf('[');
40 if (delim > -1) {
41 if (children == null && !name.endsWith("]")) {
42 throw new IllegalArgumentException(
43 "Invalid index syntax in property: '" + name + "'. Missing closing bracket.");
44 }
45 index = name.substring(delim + 1, name.length() - 1);
46 name = name.substring(0, delim);
47 }
48 }
49
50 public String getName() {
51 return name;
52 }
53
54 public String getIndex() {
55 return index;
56 }
57
58 public String getIndexedName() {
59 return indexedName;
60 }
61
62 public String getChildren() {
63 return children;
64 }
65
66 @Override
67 public boolean hasNext() {
68 return children != null;
69 }
70
71 @Override
72 public PropertyTokenizer next() {
73 return new PropertyTokenizer(children);
74 }
75
76 @Override
77 public void remove() {
78 throw new UnsupportedOperationException(
79 "Remove is not supported, as it has no meaning in the context of properties.");
80 }
81 }