View Javadoc

    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  package org.apache.commons.jxpath.ri.model.beans;
    17
    18  import java.util.Locale;
    19
    20  import org.apache.commons.jxpath.JXPathContext;
    21  import org.apache.commons.jxpath.ri.QName;
    22  import org.apache.commons.jxpath.ri.model.NodePointer;
    23
    24  /***
    25   * @author Dmitri Plotnikov
    26   * @version $Revision: 1.11 $ $Date: 2004/02/29 14:17:41 $
    27   */
    28  public class NullPointer extends PropertyOwnerPointer {
    29      private QName name;
    30      private String id;
    31
    32      public NullPointer(QName name, Locale locale) {
    33          super(null, locale);
    34          this.name = name;
    35      }
    36
    37      /***
    38       * Used for the root node
    39       */
    40      public NullPointer(NodePointer parent, QName name) {
    41          super(parent);
    42          this.name = name;
    43      }
    44
    45      public NullPointer(Locale locale, String id) {
    46          super(null, locale);
    47          this.id = id;
    48      }
    49
    50      public QName getName() {
    51          return name;
    52      }
    53
    54      public Object getBaseValue() {
    55          return null;
    56      }
    57
    58      public boolean isCollection() {
    59          return false;
    60      }
    61
    62      public boolean isLeaf() {
    63          return true;
    64      }
    65
    66      public boolean isActual() {
    67          return false;
    68      }
    69
    70      public PropertyPointer getPropertyPointer() {
    71          return new NullPropertyPointer(this);
    72      }
    73
    74      public NodePointer createPath(JXPathContext context, Object value) {
    75          if (parent != null) {
    76              return parent.createPath(context, value).getValuePointer();
    77          }
    78          else {
    79              throw new UnsupportedOperationException(
    80                  "Cannot create the root object: " + asPath());
    81          }
    82      }
    83
    84      public NodePointer createPath(JXPathContext context) {
    85          if (parent != null) {
    86              return parent.createPath(context).getValuePointer();
    87          }
    88          else {
    89              throw new UnsupportedOperationException(
    90                  "Cannot create the root object: " + asPath());
    91          }
    92      }
    93
    94      public NodePointer createChild(
    95          JXPathContext context,
    96          QName name,
    97          int index)
    98      {
    99          return createPath(context).createChild(context, name, index);
    100     }
    101
    102     public NodePointer createChild(
    103         JXPathContext context,
    104         QName name,
    105         int index,
    106         Object value)
    107     {
    108         return createPath(context).createChild(context, name, index, value);
    109     }
    110
    111     public int hashCode() {
    112         return name == null ? 0 : name.hashCode();
    113     }
    114
    115     public boolean equals(Object object) {
    116         if (object == this) {
    117             return true;
    118         }
    119
    120         if (!(object instanceof NullPointer)) {
    121             return false;
    122         }
    123
    124         NullPointer other = (NullPointer) object;
    125         return (name == null && other.name == null)
    126             || (name != null && name.equals(other.name));
    127     }
    128
    129     public String asPath() {
    130         if (id != null) {
    131             return "id(" + id + ")";
    132         }
    133
    134         if (parent != null) {
    135             return super.asPath();
    136         }
    137         return "null()";
    138     }
    139
    140     public int getLength() {
    141         return 0;
    142     }
    143 }