1/* 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.xml.internal.bind.v2.runtime; 27 28import javax.xml.namespace.QName; 29 30/** 31 * The internal representation of an XML name. 32 * 33 * <p> 34 * This class keeps indicies for URI and local name for enabling faster processing. 35 * 36 * <p> 37 * {@link Name}s are ordered lexicographically (nsUri first, local name next.) 38 * This is the same order required by canonical XML. 39 * 40 * @author Kohsuke Kawaguchi 41 */ 42public final class Name implements Comparable<Name> { 43 /** 44 * Namespace URI. interned. 45 */ 46 public final String nsUri; 47 48 /** 49 * Local name. interned. 50 */ 51 public final String localName; 52 53 /** 54 * Index -1 is reserved for representing the empty namespace URI of attributes. 55 */ 56 public final short nsUriIndex; 57 public final short localNameIndex; 58 59 /** 60 * Index of the Name for an EII or AII 61 */ 62 public final short qNameIndex; 63 64 /** 65 * Specifies if the Name is associated with an EII or AII 66 */ 67 public final boolean isAttribute; 68 69 Name(int qNameIndex, int nsUriIndex, String nsUri, int localIndex, String localName, boolean isAttribute) { 70 this.qNameIndex = (short)qNameIndex; 71 this.nsUri = nsUri; 72 this.localName = localName; 73 this.nsUriIndex = (short)nsUriIndex; 74 this.localNameIndex = (short)localIndex; 75 this.isAttribute = isAttribute; 76 } 77 78 public String toString() { 79 return '{'+nsUri+'}'+localName; 80 } 81 82 /** 83 * Creates a {@link QName} from this. 84 */ 85 public QName toQName() { 86 return new QName(nsUri,localName); 87 } 88 89 public boolean equals( String nsUri, String localName ) { 90 return localName.equals(this.localName) && nsUri.equals(this.nsUri); 91 } 92 93 public int compareTo(Name that) { 94 int r = this.nsUri.compareTo(that.nsUri); 95 if(r!=0) return r; 96 return this.localName.compareTo(that.localName); 97 } 98} 99