001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: ExtendedType.java,v 1.3 2004/02/16 23:06:11 minchau Exp $
018: */
019: package org.apache.xml.dtm.ref;
020:
021: /**
022: * The class ExtendedType represents an extended type object used by
023: * ExpandedNameTable.
024: */
025: public final class ExtendedType {
026: private int nodetype;
027: private String namespace;
028: private String localName;
029: private int hash;
030:
031: /**
032: * Create an ExtendedType object from node type, namespace and local name.
033: * The hash code is calculated from the node type, namespace and local name.
034: *
035: * @param nodetype Type of the node
036: * @param namespace Namespace of the node
037: * @param localName Local name of the node
038: */
039: public ExtendedType(int nodetype, String namespace, String localName) {
040: this .nodetype = nodetype;
041: this .namespace = namespace;
042: this .localName = localName;
043: this .hash = nodetype + namespace.hashCode()
044: + localName.hashCode();
045: }
046:
047: /**
048: * Create an ExtendedType object from node type, namespace, local name
049: * and a given hash code.
050: *
051: * @param nodetype Type of the node
052: * @param namespace Namespace of the node
053: * @param localName Local name of the node
054: * @param hash The given hash code
055: */
056: public ExtendedType(int nodetype, String namespace,
057: String localName, int hash) {
058: this .nodetype = nodetype;
059: this .namespace = namespace;
060: this .localName = localName;
061: this .hash = hash;
062: }
063:
064: /**
065: * Redefine this ExtendedType object to represent a different extended type.
066: * This is intended to be used ONLY on the hashET object. Using it elsewhere
067: * will mess up existing hashtable entries!
068: */
069: protected void redefine(int nodetype, String namespace,
070: String localName) {
071: this .nodetype = nodetype;
072: this .namespace = namespace;
073: this .localName = localName;
074: this .hash = nodetype + namespace.hashCode()
075: + localName.hashCode();
076: }
077:
078: /**
079: * Redefine this ExtendedType object to represent a different extended type.
080: * This is intended to be used ONLY on the hashET object. Using it elsewhere
081: * will mess up existing hashtable entries!
082: */
083: protected void redefine(int nodetype, String namespace,
084: String localName, int hash) {
085: this .nodetype = nodetype;
086: this .namespace = namespace;
087: this .localName = localName;
088: this .hash = hash;
089: }
090:
091: /**
092: * Override the hashCode() method in the Object class
093: */
094: public int hashCode() {
095: return hash;
096: }
097:
098: /**
099: * Test if this ExtendedType object is equal to the given ExtendedType.
100: *
101: * @param other The other ExtendedType object to test for equality
102: * @return true if the two ExtendedType objects are equal.
103: */
104: public boolean equals(ExtendedType other) {
105: try {
106: return other.nodetype == this .nodetype
107: && other.localName.equals(this .localName)
108: && other.namespace.equals(this .namespace);
109: } catch (NullPointerException e) {
110: return false;
111: }
112: }
113:
114: /**
115: * Return the node type
116: */
117: public int getNodeType() {
118: return nodetype;
119: }
120:
121: /**
122: * Return the local name
123: */
124: public String getLocalName() {
125: return localName;
126: }
127:
128: /**
129: * Return the namespace
130: */
131: public String getNamespace() {
132: return namespace;
133: }
134:
135: }
|