001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.jxpath.ri.model.beans;
017:
018: import java.util.Locale;
019:
020: import org.apache.commons.jxpath.JXPathContext;
021: import org.apache.commons.jxpath.ri.QName;
022: import org.apache.commons.jxpath.ri.model.NodePointer;
023:
024: /**
025: * @author Dmitri Plotnikov
026: * @version $Revision: 1.11 $ $Date: 2004/02/29 14:17:41 $
027: */
028: public class NullPointer extends PropertyOwnerPointer {
029: private QName name;
030: private String id;
031:
032: public NullPointer(QName name, Locale locale) {
033: super (null, locale);
034: this .name = name;
035: }
036:
037: /**
038: * Used for the root node
039: */
040: public NullPointer(NodePointer parent, QName name) {
041: super (parent);
042: this .name = name;
043: }
044:
045: public NullPointer(Locale locale, String id) {
046: super (null, locale);
047: this .id = id;
048: }
049:
050: public QName getName() {
051: return name;
052: }
053:
054: public Object getBaseValue() {
055: return null;
056: }
057:
058: public boolean isCollection() {
059: return false;
060: }
061:
062: public boolean isLeaf() {
063: return true;
064: }
065:
066: public boolean isActual() {
067: return false;
068: }
069:
070: public PropertyPointer getPropertyPointer() {
071: return new NullPropertyPointer(this );
072: }
073:
074: public NodePointer createPath(JXPathContext context, Object value) {
075: if (parent != null) {
076: return parent.createPath(context, value).getValuePointer();
077: } else {
078: throw new UnsupportedOperationException(
079: "Cannot create the root object: " + asPath());
080: }
081: }
082:
083: public NodePointer createPath(JXPathContext context) {
084: if (parent != null) {
085: return parent.createPath(context).getValuePointer();
086: } else {
087: throw new UnsupportedOperationException(
088: "Cannot create the root object: " + asPath());
089: }
090: }
091:
092: public NodePointer createChild(JXPathContext context, QName name,
093: int index) {
094: return createPath(context).createChild(context, name, index);
095: }
096:
097: public NodePointer createChild(JXPathContext context, QName name,
098: int index, Object value) {
099: return createPath(context).createChild(context, name, index,
100: value);
101: }
102:
103: public int hashCode() {
104: return name == null ? 0 : name.hashCode();
105: }
106:
107: public boolean equals(Object object) {
108: if (object == this ) {
109: return true;
110: }
111:
112: if (!(object instanceof NullPointer)) {
113: return false;
114: }
115:
116: NullPointer other = (NullPointer) object;
117: return (name == null && other.name == null)
118: || (name != null && name.equals(other.name));
119: }
120:
121: public String asPath() {
122: if (id != null) {
123: return "id(" + id + ")";
124: }
125:
126: if (parent != null) {
127: return super .asPath();
128: }
129: return "null()";
130: }
131:
132: public int getLength() {
133: return 0;
134: }
135: }
|