View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.portals.applications.springmvc;
    18
    19  import java.io.Serializable;
    20  import java.lang.Comparable;
    21
    22  public class DOMTree implements Comparable, Serializable
    23  {
    24      private static final long serialVersionUID = 1L;
    25
    26      private String name;
    27      private String path;
    28      private org.w3c.dom.Document doc;
    29      private String message;
    30
    31      private int hashCode = Integer.MIN_VALUE;
    32
    33
    34  	public DOMTree()
    35  	{
    36  		super();
    37  	}
    38
    39  	public DOMTree( String name, String path )
    40  	{
    41  		super();
    42  		setName( name );
    43  		setPath( path );
    44  	}
    45
    46  	public String getName()
    47  	{
    48          return name;
    49      }
    50
    51      public void setName( String name )
    52      {
    53          if (name == null) name = "";
    54          this.name = name;
    55          this.hashCode = Integer.MIN_VALUE;
    56      }
    57
    58  	public String getPath()
    59  	{
    60          return path;
    61      }
    62
    63      public void setPath( String path )
    64      {
    65          if (path == null) path = "";
    66          this.path = path;
    67          this.hashCode = Integer.MIN_VALUE;
    68      }
    69
    70      public void setParsedDocument( org.w3c.dom.Document doc )
    71      {
    72      	this.doc = doc;
    73      }
    74      public org.w3c.dom.Document getParsedDocument()
    75      {
    76      	return doc;
    77      }
    78
    79      public String getMessage()
    80  	{
    81          return message;
    82      }
    83
    84      public void setMessage( String message )
    85      {
    86          this.message = message;
    87      }
    88
    89      public int compareTo(Object obj)
    90      {
    91          if (obj == null) throw new NullPointerException( "Cannot compare to null object" );
    92          if (!(obj instanceof DOMTree)) throw new ClassCastException( "Can only compare to class" + this.getClass().getName() );
    93          if (this.name == null || this.path == null) throw new NullPointerException( "This object is not initialized yet" );
    94          if (this.equals(obj)) return 0;
    95          DOMTree dt = (DOMTree)obj;
    96          int res = getName().compareTo(dt.getName());
    97          if (res != 0) return res;
    98          return getPath().compareTo(dt.getPath());
    99      }
    100
    101     public boolean equals(Object obj)
    102     {
    103         if ( obj == null ) return false;
    104         if ( !(obj instanceof DOMTree) ) return false;
    105         if ( this.name == null || this.path == null ) return false;
    106         DOMTree dt = (DOMTree)obj;
    107         return (this.name.equals(dt.getName()) &&
    108                  this.path.equals(dt.getPath()));
    109     }
    110
    111     public int hashCode()
    112     {
    113 		if (Integer.MIN_VALUE == this.hashCode)
    114 		{
    115 			String hashStr = this.getClass().getName() + ":" + this.toString();
    116 			this.hashCode = hashStr.hashCode();
    117 		}
    118 		return this.hashCode;
    119     }
    120
    121     public String toString()
    122     {
    123         return this.name + ":" + this.path;
    124     }
    125
    126 }