author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 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 |
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
|
26 |
*/ |
|
27 |
||
28 |
package com.sun.xml.internal.org.jvnet.fastinfoset.sax.helpers; |
|
29 |
||
30 |
import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
|
31 |
import com.sun.xml.internal.fastinfoset.EncodingConstants; |
|
32 |
import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory; |
|
33 |
import java.io.IOException; |
|
34 |
import java.util.Map; |
|
35 |
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm; |
|
36 |
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException; |
|
37 |
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes; |
|
38 |
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException; |
|
39 |
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes; |
|
40 |
import org.xml.sax.Attributes; |
|
41 |
||
42 |
/** |
|
43 |
* Default implementation of the {@link EncodingAlgorithmAttributes} interface. |
|
44 |
* |
|
45 |
* <p>This class provides a default implementation of the SAX2 |
|
46 |
* {@link EncodingAlgorithmAttributes} interface, with the |
|
47 |
* addition of manipulators so that the list can be modified or |
|
48 |
* reused.</p> |
|
49 |
* |
|
50 |
* <p>There are two typical uses of this class:</p> |
|
51 |
* |
|
52 |
* <ol> |
|
53 |
* <li>to take a persistent snapshot of an EncodingAlgorithmAttributes object |
|
54 |
* in a {@link org.xml.sax.ContentHandler#startElement startElement} event; or</li> |
|
55 |
* <li>to construct or modify an EncodingAlgorithmAttributes object in a SAX2 |
|
56 |
* driver or filter.</li> |
|
57 |
* </ol> |
|
58 |
*/ |
|
59 |
public class EncodingAlgorithmAttributesImpl implements EncodingAlgorithmAttributes { |
|
60 |
private static final int DEFAULT_CAPACITY = 8; |
|
61 |
||
62 |
private static final int URI_OFFSET = 0; |
|
63 |
private static final int LOCALNAME_OFFSET = 1; |
|
64 |
private static final int QNAME_OFFSET = 2; |
|
65 |
private static final int TYPE_OFFSET = 3; |
|
66 |
private static final int VALUE_OFFSET = 4; |
|
67 |
private static final int ALGORITHMURI_OFFSET = 5; |
|
68 |
||
69 |
private static final int SIZE = 6; |
|
70 |
||
71 |
private Map _registeredEncodingAlgorithms; |
|
72 |
||
73 |
private int _length; |
|
74 |
||
75 |
private String[] _data; |
|
76 |
||
77 |
private int[] _algorithmIds; |
|
78 |
||
79 |
private Object[] _algorithmData; |
|
80 |
||
81 |
private String[] _alphabets; |
|
82 |
||
83 |
private boolean[] _toIndex; |
|
84 |
||
85 |
/** |
|
86 |
* Construct a new, empty EncodingAlgorithmAttributesImpl object. |
|
87 |
*/ |
|
88 |
public EncodingAlgorithmAttributesImpl() { |
|
89 |
this(null, null); |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Copy an existing Attributes object. |
|
94 |
* |
|
95 |
* <p>This constructor is especially useful inside a |
|
96 |
* {@link org.xml.sax.ContentHandler#startElement startElement} event.</p> |
|
97 |
* |
|
98 |
* @param attributes The existing Attributes object. |
|
99 |
*/ |
|
100 |
public EncodingAlgorithmAttributesImpl(Attributes attributes) { |
|
101 |
this(null, attributes); |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Use registered encoding algorithms and copy an existing Attributes object. |
|
106 |
* |
|
107 |
* <p>This constructor is especially useful inside a |
|
108 |
* {@link org.xml.sax.ContentHandler#startElement startElement} event.</p> |
|
109 |
* |
|
110 |
* @param registeredEncodingAlgorithms |
|
111 |
* The registeredEncodingAlgorithms encoding algorithms. |
|
112 |
* @param attributes The existing Attributes object. |
|
113 |
*/ |
|
114 |
public EncodingAlgorithmAttributesImpl(Map registeredEncodingAlgorithms, |
|
115 |
Attributes attributes) { |
|
116 |
_data = new String[DEFAULT_CAPACITY * SIZE]; |
|
117 |
_algorithmIds = new int[DEFAULT_CAPACITY]; |
|
118 |
_algorithmData = new Object[DEFAULT_CAPACITY]; |
|
119 |
_alphabets = new String[DEFAULT_CAPACITY]; |
|
120 |
_toIndex = new boolean[DEFAULT_CAPACITY]; |
|
121 |
||
122 |
_registeredEncodingAlgorithms = registeredEncodingAlgorithms; |
|
123 |
||
124 |
if (attributes != null) { |
|
125 |
if (attributes instanceof EncodingAlgorithmAttributes) { |
|
126 |
setAttributes((EncodingAlgorithmAttributes)attributes); |
|
127 |
} else { |
|
128 |
setAttributes(attributes); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Clear the attribute list for reuse. |
|
135 |
* |
|
136 |
*/ |
|
137 |
public final void clear() { |
|
138 |
for (int i = 0; i < _length; i++) { |
|
139 |
_data[i * SIZE + VALUE_OFFSET] = null; |
|
140 |
_algorithmData[i] = null; |
|
141 |
} |
|
142 |
_length = 0; |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Add an attribute to the end of the list. |
|
147 |
* |
|
148 |
* <p>For the sake of speed, this method does no checking |
|
149 |
* to see if the attribute is already in the list: that is |
|
150 |
* the responsibility of the application.</p> |
|
151 |
* |
|
152 |
* @param URI The Namespace URI, or the empty string if |
|
153 |
* none is available or Namespace processing is not |
|
154 |
* being performed. |
|
155 |
* @param localName The local name, or the empty string if |
|
156 |
* Namespace processing is not being performed. |
|
157 |
* @param qName The qualified (prefixed) name, or the empty string |
|
158 |
* if qualified names are not available. |
|
159 |
* @param type The attribute type as a string. |
|
160 |
* @param value The attribute value. |
|
161 |
*/ |
|
162 |
public void addAttribute(String URI, String localName, String qName, |
|
163 |
String type, String value) { |
|
164 |
if (_length >= _algorithmData.length) { |
|
165 |
resize(); |
|
166 |
} |
|
167 |
||
168 |
int i = _length * SIZE; |
|
169 |
_data[i++] = replaceNull(URI); |
|
170 |
_data[i++] = replaceNull(localName); |
|
171 |
_data[i++] = replaceNull(qName); |
|
172 |
_data[i++] = replaceNull(type); |
|
173 |
_data[i++] = replaceNull(value); |
|
174 |
_toIndex[_length] = false; |
|
175 |
_alphabets[_length] = null; |
|
176 |
||
177 |
_length++; |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Add an attribute to the end of the list. |
|
182 |
* |
|
183 |
* <p>For the sake of speed, this method does no checking |
|
184 |
* to see if the attribute is already in the list: that is |
|
185 |
* the responsibility of the application.</p> |
|
186 |
* |
|
187 |
* @param URI The Namespace URI, or the empty string if |
|
188 |
* none is available or Namespace processing is not |
|
189 |
* being performed. |
|
190 |
* @param localName The local name, or the empty string if |
|
191 |
* Namespace processing is not being performed. |
|
192 |
* @param qName The qualified (prefixed) name, or the empty string |
|
193 |
* if qualified names are not available. |
|
194 |
* @param type The attribute type as a string. |
|
195 |
* @param value The attribute value. |
|
196 |
* @param index True if attribute should be indexed. |
|
197 |
* @param alphabet The alphabet associated with the attribute value, |
|
198 |
* may be null if there is no associated alphabet. |
|
199 |
*/ |
|
200 |
public void addAttribute(String URI, String localName, String qName, |
|
201 |
String type, String value, boolean index, String alphabet) { |
|
202 |
if (_length >= _algorithmData.length) { |
|
203 |
resize(); |
|
204 |
} |
|
205 |
||
206 |
int i = _length * SIZE; |
|
207 |
_data[i++] = replaceNull(URI); |
|
208 |
_data[i++] = replaceNull(localName); |
|
209 |
_data[i++] = replaceNull(qName); |
|
210 |
_data[i++] = replaceNull(type); |
|
211 |
_data[i++] = replaceNull(value); |
|
212 |
_toIndex[_length] = index; |
|
213 |
_alphabets[_length] = alphabet; |
|
214 |
||
215 |
_length++; |
|
216 |
} |
|
217 |
||
218 |
/** |
|
219 |
* Add an attribute with built in algorithm data to the end of the list. |
|
220 |
* |
|
221 |
* <p>For the sake of speed, this method does no checking |
|
222 |
* to see if the attribute is already in the list: that is |
|
223 |
* the responsibility of the application.</p> |
|
224 |
* |
|
225 |
* @param URI The Namespace URI, or the empty string if |
|
226 |
* none is available or Namespace processing is not |
|
227 |
* being performed. |
|
228 |
* @param localName The local name, or the empty string if |
|
229 |
* Namespace processing is not being performed. |
|
230 |
* @param qName The qualified (prefixed) name, or the empty string |
|
231 |
* if qualified names are not available. |
|
232 |
* @param builtInAlgorithmID The built in algorithm ID. |
|
233 |
* @param algorithmData The built in algorithm data. |
|
234 |
*/ |
|
235 |
public void addAttributeWithBuiltInAlgorithmData(String URI, String localName, String qName, |
|
236 |
int builtInAlgorithmID, Object algorithmData) { |
|
237 |
if (_length >= _algorithmData.length) { |
|
238 |
resize(); |
|
239 |
} |
|
240 |
||
241 |
int i = _length * SIZE; |
|
242 |
_data[i++] = replaceNull(URI); |
|
243 |
_data[i++] = replaceNull(localName); |
|
244 |
_data[i++] = replaceNull(qName); |
|
245 |
_data[i++] = "CDATA"; |
|
246 |
_data[i++] = ""; |
|
247 |
_data[i++] = null; |
|
248 |
_algorithmIds[_length] = builtInAlgorithmID; |
|
249 |
_algorithmData[_length] = algorithmData; |
|
250 |
_toIndex[_length] = false; |
|
251 |
_alphabets[_length] = null; |
|
252 |
||
253 |
_length++; |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Add an attribute with algorithm data to the end of the list. |
|
258 |
* |
|
259 |
* <p>For the sake of speed, this method does no checking |
|
260 |
* to see if the attribute is already in the list: that is |
|
261 |
* the responsibility of the application.</p> |
|
262 |
* |
|
263 |
* @param URI The Namespace URI, or the empty string if |
|
264 |
* none is available or Namespace processing is not |
|
265 |
* being performed. |
|
266 |
* @param localName The local name, or the empty string if |
|
267 |
* Namespace processing is not being performed. |
|
268 |
* @param qName The qualified (prefixed) name, or the empty string |
|
269 |
* if qualified names are not available. |
|
270 |
* @param algorithmURI The algorithm URI, or null if a built in algorithm |
|
271 |
* @param algorithmID The algorithm ID. |
|
272 |
* @param algorithmData The algorithm data. |
|
273 |
*/ |
|
274 |
public void addAttributeWithAlgorithmData(String URI, String localName, String qName, |
|
275 |
String algorithmURI, int algorithmID, Object algorithmData) { |
|
276 |
if (_length >= _algorithmData.length) { |
|
277 |
resize(); |
|
278 |
} |
|
279 |
||
280 |
int i = _length * SIZE; |
|
281 |
_data[i++] = replaceNull(URI); |
|
282 |
_data[i++] = replaceNull(localName); |
|
283 |
_data[i++] = replaceNull(qName); |
|
284 |
_data[i++] = "CDATA"; |
|
285 |
_data[i++] = ""; |
|
286 |
_data[i++] = algorithmURI; |
|
287 |
_algorithmIds[_length] = algorithmID; |
|
288 |
_algorithmData[_length] = algorithmData; |
|
289 |
_toIndex[_length] = false; |
|
290 |
_alphabets[_length] = null; |
|
291 |
||
292 |
_length++; |
|
293 |
} |
|
294 |
||
295 |
/** |
|
296 |
* Replace an attribute value with algorithm data. |
|
297 |
* |
|
298 |
* <p>For the sake of speed, this method does no checking |
|
299 |
* to see if the attribute is already in the list: that is |
|
300 |
* the responsibility of the application.</p> |
|
301 |
* |
|
302 |
* @param index The index of the attribute whose value is to be replaced |
|
303 |
* @param algorithmURI The algorithm URI, or null if a built in algorithm |
|
304 |
* @param algorithmID The algorithm ID. |
|
305 |
* @param algorithmData The algorithm data. |
|
306 |
*/ |
|
307 |
public void replaceWithAttributeAlgorithmData(int index, |
|
308 |
String algorithmURI, int algorithmID, Object algorithmData) { |
|
309 |
if (index < 0 || index >= _length) return; |
|
310 |
||
311 |
int i = index * SIZE; |
|
312 |
_data[i + VALUE_OFFSET] = null; |
|
313 |
_data[i + ALGORITHMURI_OFFSET] = algorithmURI; |
|
314 |
_algorithmIds[index] = algorithmID; |
|
315 |
_algorithmData[index] = algorithmData; |
|
316 |
_toIndex[index] = false; |
|
317 |
_alphabets[index] = null; |
|
318 |
} |
|
319 |
||
320 |
/** |
|
321 |
* Copy an entire Attributes object. |
|
322 |
* |
|
323 |
* @param atts The attributes to copy. |
|
324 |
*/ |
|
325 |
public void setAttributes(Attributes atts) { |
|
326 |
_length = atts.getLength(); |
|
327 |
if (_length > 0) { |
|
328 |
||
329 |
if (_length >= _algorithmData.length) { |
|
330 |
resizeNoCopy(); |
|
331 |
} |
|
332 |
||
333 |
int index = 0; |
|
334 |
for (int i = 0; i < _length; i++) { |
|
335 |
_data[index++] = atts.getURI(i); |
|
336 |
_data[index++] = atts.getLocalName(i); |
|
337 |
_data[index++] = atts.getQName(i); |
|
338 |
_data[index++] = atts.getType(i); |
|
339 |
_data[index++] = atts.getValue(i); |
|
340 |
index++; |
|
341 |
_toIndex[i] = false; |
|
342 |
_alphabets[i] = null; |
|
343 |
} |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
/** |
|
348 |
* Copy an entire EncodingAlgorithmAttributes object. |
|
349 |
* |
|
350 |
* @param atts The attributes to copy. |
|
351 |
*/ |
|
352 |
public void setAttributes(EncodingAlgorithmAttributes atts) { |
|
353 |
_length = atts.getLength(); |
|
354 |
if (_length > 0) { |
|
355 |
||
356 |
if (_length >= _algorithmData.length) { |
|
357 |
resizeNoCopy(); |
|
358 |
} |
|
359 |
||
360 |
int index = 0; |
|
361 |
for (int i = 0; i < _length; i++) { |
|
362 |
_data[index++] = atts.getURI(i); |
|
363 |
_data[index++] = atts.getLocalName(i); |
|
364 |
_data[index++] = atts.getQName(i); |
|
365 |
_data[index++] = atts.getType(i); |
|
366 |
_data[index++] = atts.getValue(i); |
|
367 |
_data[index++] = atts.getAlgorithmURI(i); |
|
368 |
_algorithmIds[i] = atts.getAlgorithmIndex(i); |
|
369 |
_algorithmData[i] = atts.getAlgorithmData(i); |
|
370 |
_toIndex[i] = false; |
|
371 |
_alphabets[i] = null; |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
// org.xml.sax.Attributes |
|
377 |
||
378 |
public final int getLength() { |
|
379 |
return _length; |
|
380 |
} |
|
381 |
||
382 |
public final String getLocalName(int index) { |
|
383 |
if (index >= 0 && index < _length) { |
|
384 |
return _data[index * SIZE + LOCALNAME_OFFSET]; |
|
385 |
} else { |
|
386 |
return null; |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
public final String getQName(int index) { |
|
391 |
if (index >= 0 && index < _length) { |
|
392 |
return _data[index * SIZE + QNAME_OFFSET]; |
|
393 |
} else { |
|
394 |
return null; |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
public final String getType(int index) { |
|
399 |
if (index >= 0 && index < _length) { |
|
400 |
return _data[index * SIZE + TYPE_OFFSET]; |
|
401 |
} else { |
|
402 |
return null; |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
public final String getURI(int index) { |
|
407 |
if (index >= 0 && index < _length) { |
|
408 |
return _data[index * SIZE + URI_OFFSET]; |
|
409 |
} else { |
|
410 |
return null; |
|
411 |
} |
|
412 |
} |
|
413 |
||
414 |
public final String getValue(int index) { |
|
415 |
if (index >= 0 && index < _length) { |
|
416 |
final String value = _data[index * SIZE + VALUE_OFFSET]; |
|
417 |
if (value != null) return value; |
|
418 |
} else { |
|
419 |
return null; |
|
420 |
} |
|
421 |
||
422 |
if (_algorithmData[index] == null || _registeredEncodingAlgorithms == null) { |
|
423 |
return null; |
|
424 |
} |
|
425 |
||
426 |
try { |
|
427 |
return _data[index * SIZE + VALUE_OFFSET] = convertEncodingAlgorithmDataToString( |
|
428 |
_algorithmIds[index], |
|
429 |
_data[index * SIZE + ALGORITHMURI_OFFSET], |
|
430 |
_algorithmData[index]).toString(); |
|
431 |
} catch (IOException e) { |
|
432 |
return null; |
|
433 |
} catch (FastInfosetException e) { |
|
434 |
return null; |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
public final int getIndex(String qName) { |
|
439 |
for (int index = 0; index < _length; index++) { |
|
440 |
if (qName.equals(_data[index * SIZE + QNAME_OFFSET])) { |
|
441 |
return index; |
|
442 |
} |
|
443 |
} |
|
444 |
return -1; |
|
445 |
} |
|
446 |
||
447 |
public final String getType(String qName) { |
|
448 |
int index = getIndex(qName); |
|
449 |
if (index >= 0) { |
|
450 |
return _data[index * SIZE + TYPE_OFFSET]; |
|
451 |
} else { |
|
452 |
return null; |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
public final String getValue(String qName) { |
|
457 |
int index = getIndex(qName); |
|
458 |
if (index >= 0) { |
|
459 |
return getValue(index); |
|
460 |
} else { |
|
461 |
return null; |
|
462 |
} |
|
463 |
} |
|
464 |
||
465 |
public final int getIndex(String uri, String localName) { |
|
466 |
for (int index = 0; index < _length; index++) { |
|
467 |
if (localName.equals(_data[index * SIZE + LOCALNAME_OFFSET]) && |
|
468 |
uri.equals(_data[index * SIZE + URI_OFFSET])) { |
|
469 |
return index; |
|
470 |
} |
|
471 |
} |
|
472 |
return -1; |
|
473 |
} |
|
474 |
||
475 |
public final String getType(String uri, String localName) { |
|
476 |
int index = getIndex(uri, localName); |
|
477 |
if (index >= 0) { |
|
478 |
return _data[index * SIZE + TYPE_OFFSET]; |
|
479 |
} else { |
|
480 |
return null; |
|
481 |
} |
|
482 |
} |
|
483 |
||
484 |
public final String getValue(String uri, String localName) { |
|
485 |
int index = getIndex(uri, localName); |
|
486 |
if (index >= 0) { |
|
487 |
return getValue(index); |
|
488 |
} else { |
|
489 |
return null; |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
// EncodingAlgorithmAttributes |
|
494 |
||
495 |
public final String getAlgorithmURI(int index) { |
|
496 |
if (index >= 0 && index < _length) { |
|
497 |
return _data[index * SIZE + ALGORITHMURI_OFFSET]; |
|
498 |
} else { |
|
499 |
return null; |
|
500 |
} |
|
501 |
} |
|
502 |
||
503 |
public final int getAlgorithmIndex(int index) { |
|
504 |
if (index >= 0 && index < _length) { |
|
505 |
return _algorithmIds[index]; |
|
506 |
} else { |
|
507 |
return -1; |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
public final Object getAlgorithmData(int index) { |
|
512 |
if (index >= 0 && index < _length) { |
|
513 |
return _algorithmData[index]; |
|
514 |
} else { |
|
515 |
return null; |
|
516 |
} |
|
517 |
} |
|
518 |
||
519 |
// ExtendedAttributes |
|
520 |
||
521 |
public final String getAlpababet(int index) { |
|
522 |
if (index >= 0 && index < _length) { |
|
523 |
return _alphabets[index]; |
|
524 |
} else { |
|
525 |
return null; |
|
526 |
} |
|
527 |
} |
|
528 |
||
529 |
public final boolean getToIndex(int index) { |
|
530 |
if (index >= 0 && index < _length) { |
|
531 |
return _toIndex[index]; |
|
532 |
} else { |
|
533 |
return false; |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
// ----- |
|
538 |
||
539 |
private final String replaceNull(String s) { |
|
540 |
return (s != null) ? s : ""; |
|
541 |
} |
|
542 |
||
543 |
private final void resizeNoCopy() { |
|
544 |
final int newLength = _length * 3 / 2 + 1; |
|
545 |
||
546 |
_data = new String[newLength * SIZE]; |
|
547 |
_algorithmIds = new int[newLength]; |
|
548 |
_algorithmData = new Object[newLength]; |
|
549 |
} |
|
550 |
||
551 |
private final void resize() { |
|
552 |
final int newLength = _length * 3 / 2 + 1; |
|
553 |
||
554 |
String[] data = new String[newLength * SIZE]; |
|
555 |
int[] algorithmIds = new int[newLength]; |
|
556 |
Object[] algorithmData = new Object[newLength]; |
|
557 |
String[] alphabets = new String[newLength]; |
|
558 |
boolean[] toIndex = new boolean[newLength]; |
|
559 |
||
560 |
System.arraycopy(_data, 0, data, 0, _length * SIZE); |
|
561 |
System.arraycopy(_algorithmIds, 0, algorithmIds, 0, _length); |
|
562 |
System.arraycopy(_algorithmData, 0, algorithmData, 0, _length); |
|
563 |
System.arraycopy(_alphabets, 0, alphabets, 0, _length); |
|
564 |
System.arraycopy(_toIndex, 0, toIndex, 0, _length); |
|
565 |
||
566 |
_data = data; |
|
567 |
_algorithmIds = algorithmIds; |
|
568 |
_algorithmData = algorithmData; |
|
569 |
_alphabets = alphabets; |
|
570 |
_toIndex = toIndex; |
|
571 |
} |
|
572 |
||
573 |
private final StringBuffer convertEncodingAlgorithmDataToString( |
|
574 |
int identifier, String URI, Object data) throws FastInfosetException, IOException { |
|
575 |
EncodingAlgorithm ea = null; |
|
576 |
if (identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { |
|
577 |
ea = BuiltInEncodingAlgorithmFactory.getAlgorithm(identifier); |
|
578 |
} else if (identifier == EncodingAlgorithmIndexes.CDATA) { |
|
579 |
throw new EncodingAlgorithmException( |
|
580 |
CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported")); |
|
581 |
} else if (identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { |
|
582 |
if (URI == null) { |
|
583 |
throw new EncodingAlgorithmException( |
|
584 |
CommonResourceBundle.getInstance().getString("message.URINotPresent") + identifier); |
|
585 |
} |
|
586 |
||
587 |
ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI); |
|
588 |
if (ea == null) { |
|
589 |
throw new EncodingAlgorithmException( |
|
590 |
CommonResourceBundle.getInstance().getString("message.algorithmNotRegistered") + URI); |
|
591 |
} |
|
592 |
} else { |
|
593 |
// Reserved built-in algorithms for future use |
|
594 |
// TODO should use sax property to decide if event will be |
|
595 |
// reported, allows for support through handler if required. |
|
596 |
throw new EncodingAlgorithmException( |
|
597 |
CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); |
|
598 |
} |
|
599 |
||
600 |
final StringBuffer sb = new StringBuffer(); |
|
601 |
ea.convertToCharacters(data, sb); |
|
602 |
return sb; |
|
603 |
} |
|
604 |
} |