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 java.util.Locale;
20
21 import org.apache.commons.jxpath.JXPathContext;
22 import org.apache.commons.jxpath.ri.QName;
23 import org.apache.commons.jxpath.ri.model.NodePointer;
24
25
26
27
28
29
30 public class NullPointer extends PropertyOwnerPointer {
31 private QName name;
32 private String id;
33
34 private static final long serialVersionUID = 2193425983220679887L;
35
36
37
38
39
40
41 public NullPointer(QName name, Locale locale) {
42 super(null, locale);
43 this.name = name;
44 }
45
46
47
48
49
50
51 public NullPointer(NodePointer parent, QName name) {
52 super(parent);
53 this.name = name;
54 }
55
56
57
58
59
60
61 public NullPointer(Locale locale, String id) {
62 super(null, locale);
63 this.id = id;
64 }
65
66 public QName getName() {
67 return name;
68 }
69
70 public Object getBaseValue() {
71 return null;
72 }
73
74 public boolean isCollection() {
75 return false;
76 }
77
78 public boolean isLeaf() {
79 return true;
80 }
81
82 public boolean isActual() {
83 return false;
84 }
85
86 public PropertyPointer getPropertyPointer() {
87 return new NullPropertyPointer(this);
88 }
89
90 public NodePointer createPath(JXPathContext context, Object value) {
91 if (parent != null) {
92 return parent.createPath(context, value).getValuePointer();
93 }
94 throw new UnsupportedOperationException(
95 "Cannot create the root object: " + asPath());
96 }
97
98 public NodePointer createPath(JXPathContext context) {
99 if (parent != null) {
100 return parent.createPath(context).getValuePointer();
101 }
102 throw new UnsupportedOperationException(
103 "Cannot create the root object: " + asPath());
104 }
105
106 public NodePointer createChild(
107 JXPathContext context,
108 QName name,
109 int index) {
110 return createPath(context).createChild(context, name, index);
111 }
112
113 public NodePointer createChild(
114 JXPathContext context,
115 QName name,
116 int index,
117 Object value) {
118 return createPath(context).createChild(context, name, index, value);
119 }
120
121 public int hashCode() {
122 return name == null ? 0 : name.hashCode();
123 }
124
125 public boolean equals(Object object) {
126 if (object == this) {
127 return true;
128 }
129
130 if (!(object instanceof NullPointer)) {
131 return false;
132 }
133
134 NullPointer other = (NullPointer) object;
135 return name == other.name || name != null && name.equals(other.name);
136 }
137
138 public String asPath() {
139 if (id != null) {
140 return "id(" + id + ")";
141 }
142 return parent == null ? "null()" : super.asPath();
143 }
144
145 public int getLength() {
146 return 0;
147 }
148 }