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: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
026: */
027:
028: /*
029: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
030: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
031: *
032: * This code is free software; you can redistribute it and/or modify it
033: * under the terms of the GNU General Public License version 2 only, as
034: * published by the Free Software Foundation. Sun designates this
035: * particular file as subject to the "Classpath" exception as provided
036: * by Sun in the LICENSE file that accompanied this code.
037: *
038: * This code is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
040: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
041: * version 2 for more details (a copy is included in the LICENSE file that
042: * accompanied this code).
043: *
044: * You should have received a copy of the GNU General Public License version
045: * 2 along with this work; if not, write to the Free Software Foundation,
046: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
047: *
048: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
049: * CA 95054 USA or visit www.sun.com if you need additional information or
050: * have any questions.
051: *
052: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
053: *
054: */
055:
056: package com.sun.xml.internal.fastinfoset;
057:
058: import javax.xml.namespace.QName;
059:
060: public class QualifiedName {
061: public final String prefix;
062: public final String namespaceName;
063: public final String localName;
064: public String qName;
065: public final int index;
066: public final int prefixIndex;
067: public final int namespaceNameIndex;
068: public final int localNameIndex;
069: public int attributeId;
070: public int attributeHash;
071: private QName qNameObject;
072:
073: public QualifiedName(String prefix, String namespaceName,
074: String localName, String qName) {
075: this .prefix = prefix;
076: this .namespaceName = namespaceName;
077: this .localName = localName;
078: this .qName = qName;
079: this .index = -1;
080: this .prefixIndex = 0;
081: this .namespaceNameIndex = 0;
082: this .localNameIndex = -1;
083: }
084:
085: public QualifiedName(String prefix, String namespaceName,
086: String localName, String qName, int index) {
087: this .prefix = prefix;
088: this .namespaceName = namespaceName;
089: this .localName = localName;
090: this .qName = qName;
091: this .index = index;
092: this .prefixIndex = 0;
093: this .namespaceNameIndex = 0;
094: this .localNameIndex = -1;
095: }
096:
097: public QualifiedName(String prefix, String namespaceName,
098: String localName, String qName, int index, int prefixIndex,
099: int namespaceNameIndex, int localNameIndex) {
100: this .prefix = prefix;
101: this .namespaceName = namespaceName;
102: this .localName = localName;
103: this .qName = qName;
104: this .index = index;
105: this .prefixIndex = prefixIndex + 1;
106: this .namespaceNameIndex = namespaceNameIndex + 1;
107: this .localNameIndex = localNameIndex;
108: }
109:
110: public QualifiedName(String prefix, String namespaceName,
111: String localName) {
112: this .prefix = prefix;
113: this .namespaceName = namespaceName;
114: this .localName = localName;
115: this .qName = createQNameString(prefix, localName);
116: this .index = -1;
117: this .prefixIndex = 0;
118: this .namespaceNameIndex = 0;
119: this .localNameIndex = -1;
120: }
121:
122: public QualifiedName(String prefix, String namespaceName,
123: String localName, int prefixIndex, int namespaceNameIndex,
124: int localNameIndex, char[] charBuffer) {
125: this .prefix = prefix;
126: this .namespaceName = namespaceName;
127: this .localName = localName;
128:
129: if (charBuffer != null) {
130: final int l1 = prefix.length();
131: final int l2 = localName.length();
132: final int total = l1 + l2 + 1;
133: if (total < charBuffer.length) {
134: prefix.getChars(0, l1, charBuffer, 0);
135: charBuffer[l1] = ':';
136: localName.getChars(0, l2, charBuffer, l1 + 1);
137: this .qName = new String(charBuffer, 0, total);
138: } else {
139: this .qName = createQNameString(prefix, localName);
140: }
141: } else {
142: this .qName = this .localName;
143: }
144:
145: this .prefixIndex = prefixIndex + 1;
146: this .namespaceNameIndex = namespaceNameIndex + 1;
147: this .localNameIndex = localNameIndex;
148: this .index = -1;
149: }
150:
151: public QualifiedName(String prefix, String namespaceName,
152: String localName, int index) {
153: this .prefix = prefix;
154: this .namespaceName = namespaceName;
155: this .localName = localName;
156: this .qName = createQNameString(prefix, localName);
157: this .index = index;
158: this .prefixIndex = 0;
159: this .namespaceNameIndex = 0;
160: this .localNameIndex = -1;
161: }
162:
163: public QualifiedName(String prefix, String namespaceName,
164: String localName, int index, int prefixIndex,
165: int namespaceNameIndex, int localNameIndex) {
166: this .prefix = prefix;
167: this .namespaceName = namespaceName;
168: this .localName = localName;
169: this .qName = createQNameString(prefix, localName);
170: this .index = index;
171: this .prefixIndex = prefixIndex + 1;
172: this .namespaceNameIndex = namespaceNameIndex + 1;
173: this .localNameIndex = localNameIndex;
174: }
175:
176: // Qualified Name as a Namespace Name
177: public QualifiedName(String prefix, String namespaceName) {
178: this .prefix = prefix;
179: this .namespaceName = namespaceName;
180: this .localName = "";
181: this .qName = "";
182: this .index = -1;
183: this .prefixIndex = 0;
184: this .namespaceNameIndex = 0;
185: this .localNameIndex = -1;
186: }
187:
188: public final QName getQName() {
189: if (qNameObject == null) {
190: qNameObject = new QName(namespaceName, localName, prefix);
191: }
192:
193: return qNameObject;
194: }
195:
196: public final String getQNameString() {
197: if (this .qName != "") {
198: return this .qName;
199: }
200:
201: return this .qName = createQNameString(prefix, localName);
202: }
203:
204: public final void createAttributeValues(int size) {
205: attributeId = localNameIndex | (namespaceNameIndex << 20);
206: attributeHash = localNameIndex % size;
207: }
208:
209: private final String createQNameString(String p, String l) {
210: if (p != null && p != "") {
211: final StringBuffer b = new StringBuffer(p);
212: b.append(':');
213: b.append(l);
214: return b.toString();
215: } else {
216: return l;
217: }
218: }
219: }
|