aoqi@0: /* aoqi@0: * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.fastinfoset; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: aoqi@0: public class QualifiedName { aoqi@0: public String prefix; aoqi@0: public String namespaceName; aoqi@0: public String localName; aoqi@0: public String qName; aoqi@0: public int index; aoqi@0: public int prefixIndex; aoqi@0: public int namespaceNameIndex; aoqi@0: public int localNameIndex; aoqi@0: public int attributeId; aoqi@0: public int attributeHash; aoqi@0: private QName qNameObject; aoqi@0: aoqi@0: public QualifiedName() { } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName, String qName) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = qName; aoqi@0: this.index = -1; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: } aoqi@0: aoqi@0: public void set(String prefix, String namespaceName, String localName, String qName) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = qName; aoqi@0: this.index = -1; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: this.qNameObject = null; aoqi@0: } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName, String qName, int index) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = qName; aoqi@0: this.index = index; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName, String localName, String qName, int index) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = qName; aoqi@0: this.index = index; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName, String qName, int index, aoqi@0: int prefixIndex, int namespaceNameIndex, int localNameIndex) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = qName; aoqi@0: this.index = index; aoqi@0: this.prefixIndex = prefixIndex + 1; aoqi@0: this.namespaceNameIndex = namespaceNameIndex + 1; aoqi@0: this.localNameIndex = localNameIndex; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName, String localName, String qName, int index, aoqi@0: int prefixIndex, int namespaceNameIndex, int localNameIndex) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = qName; aoqi@0: this.index = index; aoqi@0: this.prefixIndex = prefixIndex + 1; aoqi@0: this.namespaceNameIndex = namespaceNameIndex + 1; aoqi@0: this.localNameIndex = localNameIndex; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: this.index = -1; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName, String localName) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: this.index = -1; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName, aoqi@0: int prefixIndex, int namespaceNameIndex, int localNameIndex, aoqi@0: char[] charBuffer) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: aoqi@0: if (charBuffer != null) { aoqi@0: final int l1 = prefix.length(); aoqi@0: final int l2 = localName.length(); aoqi@0: final int total = l1 + l2 + 1; aoqi@0: if (total < charBuffer.length) { aoqi@0: prefix.getChars(0, l1, charBuffer, 0); aoqi@0: charBuffer[l1] = ':'; aoqi@0: localName.getChars(0, l2, charBuffer, l1 + 1); aoqi@0: this.qName = new String(charBuffer, 0, total); aoqi@0: } else { aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: } aoqi@0: } else { aoqi@0: this.qName = this.localName; aoqi@0: } aoqi@0: aoqi@0: this.prefixIndex = prefixIndex + 1; aoqi@0: this.namespaceNameIndex = namespaceNameIndex + 1; aoqi@0: this.localNameIndex = localNameIndex; aoqi@0: this.index = -1; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName, String localName, aoqi@0: int prefixIndex, int namespaceNameIndex, int localNameIndex, aoqi@0: char[] charBuffer) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: aoqi@0: if (charBuffer != null) { aoqi@0: final int l1 = prefix.length(); aoqi@0: final int l2 = localName.length(); aoqi@0: final int total = l1 + l2 + 1; aoqi@0: if (total < charBuffer.length) { aoqi@0: prefix.getChars(0, l1, charBuffer, 0); aoqi@0: charBuffer[l1] = ':'; aoqi@0: localName.getChars(0, l2, charBuffer, l1 + 1); aoqi@0: this.qName = new String(charBuffer, 0, total); aoqi@0: } else { aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: } aoqi@0: } else { aoqi@0: this.qName = this.localName; aoqi@0: } aoqi@0: aoqi@0: this.prefixIndex = prefixIndex + 1; aoqi@0: this.namespaceNameIndex = namespaceNameIndex + 1; aoqi@0: this.localNameIndex = localNameIndex; aoqi@0: this.index = -1; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName, int index) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: this.index = index; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName, String localName, int index) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: this.index = index; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public QualifiedName(String prefix, String namespaceName, String localName, int index, aoqi@0: int prefixIndex, int namespaceNameIndex, int localNameIndex) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: this.index = index; aoqi@0: this.prefixIndex = prefixIndex + 1; aoqi@0: this.namespaceNameIndex = namespaceNameIndex + 1; aoqi@0: this.localNameIndex = localNameIndex; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName, String localName, int index, aoqi@0: int prefixIndex, int namespaceNameIndex, int localNameIndex) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = localName; aoqi@0: this.qName = createQNameString(prefix, localName); aoqi@0: this.index = index; aoqi@0: this.prefixIndex = prefixIndex + 1; aoqi@0: this.namespaceNameIndex = namespaceNameIndex + 1; aoqi@0: this.localNameIndex = localNameIndex; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: // Qualified Name as a Namespace Name aoqi@0: public QualifiedName(String prefix, String namespaceName) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = ""; aoqi@0: this.qName = ""; aoqi@0: this.index = -1; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: } aoqi@0: aoqi@0: public final QualifiedName set(String prefix, String namespaceName) { aoqi@0: this.prefix = prefix; aoqi@0: this.namespaceName = namespaceName; aoqi@0: this.localName = ""; aoqi@0: this.qName = ""; aoqi@0: this.index = -1; aoqi@0: this.prefixIndex = 0; aoqi@0: this.namespaceNameIndex = 0; aoqi@0: this.localNameIndex = -1; aoqi@0: this.qNameObject = null; aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public final QName getQName() { aoqi@0: if (qNameObject == null) { aoqi@0: qNameObject = new QName(namespaceName, localName, prefix); aoqi@0: } aoqi@0: aoqi@0: return qNameObject; aoqi@0: } aoqi@0: aoqi@0: public final String getQNameString() { aoqi@0: if (this.qName != "") { aoqi@0: return this.qName; aoqi@0: } aoqi@0: aoqi@0: return this.qName = createQNameString(prefix, localName); aoqi@0: } aoqi@0: aoqi@0: public final void createAttributeValues(int size) { aoqi@0: attributeId = localNameIndex | (namespaceNameIndex << 20); aoqi@0: attributeHash = localNameIndex % size; aoqi@0: } aoqi@0: aoqi@0: private final String createQNameString(String p, String l) { aoqi@0: if (p != null && p.length() > 0) { aoqi@0: final StringBuffer b = new StringBuffer(p); aoqi@0: b.append(':'); aoqi@0: b.append(l); aoqi@0: return b.toString(); aoqi@0: } else { aoqi@0: return l; aoqi@0: } aoqi@0: } aoqi@0: }