1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/*
19 * $Id: XNull.java 468655 2006-10-28 07:12:06Z minchau $
20 */
21package org.apache.xpath.objects;
22
23import org.apache.xml.dtm.DTM;
24import org.apache.xpath.XPathContext;
25
26/**
27 * This class represents an XPath null object, and is capable of
28 * converting the null to other types, such as a string.
29 * @xsl.usage general
30 */
31public class XNull extends XNodeSet
32{
33    static final long serialVersionUID = -6841683711458983005L;
34
35  /**
36   * Create an XObject.
37   */
38  public XNull()
39  {
40    super();
41  }
42
43  /**
44   * Tell what kind of class this is.
45   *
46   * @return type CLASS_NULL
47   */
48  public int getType()
49  {
50    return CLASS_NULL;
51  }
52
53  /**
54   * Given a request type, return the equivalent string.
55   * For diagnostic purposes.
56   *
57   * @return type string "#CLASS_NULL"
58   */
59  public String getTypeString()
60  {
61    return "#CLASS_NULL";
62  }
63
64  /**
65   * Cast result object to a number.
66   *
67   * @return 0.0
68   */
69
70  public double num()
71  {
72    return 0.0;
73  }
74
75  /**
76   * Cast result object to a boolean.
77   *
78   * @return false
79   */
80  public boolean bool()
81  {
82    return false;
83  }
84
85  /**
86   * Cast result object to a string.
87   *
88   * @return empty string ""
89   */
90  public String str()
91  {
92    return "";
93  }
94
95  /**
96   * Cast result object to a result tree fragment.
97   *
98   * @param support XPath context to use for the conversion
99   *
100   * @return The object as a result tree fragment.
101   */
102  public int rtf(XPathContext support)
103  {
104    // DTM frag = support.createDocumentFragment();
105    // %REVIEW%
106    return DTM.NULL;
107  }
108
109//  /**
110//   * Cast result object to a nodelist.
111//   *
112//   * @return null
113//   */
114//  public DTMIterator iter()
115//  {
116//    return null;
117//  }
118
119  /**
120   * Tell if two objects are functionally equal.
121   *
122   * @param obj2 Object to compare this to
123   *
124   * @return True if the given object is of type CLASS_NULL
125   */
126  public boolean equals(XObject obj2)
127  {
128    return obj2.getType() == CLASS_NULL;
129  }
130}
131