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: /*
017: * $Id: XNull.java,v 1.14 2004/08/17 19:25:39 jycli Exp $
018: */
019: package org.apache.xpath.objects;
020:
021: import org.apache.xml.dtm.DTM;
022: import org.apache.xpath.XPathContext;
023:
024: /**
025: * This class represents an XPath null object, and is capable of
026: * converting the null to other types, such as a string.
027: * @xsl.usage general
028: */
029: public class XNull extends XNodeSet {
030: static final long serialVersionUID = -6841683711458983005L;
031:
032: /**
033: * Create an XObject.
034: */
035: public XNull() {
036: super ();
037: }
038:
039: /**
040: * Tell what kind of class this is.
041: *
042: * @return type CLASS_NULL
043: */
044: public int getType() {
045: return CLASS_NULL;
046: }
047:
048: /**
049: * Given a request type, return the equivalent string.
050: * For diagnostic purposes.
051: *
052: * @return type string "#CLASS_NULL"
053: */
054: public String getTypeString() {
055: return "#CLASS_NULL";
056: }
057:
058: /**
059: * Cast result object to a number.
060: *
061: * @return 0.0
062: */
063:
064: public double num() {
065: return 0.0;
066: }
067:
068: /**
069: * Cast result object to a boolean.
070: *
071: * @return false
072: */
073: public boolean bool() {
074: return false;
075: }
076:
077: /**
078: * Cast result object to a string.
079: *
080: * @return empty string ""
081: */
082: public String str() {
083: return "";
084: }
085:
086: /**
087: * Cast result object to a result tree fragment.
088: *
089: * @param support XPath context to use for the conversion
090: *
091: * @return The object as a result tree fragment.
092: */
093: public int rtf(XPathContext support) {
094: // DTM frag = support.createDocumentFragment();
095: // %REVIEW%
096: return DTM.NULL;
097: }
098:
099: // /**
100: // * Cast result object to a nodelist.
101: // *
102: // * @return null
103: // */
104: // public DTMIterator iter()
105: // {
106: // return null;
107: // }
108:
109: /**
110: * Tell if two objects are functionally equal.
111: *
112: * @param obj2 Object to compare this to
113: *
114: * @return True if the given object is of type CLASS_NULL
115: */
116: public boolean equals(XObject obj2) {
117: return obj2.getType() == CLASS_NULL;
118: }
119: }
|