1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model.dynamic;
18
19 import java.util.Locale;
20
21 import org.apache.commons.jxpath.DynamicPropertyHandler;
22 import org.apache.commons.jxpath.JXPathIntrospector;
23 import org.apache.commons.jxpath.ri.QName;
24 import org.apache.commons.jxpath.ri.model.NodeIterator;
25 import org.apache.commons.jxpath.ri.model.NodePointer;
26 import org.apache.commons.jxpath.ri.model.beans.PropertyIterator;
27 import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer;
28 import org.apache.commons.jxpath.ri.model.beans.PropertyPointer;
29
30
31
32
33
34
35
36
37
38 public class DynamicPointer extends PropertyOwnerPointer {
39 private QName name;
40 private Object bean;
41 private DynamicPropertyHandler handler;
42
43 private static final long serialVersionUID = -1842347025295904256L;
44
45
46
47
48
49
50
51
52 public DynamicPointer(QName name, Object bean,
53 DynamicPropertyHandler handler, Locale locale) {
54 super(null, locale);
55 this.name = name;
56 this.bean = bean;
57 this.handler = handler;
58 }
59
60
61
62
63
64
65
66
67 public DynamicPointer(NodePointer parent, QName name,
68 Object bean, DynamicPropertyHandler handler) {
69 super(parent);
70 this.name = name;
71 this.bean = bean;
72 this.handler = handler;
73 }
74
75 public PropertyPointer getPropertyPointer() {
76 return new DynamicPropertyPointer(this, handler);
77 }
78
79 public NodeIterator createNodeIterator(
80 String property, boolean reverse, NodePointer startWith) {
81 return new PropertyIterator(this, property, reverse, startWith);
82 }
83
84 public NodeIterator attributeIterator(QName name) {
85 return new DynamicAttributeIterator(this, name);
86 }
87
88 public QName getName() {
89 return name;
90 }
91
92 public boolean isDynamicPropertyDeclarationSupported() {
93 return true;
94 }
95
96
97
98
99
100 public Object getBaseValue() {
101 return bean;
102 }
103
104 public boolean isLeaf() {
105 Object value = getNode();
106 return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic();
107 }
108
109 public boolean isCollection() {
110 return false;
111 }
112
113
114
115
116
117 public int getLength() {
118 return 1;
119 }
120
121 public String asPath() {
122 return parent == null ? "/" : super.asPath();
123 }
124
125 public int hashCode() {
126 return System.identityHashCode(bean) + (name == null ? 0 : name.hashCode());
127 }
128
129 public boolean equals(Object object) {
130 if (object == this) {
131 return true;
132 }
133
134 if (!(object instanceof DynamicPointer)) {
135 return false;
136 }
137
138 DynamicPointer other = (DynamicPointer) object;
139 if (bean != other.bean) {
140 return false;
141 }
142 return name == other.name || name != null && name.equals(other.name);
143 }
144 }