Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.stream.buffer; |
ohair@286 | 27 | |
ohair@286 | 28 | /** |
ohair@286 | 29 | * Base class for classes that creates {@link MutableXMLStreamBuffer} |
ohair@286 | 30 | * and from infoset in API-specific form. |
ohair@286 | 31 | */ |
ohair@286 | 32 | public class AbstractCreator extends AbstractCreatorProcessor { |
ohair@286 | 33 | |
ohair@286 | 34 | protected MutableXMLStreamBuffer _buffer; |
ohair@286 | 35 | |
ohair@286 | 36 | public void setXMLStreamBuffer(MutableXMLStreamBuffer buffer) { |
ohair@286 | 37 | if (buffer == null) { |
ohair@286 | 38 | throw new NullPointerException("buffer cannot be null"); |
ohair@286 | 39 | } |
ohair@286 | 40 | setBuffer(buffer); |
ohair@286 | 41 | } |
ohair@286 | 42 | |
ohair@286 | 43 | public MutableXMLStreamBuffer getXMLStreamBuffer() { |
ohair@286 | 44 | return _buffer; |
ohair@286 | 45 | } |
ohair@286 | 46 | |
ohair@286 | 47 | |
ohair@286 | 48 | protected final void createBuffer() { |
ohair@286 | 49 | setBuffer(new MutableXMLStreamBuffer()); |
ohair@286 | 50 | } |
ohair@286 | 51 | |
ohair@286 | 52 | /** |
ohair@286 | 53 | * Should be called whenever a new tree is stored on the buffer. |
ohair@286 | 54 | */ |
ohair@286 | 55 | protected final void increaseTreeCount() { |
ohair@286 | 56 | _buffer.treeCount++; |
ohair@286 | 57 | } |
ohair@286 | 58 | |
ohair@286 | 59 | protected final void setBuffer(MutableXMLStreamBuffer buffer) { |
ohair@286 | 60 | _buffer = buffer; |
ohair@286 | 61 | |
ohair@286 | 62 | _currentStructureFragment = _buffer.getStructure(); |
ohair@286 | 63 | _structure = _currentStructureFragment.getArray(); |
ohair@286 | 64 | _structurePtr = 0; |
ohair@286 | 65 | |
ohair@286 | 66 | _currentStructureStringFragment = _buffer.getStructureStrings(); |
ohair@286 | 67 | _structureStrings = _currentStructureStringFragment.getArray(); |
ohair@286 | 68 | _structureStringsPtr = 0; |
ohair@286 | 69 | |
ohair@286 | 70 | _currentContentCharactersBufferFragment = _buffer.getContentCharactersBuffer(); |
ohair@286 | 71 | _contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray(); |
ohair@286 | 72 | _contentCharactersBufferPtr = 0; |
ohair@286 | 73 | |
ohair@286 | 74 | _currentContentObjectFragment = _buffer.getContentObjects(); |
ohair@286 | 75 | _contentObjects = _currentContentObjectFragment.getArray(); |
ohair@286 | 76 | _contentObjectsPtr = 0; |
ohair@286 | 77 | } |
ohair@286 | 78 | |
ohair@286 | 79 | protected final void setHasInternedStrings(boolean hasInternedStrings) { |
ohair@286 | 80 | _buffer.setHasInternedStrings(hasInternedStrings); |
ohair@286 | 81 | } |
ohair@286 | 82 | |
ohair@286 | 83 | protected final void storeStructure(int b) { |
ohair@286 | 84 | _structure[_structurePtr++] = (byte)b; |
ohair@286 | 85 | if (_structurePtr == _structure.length) { |
ohair@286 | 86 | resizeStructure(); |
ohair@286 | 87 | } |
ohair@286 | 88 | } |
ohair@286 | 89 | |
ohair@286 | 90 | protected final void resizeStructure() { |
ohair@286 | 91 | _structurePtr = 0; |
ohair@286 | 92 | if (_currentStructureFragment.getNext() != null) { |
ohair@286 | 93 | _currentStructureFragment = _currentStructureFragment.getNext(); |
ohair@286 | 94 | _structure = _currentStructureFragment.getArray(); |
ohair@286 | 95 | } else { |
ohair@286 | 96 | _structure = new byte[_structure.length]; |
ohair@286 | 97 | _currentStructureFragment = new FragmentedArray(_structure, _currentStructureFragment); |
ohair@286 | 98 | } |
ohair@286 | 99 | } |
ohair@286 | 100 | |
ohair@286 | 101 | protected final void storeStructureString(String s) { |
ohair@286 | 102 | _structureStrings[_structureStringsPtr++] = s; |
ohair@286 | 103 | if (_structureStringsPtr == _structureStrings.length) { |
ohair@286 | 104 | resizeStructureStrings(); |
ohair@286 | 105 | } |
ohair@286 | 106 | } |
ohair@286 | 107 | |
ohair@286 | 108 | protected final void resizeStructureStrings() { |
ohair@286 | 109 | _structureStringsPtr = 0; |
ohair@286 | 110 | if (_currentStructureStringFragment.getNext() != null) { |
ohair@286 | 111 | _currentStructureStringFragment = _currentStructureStringFragment.getNext(); |
ohair@286 | 112 | _structureStrings = _currentStructureStringFragment.getArray(); |
ohair@286 | 113 | } else { |
ohair@286 | 114 | _structureStrings = new String[_structureStrings.length]; |
ohair@286 | 115 | _currentStructureStringFragment = new FragmentedArray(_structureStrings, _currentStructureStringFragment); |
ohair@286 | 116 | } |
ohair@286 | 117 | } |
ohair@286 | 118 | |
ohair@286 | 119 | protected final void storeContentString(String s) { |
ohair@286 | 120 | storeContentObject(s); |
ohair@286 | 121 | } |
ohair@286 | 122 | |
ohair@286 | 123 | protected final void storeContentCharacters(int type, char[] ch, int start, int length) { |
ohair@286 | 124 | if (_contentCharactersBufferPtr + length >= _contentCharactersBuffer.length) { |
ohair@286 | 125 | if (length >= 512) { |
ohair@286 | 126 | storeStructure(type | CONTENT_TYPE_CHAR_ARRAY_COPY); |
ohair@286 | 127 | storeContentCharactersCopy(ch, start, length); |
ohair@286 | 128 | return; |
ohair@286 | 129 | } |
ohair@286 | 130 | resizeContentCharacters(); |
ohair@286 | 131 | } |
ohair@286 | 132 | |
ohair@286 | 133 | if (length < CHAR_ARRAY_LENGTH_SMALL_SIZE) { |
alanb@368 | 134 | storeStructure(type); |
ohair@286 | 135 | storeStructure(length); |
ohair@286 | 136 | System.arraycopy(ch, start, _contentCharactersBuffer, _contentCharactersBufferPtr, length); |
ohair@286 | 137 | _contentCharactersBufferPtr += length; |
ohair@286 | 138 | } else if (length < CHAR_ARRAY_LENGTH_MEDIUM_SIZE) { |
ohair@286 | 139 | storeStructure(type | CHAR_ARRAY_LENGTH_MEDIUM); |
ohair@286 | 140 | storeStructure(length >> 8); |
ohair@286 | 141 | storeStructure(length & 255); |
ohair@286 | 142 | System.arraycopy(ch, start, _contentCharactersBuffer, _contentCharactersBufferPtr, length); |
ohair@286 | 143 | _contentCharactersBufferPtr += length; |
ohair@286 | 144 | } else { |
ohair@286 | 145 | storeStructure(type | CONTENT_TYPE_CHAR_ARRAY_COPY); |
ohair@286 | 146 | storeContentCharactersCopy(ch, start, length); |
ohair@286 | 147 | } |
ohair@286 | 148 | } |
ohair@286 | 149 | |
ohair@286 | 150 | protected final void resizeContentCharacters() { |
ohair@286 | 151 | _contentCharactersBufferPtr = 0; |
ohair@286 | 152 | if (_currentContentCharactersBufferFragment.getNext() != null) { |
ohair@286 | 153 | _currentContentCharactersBufferFragment = _currentContentCharactersBufferFragment.getNext(); |
ohair@286 | 154 | _contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray(); |
ohair@286 | 155 | } else { |
ohair@286 | 156 | _contentCharactersBuffer = new char[_contentCharactersBuffer.length]; |
ohair@286 | 157 | _currentContentCharactersBufferFragment = new FragmentedArray(_contentCharactersBuffer, |
ohair@286 | 158 | _currentContentCharactersBufferFragment); |
ohair@286 | 159 | } |
ohair@286 | 160 | } |
ohair@286 | 161 | |
ohair@286 | 162 | protected final void storeContentCharactersCopy(char[] ch, int start, int length) { |
ohair@286 | 163 | char[] copyOfCh = new char[length]; |
ohair@286 | 164 | System.arraycopy(ch, start, copyOfCh, 0, length); |
ohair@286 | 165 | storeContentObject(copyOfCh); |
ohair@286 | 166 | } |
ohair@286 | 167 | |
ohair@286 | 168 | protected final Object peekAtContentObject() { |
ohair@286 | 169 | return _contentObjects[_contentObjectsPtr]; |
ohair@286 | 170 | } |
ohair@286 | 171 | |
ohair@286 | 172 | protected final void storeContentObject(Object s) { |
ohair@286 | 173 | _contentObjects[_contentObjectsPtr++] = s; |
ohair@286 | 174 | if (_contentObjectsPtr == _contentObjects.length) { |
ohair@286 | 175 | resizeContentObjects(); |
ohair@286 | 176 | } |
ohair@286 | 177 | } |
ohair@286 | 178 | |
ohair@286 | 179 | protected final void resizeContentObjects() { |
ohair@286 | 180 | _contentObjectsPtr = 0; |
ohair@286 | 181 | if (_currentContentObjectFragment.getNext() != null) { |
ohair@286 | 182 | _currentContentObjectFragment = _currentContentObjectFragment.getNext(); |
ohair@286 | 183 | _contentObjects = _currentContentObjectFragment.getArray(); |
ohair@286 | 184 | } else { |
ohair@286 | 185 | _contentObjects = new Object[_contentObjects.length]; |
ohair@286 | 186 | _currentContentObjectFragment = new FragmentedArray(_contentObjects, _currentContentObjectFragment); |
ohair@286 | 187 | } |
ohair@286 | 188 | } |
ohair@286 | 189 | } |