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