View Javadoc
1   /**
2    *    Copyright 2009-2017 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.reflection.property;
17  
18  import java.util.Iterator;
19  
20  /**
21   * @author Clinton Begin
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        index = name.substring(delim + 1, name.length() - 1);
42        name = name.substring(0, delim);
43      }
44    }
45  
46    public String getName() {
47      return name;
48    }
49  
50    public String getIndex() {
51      return index;
52    }
53  
54    public String getIndexedName() {
55      return indexedName;
56    }
57  
58    public String getChildren() {
59      return children;
60    }
61  
62    @Override
63    public boolean hasNext() {
64      return children != null;
65    }
66  
67    @Override
68    public PropertyTokenizer next() {
69      return new PropertyTokenizer(children);
70    }
71  
72    @Override
73    public void remove() {
74      throw new UnsupportedOperationException("Remove is not supported, as it has no meaning in the context of properties.");
75    }
76  }