1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model.dynabeans;
18
19 import java.util.Locale;
20
21 import org.apache.commons.beanutils.DynaBean;
22 import org.apache.commons.jxpath.ri.QName;
23 import org.apache.commons.jxpath.ri.model.NodePointer;
24 import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer;
25 import org.apache.commons.jxpath.ri.model.beans.PropertyPointer;
26
27
28
29
30
31
32
33
34
35 public class DynaBeanPointer extends PropertyOwnerPointer {
36 private static final long serialVersionUID = -9135052498044877965L;
37
38 private QName name;
39 private DynaBean dynaBean;
40
41
42
43
44
45
46
47 public DynaBeanPointer(QName name, DynaBean dynaBean, Locale locale) {
48 super(null, locale);
49 this.name = name;
50 this.dynaBean = dynaBean;
51 }
52
53
54
55
56
57
58
59 public DynaBeanPointer(NodePointer parent, QName name, DynaBean dynaBean) {
60 super(parent);
61 this.name = name;
62 this.dynaBean = dynaBean;
63 }
64
65 public PropertyPointer getPropertyPointer() {
66 return new DynaBeanPropertyPointer(this, dynaBean);
67 }
68
69 public QName getName() {
70 return name;
71 }
72
73 public Object getBaseValue() {
74 return dynaBean;
75 }
76
77 public Object getImmediateNode() {
78 return dynaBean;
79 }
80
81 public boolean isCollection() {
82 return false;
83 }
84
85 public int getLength() {
86 return 1;
87 }
88
89 public boolean isLeaf() {
90 return false;
91 }
92
93 public int hashCode() {
94 return name == null ? 0 : name.hashCode();
95 }
96
97 public boolean equals(Object object) {
98 if (object == this) {
99 return true;
100 }
101
102 if (!(object instanceof DynaBeanPointer)) {
103 return false;
104 }
105
106 DynaBeanPointer other = (DynaBeanPointer) object;
107 if (!(equalObjects(parent, other.parent) && equalObjects(name, other.name))) {
108 return false;
109 }
110
111 int iThis = (index == WHOLE_COLLECTION ? 0 : index);
112 int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index);
113 return iThis == iOther && dynaBean == other.dynaBean;
114 }
115
116 public String asPath() {
117 return parent == null ? "/" : super.asPath();
118 }
119
120
121
122
123
124
125
126 private static boolean equalObjects(Object o1, Object o2) {
127 return o1 == o2 || o1 != null && o1.equals(o2);
128 }
129 }