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 com.sun.org.apache.xml.internal.dtm.ref;
  20. /**
  21. * The class ExtendedType represents an extended type object used by
  22. * ExpandedNameTable.
  23. */
  24. public final class ExtendedType
  25. {
  26. private int nodetype;
  27. private String namespace;
  28. private String localName;
  29. private int hash;
  30. /**
  31. * Create an ExtendedType object from node type, namespace and local name.
  32. * The hash code is calculated from the node type, namespace and local name.
  33. *
  34. * @param nodetype Type of the node
  35. * @param namespace Namespace of the node
  36. * @param localName Local name of the node
  37. */
  38. public ExtendedType (int nodetype, String namespace, String localName)
  39. {
  40. this.nodetype = nodetype;
  41. this.namespace = namespace;
  42. this.localName = localName;
  43. this.hash = nodetype + namespace.hashCode() + localName.hashCode();
  44. }
  45. /**
  46. * Create an ExtendedType object from node type, namespace, local name
  47. * and a given hash code.
  48. *
  49. * @param nodetype Type of the node
  50. * @param namespace Namespace of the node
  51. * @param localName Local name of the node
  52. * @param hash The given hash code
  53. */
  54. public ExtendedType (int nodetype, String namespace, String localName, int hash)
  55. {
  56. this.nodetype = nodetype;
  57. this.namespace = namespace;
  58. this.localName = localName;
  59. this.hash = hash;
  60. }
  61. /**
  62. * Redefine this ExtendedType object to represent a different extended type.
  63. * This is intended to be used ONLY on the hashET object. Using it elsewhere
  64. * will mess up existing hashtable entries!
  65. */
  66. protected void redefine(int nodetype, String namespace, String localName)
  67. {
  68. this.nodetype = nodetype;
  69. this.namespace = namespace;
  70. this.localName = localName;
  71. this.hash = nodetype + namespace.hashCode() + localName.hashCode();
  72. }
  73. /**
  74. * Redefine this ExtendedType object to represent a different extended type.
  75. * This is intended to be used ONLY on the hashET object. Using it elsewhere
  76. * will mess up existing hashtable entries!
  77. */
  78. protected void redefine(int nodetype, String namespace, String localName, int hash)
  79. {
  80. this.nodetype = nodetype;
  81. this.namespace = namespace;
  82. this.localName = localName;
  83. this.hash = hash;
  84. }
  85. /**
  86. * Override the hashCode() method in the Object class
  87. */
  88. public int hashCode()
  89. {
  90. return hash;
  91. }
  92. /**
  93. * Test if this ExtendedType object is equal to the given ExtendedType.
  94. *
  95. * @param other The other ExtendedType object to test for equality
  96. * @return true if the two ExtendedType objects are equal.
  97. */
  98. public boolean equals(ExtendedType other)
  99. {
  100. try
  101. {
  102. return other.nodetype == this.nodetype &&
  103. other.localName.equals(this.localName) &&
  104. other.namespace.equals(this.namespace);
  105. }
  106. catch(NullPointerException e)
  107. {
  108. return false;
  109. }
  110. }
  111. /**
  112. * Return the node type
  113. */
  114. public int getNodeType()
  115. {
  116. return nodetype;
  117. }
  118. /**
  119. * Return the local name
  120. */
  121. public String getLocalName()
  122. {
  123. return localName;
  124. }
  125. /**
  126. * Return the namespace
  127. */
  128. public String getNamespace()
  129. {
  130. return namespace;
  131. }
  132. }