001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.bind.v2.runtime;
027:
028: import javax.xml.namespace.QName;
029:
030: /**
031: * The internal representation of an XML name.
032: *
033: * <p>
034: * This class keeps indicies for URI and local name for enabling faster processing.
035: *
036: * <p>
037: * {@link Name}s are ordered lexicographically (nsUri first, local name next.)
038: * This is the same order required by canonical XML.
039: *
040: * @author Kohsuke Kawaguchi
041: */
042: public final class Name implements Comparable<Name> {
043: /**
044: * Namespace URI. interned.
045: */
046: public final String nsUri;
047:
048: /**
049: * Local name. interned.
050: */
051: public final String localName;
052:
053: /**
054: * Index -1 is reserved for representing the empty namespace URI of attributes.
055: */
056: public final short nsUriIndex;
057: public final short localNameIndex;
058:
059: /**
060: * Index of the Name for an EII or AII
061: */
062: public final short qNameIndex;
063:
064: /**
065: * Specifies if the Name is associated with an EII or AII
066: */
067: public final boolean isAttribute;
068:
069: Name(int qNameIndex, int nsUriIndex, String nsUri, int localIndex,
070: String localName, boolean isAttribute) {
071: this .qNameIndex = (short) qNameIndex;
072: this .nsUri = nsUri;
073: this .localName = localName;
074: this .nsUriIndex = (short) nsUriIndex;
075: this .localNameIndex = (short) localIndex;
076: this .isAttribute = isAttribute;
077: }
078:
079: public String toString() {
080: return '{' + nsUri + '}' + localName;
081: }
082:
083: /**
084: * Creates a {@link QName} from this.
085: */
086: public QName toQName() {
087: return new QName(nsUri, localName);
088: }
089:
090: public boolean equals(String nsUri, String localName) {
091: return localName.equals(this .localName)
092: && nsUri.equals(this .nsUri);
093: }
094:
095: public int compareTo(Name that) {
096: int r = this .nsUri.compareTo(that.nsUri);
097: if (r != 0)
098: return r;
099: return this.localName.compareTo(that.localName);
100: }
101: }
|