KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > dtm > ref > ExtendedType


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: ExtendedType.java,v 1.3 2004/02/16 23:06:11 minchau Exp $
18  */

19 package org.apache.xml.dtm.ref;
20
21 /**
22  * The class ExtendedType represents an extended type object used by
23  * ExpandedNameTable.
24  */

25 public final class ExtendedType
26 {
27     private int nodetype;
28     private String JavaDoc namespace;
29     private String JavaDoc localName;
30     private int hash;
31
32     /**
33      * Create an ExtendedType object from node type, namespace and local name.
34      * The hash code is calculated from the node type, namespace and local name.
35      *
36      * @param nodetype Type of the node
37      * @param namespace Namespace of the node
38      * @param localName Local name of the node
39      */

40     public ExtendedType (int nodetype, String JavaDoc namespace, String JavaDoc localName)
41     {
42       this.nodetype = nodetype;
43       this.namespace = namespace;
44       this.localName = localName;
45       this.hash = nodetype + namespace.hashCode() + localName.hashCode();
46     }
47
48     /**
49      * Create an ExtendedType object from node type, namespace, local name
50      * and a given hash code.
51      *
52      * @param nodetype Type of the node
53      * @param namespace Namespace of the node
54      * @param localName Local name of the node
55      * @param hash The given hash code
56      */

57     public ExtendedType (int nodetype, String JavaDoc namespace, String JavaDoc localName, int hash)
58     {
59       this.nodetype = nodetype;
60       this.namespace = namespace;
61       this.localName = localName;
62       this.hash = hash;
63     }
64
65     /**
66      * Redefine this ExtendedType object to represent a different extended type.
67      * This is intended to be used ONLY on the hashET object. Using it elsewhere
68      * will mess up existing hashtable entries!
69      */

70     protected void redefine(int nodetype, String JavaDoc namespace, String JavaDoc localName)
71     {
72       this.nodetype = nodetype;
73       this.namespace = namespace;
74       this.localName = localName;
75       this.hash = nodetype + namespace.hashCode() + localName.hashCode();
76     }
77
78     /**
79      * Redefine this ExtendedType object to represent a different extended type.
80      * This is intended to be used ONLY on the hashET object. Using it elsewhere
81      * will mess up existing hashtable entries!
82      */

83     protected void redefine(int nodetype, String JavaDoc namespace, String JavaDoc localName, int hash)
84     {
85       this.nodetype = nodetype;
86       this.namespace = namespace;
87       this.localName = localName;
88       this.hash = hash;
89     }
90
91     /**
92      * Override the hashCode() method in the Object class
93      */

94     public int hashCode()
95     {
96       return hash;
97     }
98
99     /**
100      * Test if this ExtendedType object is equal to the given ExtendedType.
101      *
102      * @param other The other ExtendedType object to test for equality
103      * @return true if the two ExtendedType objects are equal.
104      */

105     public boolean equals(ExtendedType other)
106     {
107       try
108       {
109         return other.nodetype == this.nodetype &&
110                 other.localName.equals(this.localName) &&
111                 other.namespace.equals(this.namespace);
112       }
113       catch(NullPointerException JavaDoc e)
114       {
115         return false;
116       }
117     }
118     
119     /**
120      * Return the node type
121      */

122     public int getNodeType()
123     {
124       return nodetype;
125     }
126     
127     /**
128      * Return the local name
129      */

130     public String JavaDoc getLocalName()
131     {
132       return localName;
133     }
134     
135     /**
136      * Return the namespace
137      */

138     public String JavaDoc getNamespace()
139     {
140       return namespace;
141     }
142
143 }
144
Popular Tags