KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > QualifiedName


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39
40 package com.sun.xml.fastinfoset;
41
42 import javax.xml.namespace.QName JavaDoc;
43
44 public class QualifiedName {
45     public final String JavaDoc prefix;
46     public final String JavaDoc namespaceName;
47     public final String JavaDoc localName;
48     public String JavaDoc qName;
49     public final int index;
50     public final int prefixIndex;
51     public final int namespaceNameIndex;
52     public final int localNameIndex;
53     public int attributeId;
54     public int attributeHash;
55     private QName JavaDoc qNameObject;
56     
57     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName, String JavaDoc qName) {
58         this.prefix = prefix;
59         this.namespaceName = namespaceName;
60         this.localName = localName;
61         this.qName = qName;
62         this.index = -1;
63         this.prefixIndex = 0;
64         this.namespaceNameIndex = 0;
65         this.localNameIndex = -1;
66     }
67
68     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName, String JavaDoc qName, int index) {
69         this.prefix = prefix;
70         this.namespaceName = namespaceName;
71         this.localName = localName;
72         this.qName = qName;
73         this.index = index;
74         this.prefixIndex = 0;
75         this.namespaceNameIndex = 0;
76         this.localNameIndex = -1;
77     }
78     
79     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName, String JavaDoc qName, int index,
80             int prefixIndex, int namespaceNameIndex, int localNameIndex) {
81         this.prefix = prefix;
82         this.namespaceName = namespaceName;
83         this.localName = localName;
84         this.qName = qName;
85         this.index = index;
86         this.prefixIndex = prefixIndex + 1;
87         this.namespaceNameIndex = namespaceNameIndex + 1;
88         this.localNameIndex = localNameIndex;
89     }
90     
91     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName) {
92         this.prefix = prefix;
93         this.namespaceName = namespaceName;
94         this.localName = localName;
95         this.qName = createQNameString(prefix, localName);
96         this.index = -1;
97         this.prefixIndex = 0;
98         this.namespaceNameIndex = 0;
99         this.localNameIndex = -1;
100     }
101
102     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName,
103             int prefixIndex, int namespaceNameIndex, int localNameIndex,
104             char[] charBuffer) {
105         this.prefix = prefix;
106         this.namespaceName = namespaceName;
107         this.localName = localName;
108
109         if (charBuffer != null) {
110             final int l1 = prefix.length();
111             final int l2 = localName.length();
112             final int total = l1 + l2 + 1;
113             if (total < charBuffer.length) {
114                 prefix.getChars(0, l1, charBuffer, 0);
115                 charBuffer[l1] = ':';
116                 localName.getChars(0, l2, charBuffer, l1 + 1);
117                 this.qName = new String JavaDoc(charBuffer, 0, total);
118             } else {
119                 this.qName = createQNameString(prefix, localName);
120             }
121         } else {
122             this.qName = this.localName;
123         }
124
125         this.prefixIndex = prefixIndex + 1;
126         this.namespaceNameIndex = namespaceNameIndex + 1;
127         this.localNameIndex = localNameIndex;
128         this.index = -1;
129     }
130     
131     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName, int index) {
132         this.prefix = prefix;
133         this.namespaceName = namespaceName;
134         this.localName = localName;
135         this.qName = createQNameString(prefix, localName);
136         this.index = index;
137         this.prefixIndex = 0;
138         this.namespaceNameIndex = 0;
139         this.localNameIndex = -1;
140     }
141     
142     public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName, String JavaDoc localName, int index,
143             int prefixIndex, int namespaceNameIndex, int localNameIndex) {
144         this.prefix = prefix;
145         this.namespaceName = namespaceName;
146         this.localName = localName;
147         this.qName = createQNameString(prefix, localName);
148         this.index = index;
149         this.prefixIndex = prefixIndex + 1;
150         this.namespaceNameIndex = namespaceNameIndex + 1;
151         this.localNameIndex = localNameIndex;
152     }
153     
154     // Qualified Name as a Namespace Name
155
public QualifiedName(String JavaDoc prefix, String JavaDoc namespaceName) {
156         this.prefix = prefix;
157         this.namespaceName = namespaceName;
158         this.localName = "";
159         this.qName = "";
160         this.index = -1;
161         this.prefixIndex = 0;
162         this.namespaceNameIndex = 0;
163         this.localNameIndex = -1;
164     }
165     
166     public final QName JavaDoc getQName() {
167         if (qNameObject == null) {
168             qNameObject = new QName JavaDoc(namespaceName, localName, prefix);
169         }
170         
171         return qNameObject;
172     }
173     
174     public final String JavaDoc getQNameString() {
175         if (this.qName != "") {
176             return this.qName;
177         }
178         
179         return this.qName = createQNameString(prefix, localName);
180     }
181     
182     public final void createAttributeValues(int size) {
183         attributeId = localNameIndex | (namespaceNameIndex << 20);
184         attributeHash = localNameIndex % size;
185     }
186     
187     private final String JavaDoc createQNameString(String JavaDoc p, String JavaDoc l) {
188         if (p != null && p != "") {
189             final StringBuffer JavaDoc b = new StringBuffer JavaDoc(p);
190             b.append(':');
191             b.append(l);
192             return b.toString();
193         } else {
194             return l;
195         }
196     }
197 }
198
Popular Tags