001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: XNull.java 468655 2006-10-28 07:12:06Z minchau $
020     */
021    package org.apache.xpath.objects;
022    
023    import org.apache.xml.dtm.DTM;
024    import org.apache.xpath.XPathContext;
025    
026    /**
027     * This class represents an XPath null object, and is capable of
028     * converting the null to other types, such as a string.
029     * @xsl.usage general
030     */
031    public class XNull extends XNodeSet
032    {
033        static final long serialVersionUID = -6841683711458983005L;
034    
035      /**
036       * Create an XObject.
037       */
038      public XNull()
039      {
040        super();
041      }
042    
043      /**
044       * Tell what kind of class this is.
045       *
046       * @return type CLASS_NULL
047       */
048      public int getType()
049      {
050        return CLASS_NULL;
051      }
052    
053      /**
054       * Given a request type, return the equivalent string.
055       * For diagnostic purposes.
056       *
057       * @return type string "#CLASS_NULL"
058       */
059      public String getTypeString()
060      {
061        return "#CLASS_NULL";
062      }
063    
064      /**
065       * Cast result object to a number.
066       * 
067       * @return 0.0
068       */
069    
070      public double num()
071      {
072        return 0.0;
073      }
074    
075      /**
076       * Cast result object to a boolean.
077       *
078       * @return false
079       */
080      public boolean bool()
081      {
082        return false;
083      }
084    
085      /**
086       * Cast result object to a string.
087       *
088       * @return empty string ""
089       */
090      public String str()
091      {
092        return "";
093      }
094    
095      /**
096       * Cast result object to a result tree fragment.
097       *
098       * @param support XPath context to use for the conversion
099       *
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    }