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