1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model.beans;
18
19 import org.apache.commons.jxpath.JXPathContext;
20 import org.apache.commons.jxpath.ri.QName;
21 import org.apache.commons.jxpath.ri.model.NodePointer;
22
23
24
25
26
27
28
29
30
31
32
33
34 public class NullElementPointer extends CollectionPointer {
35
36 private static final long serialVersionUID = 8714236818791036721L;
37
38
39
40
41
42
43 public NullElementPointer(NodePointer parent, int index) {
44 super(parent, (Object) null);
45 this.index = index;
46 }
47
48 public QName getName() {
49 return null;
50 }
51
52 public Object getBaseValue() {
53 return null;
54 }
55
56 public Object getImmediateNode() {
57 return null;
58 }
59
60 public boolean isLeaf() {
61 return true;
62 }
63
64 public boolean isCollection() {
65 return false;
66 }
67
68
69
70
71
72 public PropertyPointer getPropertyPointer() {
73 return new NullPropertyPointer(this);
74 }
75
76 public NodePointer getValuePointer() {
77 return new NullPointer(this, getName());
78 }
79
80 public void setValue(Object value) {
81 throw new UnsupportedOperationException(
82 "Collection element does not exist: " + this);
83 }
84
85 public boolean isActual() {
86 return false;
87 }
88
89 public boolean isContainer() {
90 return true;
91 }
92
93 public NodePointer createPath(JXPathContext context) {
94 return parent.createChild(context, null, index);
95 }
96
97 public NodePointer createPath(JXPathContext context, Object value) {
98 return parent.createChild(context, null, index, value);
99 }
100
101 public int hashCode() {
102 return getImmediateParentPointer().hashCode() + index;
103 }
104
105 public boolean equals(Object object) {
106 if (object == this) {
107 return true;
108 }
109
110 if (!(object instanceof NullElementPointer)) {
111 return false;
112 }
113
114 NullElementPointer other = (NullElementPointer) object;
115 return getImmediateParentPointer() == other.getImmediateParentPointer()
116 && index == other.index;
117 }
118
119 public int getLength() {
120 return 0;
121 }
122
123 public String asPath() {
124 StringBuffer buffer = new StringBuffer();
125 NodePointer parent = getImmediateParentPointer();
126 if (parent != null) {
127 buffer.append(parent.asPath());
128 }
129 if (index != WHOLE_COLLECTION) {
130
131 if (parent != null && parent.getIndex() != WHOLE_COLLECTION) {
132 buffer.append("/.");
133 }
134 else if (parent != null
135 && parent.getImmediateParentPointer() != null
136 && parent.getImmediateParentPointer().getIndex() != WHOLE_COLLECTION) {
137 buffer.append("/.");
138 }
139 buffer.append("[").append(index + 1).append(']');
140 }
141
142 return buffer.toString();
143 }
144 }