1 /*
2  * reserved comment block
3  * DO NOT REMOVE OR ALTER!
4  */
5 /*
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 package com.sun.org.apache.xml.internal.dtm.ref;
23 
24 /**
25  * The class ExtendedType represents an extended type object used by
26  * ExpandedNameTable.
27  */
28 public final class ExtendedType
29 {
30     private int nodetype;
31     private String namespace;
32     private String localName;
33     private int hash;
34 
35     /**
36      * Create an ExtendedType object from node type, namespace and local name.
37      * The hash code is calculated from the node type, namespace and local name.
38      *
39      * @param nodetype Type of the node
40      * @param namespace Namespace of the node
41      * @param localName Local name of the node
42      */
ExtendedType(int nodetype, String namespace, String localName)43     public ExtendedType (int nodetype, String namespace, String localName)
44     {
45       this.nodetype = nodetype;
46       this.namespace = namespace;
47       this.localName = localName;
48       this.hash = nodetype + namespace.hashCode() + localName.hashCode();
49     }
50 
51     /**
52      * Create an ExtendedType object from node type, namespace, local name
53      * and a given hash code.
54      *
55      * @param nodetype Type of the node
56      * @param namespace Namespace of the node
57      * @param localName Local name of the node
58      * @param hash The given hash code
59      */
ExtendedType(int nodetype, String namespace, String localName, int hash)60     public ExtendedType (int nodetype, String namespace, String localName, int hash)
61     {
62       this.nodetype = nodetype;
63       this.namespace = namespace;
64       this.localName = localName;
65       this.hash = hash;
66     }
67 
68     /**
69      * Redefine this ExtendedType object to represent a different extended type.
70      * This is intended to be used ONLY on the hashET object. Using it elsewhere
71      * will mess up existing hashtable entries!
72      */
redefine(int nodetype, String namespace, String localName)73     protected void redefine(int nodetype, String namespace, String localName)
74     {
75       this.nodetype = nodetype;
76       this.namespace = namespace;
77       this.localName = localName;
78       this.hash = nodetype + namespace.hashCode() + localName.hashCode();
79     }
80 
81     /**
82      * Redefine this ExtendedType object to represent a different extended type.
83      * This is intended to be used ONLY on the hashET object. Using it elsewhere
84      * will mess up existing hashtable entries!
85      */
redefine(int nodetype, String namespace, String localName, int hash)86     protected void redefine(int nodetype, String namespace, String localName, int hash)
87     {
88       this.nodetype = nodetype;
89       this.namespace = namespace;
90       this.localName = localName;
91       this.hash = hash;
92     }
93 
94     /**
95      * Override the hashCode() method in the Object class
96      */
hashCode()97     public int hashCode()
98     {
99       return hash;
100     }
101 
102     /**
103      * Test if this ExtendedType object is equal to the given ExtendedType.
104      *
105      * @param other The other ExtendedType object to test for equality
106      * @return true if the two ExtendedType objects are equal.
107      */
equals(ExtendedType other)108     public boolean equals(ExtendedType other)
109     {
110       try
111       {
112         return other.nodetype == this.nodetype &&
113                 other.localName.equals(this.localName) &&
114                 other.namespace.equals(this.namespace);
115       }
116       catch(NullPointerException e)
117       {
118         return false;
119       }
120     }
121 
122     /**
123      * Return the node type
124      */
getNodeType()125     public int getNodeType()
126     {
127       return nodetype;
128     }
129 
130     /**
131      * Return the local name
132      */
getLocalName()133     public String getLocalName()
134     {
135       return localName;
136     }
137 
138     /**
139      * Return the namespace
140      */
getNamespace()141     public String getNamespace()
142     {
143       return namespace;
144     }
145 
146 }
147