001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: ExtendedType.java 468653 2006-10-28 07:07:05Z minchau $ 020 */ 021 package org.apache.xml.dtm.ref; 022 023 /** 024 * The class ExtendedType represents an extended type object used by 025 * ExpandedNameTable. 026 */ 027 public final class ExtendedType 028 { 029 private int nodetype; 030 private String namespace; 031 private String localName; 032 private int hash; 033 034 /** 035 * Create an ExtendedType object from node type, namespace and local name. 036 * The hash code is calculated from the node type, namespace and local name. 037 * 038 * @param nodetype Type of the node 039 * @param namespace Namespace of the node 040 * @param localName Local name of the node 041 */ 042 public ExtendedType (int nodetype, String namespace, String localName) 043 { 044 this.nodetype = nodetype; 045 this.namespace = namespace; 046 this.localName = localName; 047 this.hash = nodetype + namespace.hashCode() + localName.hashCode(); 048 } 049 050 /** 051 * Create an ExtendedType object from node type, namespace, local name 052 * and a given hash code. 053 * 054 * @param nodetype Type of the node 055 * @param namespace Namespace of the node 056 * @param localName Local name of the node 057 * @param hash The given hash code 058 */ 059 public ExtendedType (int nodetype, String namespace, String localName, int hash) 060 { 061 this.nodetype = nodetype; 062 this.namespace = namespace; 063 this.localName = localName; 064 this.hash = hash; 065 } 066 067 /** 068 * Redefine this ExtendedType object to represent a different extended type. 069 * This is intended to be used ONLY on the hashET object. Using it elsewhere 070 * will mess up existing hashtable entries! 071 */ 072 protected void redefine(int nodetype, String namespace, String localName) 073 { 074 this.nodetype = nodetype; 075 this.namespace = namespace; 076 this.localName = localName; 077 this.hash = nodetype + namespace.hashCode() + localName.hashCode(); 078 } 079 080 /** 081 * Redefine this ExtendedType object to represent a different extended type. 082 * This is intended to be used ONLY on the hashET object. Using it elsewhere 083 * will mess up existing hashtable entries! 084 */ 085 protected void redefine(int nodetype, String namespace, String localName, int hash) 086 { 087 this.nodetype = nodetype; 088 this.namespace = namespace; 089 this.localName = localName; 090 this.hash = hash; 091 } 092 093 /** 094 * Override the hashCode() method in the Object class 095 */ 096 public int hashCode() 097 { 098 return hash; 099 } 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 }