1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/AbstractCreator.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,189 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.stream.buffer; 1.30 + 1.31 +/** 1.32 + * Base class for classes that creates {@link MutableXMLStreamBuffer} 1.33 + * and from infoset in API-specific form. 1.34 + */ 1.35 +public class AbstractCreator extends AbstractCreatorProcessor { 1.36 + 1.37 + protected MutableXMLStreamBuffer _buffer; 1.38 + 1.39 + public void setXMLStreamBuffer(MutableXMLStreamBuffer buffer) { 1.40 + if (buffer == null) { 1.41 + throw new NullPointerException("buffer cannot be null"); 1.42 + } 1.43 + setBuffer(buffer); 1.44 + } 1.45 + 1.46 + public MutableXMLStreamBuffer getXMLStreamBuffer() { 1.47 + return _buffer; 1.48 + } 1.49 + 1.50 + 1.51 + protected final void createBuffer() { 1.52 + setBuffer(new MutableXMLStreamBuffer()); 1.53 + } 1.54 + 1.55 + /** 1.56 + * Should be called whenever a new tree is stored on the buffer. 1.57 + */ 1.58 + protected final void increaseTreeCount() { 1.59 + _buffer.treeCount++; 1.60 + } 1.61 + 1.62 + protected final void setBuffer(MutableXMLStreamBuffer buffer) { 1.63 + _buffer = buffer; 1.64 + 1.65 + _currentStructureFragment = _buffer.getStructure(); 1.66 + _structure = _currentStructureFragment.getArray(); 1.67 + _structurePtr = 0; 1.68 + 1.69 + _currentStructureStringFragment = _buffer.getStructureStrings(); 1.70 + _structureStrings = _currentStructureStringFragment.getArray(); 1.71 + _structureStringsPtr = 0; 1.72 + 1.73 + _currentContentCharactersBufferFragment = _buffer.getContentCharactersBuffer(); 1.74 + _contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray(); 1.75 + _contentCharactersBufferPtr = 0; 1.76 + 1.77 + _currentContentObjectFragment = _buffer.getContentObjects(); 1.78 + _contentObjects = _currentContentObjectFragment.getArray(); 1.79 + _contentObjectsPtr = 0; 1.80 + } 1.81 + 1.82 + protected final void setHasInternedStrings(boolean hasInternedStrings) { 1.83 + _buffer.setHasInternedStrings(hasInternedStrings); 1.84 + } 1.85 + 1.86 + protected final void storeStructure(int b) { 1.87 + _structure[_structurePtr++] = (byte)b; 1.88 + if (_structurePtr == _structure.length) { 1.89 + resizeStructure(); 1.90 + } 1.91 + } 1.92 + 1.93 + protected final void resizeStructure() { 1.94 + _structurePtr = 0; 1.95 + if (_currentStructureFragment.getNext() != null) { 1.96 + _currentStructureFragment = _currentStructureFragment.getNext(); 1.97 + _structure = _currentStructureFragment.getArray(); 1.98 + } else { 1.99 + _structure = new byte[_structure.length]; 1.100 + _currentStructureFragment = new FragmentedArray(_structure, _currentStructureFragment); 1.101 + } 1.102 + } 1.103 + 1.104 + protected final void storeStructureString(String s) { 1.105 + _structureStrings[_structureStringsPtr++] = s; 1.106 + if (_structureStringsPtr == _structureStrings.length) { 1.107 + resizeStructureStrings(); 1.108 + } 1.109 + } 1.110 + 1.111 + protected final void resizeStructureStrings() { 1.112 + _structureStringsPtr = 0; 1.113 + if (_currentStructureStringFragment.getNext() != null) { 1.114 + _currentStructureStringFragment = _currentStructureStringFragment.getNext(); 1.115 + _structureStrings = _currentStructureStringFragment.getArray(); 1.116 + } else { 1.117 + _structureStrings = new String[_structureStrings.length]; 1.118 + _currentStructureStringFragment = new FragmentedArray(_structureStrings, _currentStructureStringFragment); 1.119 + } 1.120 + } 1.121 + 1.122 + protected final void storeContentString(String s) { 1.123 + storeContentObject(s); 1.124 + } 1.125 + 1.126 + protected final void storeContentCharacters(int type, char[] ch, int start, int length) { 1.127 + if (_contentCharactersBufferPtr + length >= _contentCharactersBuffer.length) { 1.128 + if (length >= 512) { 1.129 + storeStructure(type | CONTENT_TYPE_CHAR_ARRAY_COPY); 1.130 + storeContentCharactersCopy(ch, start, length); 1.131 + return; 1.132 + } 1.133 + resizeContentCharacters(); 1.134 + } 1.135 + 1.136 + if (length < CHAR_ARRAY_LENGTH_SMALL_SIZE) { 1.137 + storeStructure(type | CHAR_ARRAY_LENGTH_SMALL); 1.138 + storeStructure(length); 1.139 + System.arraycopy(ch, start, _contentCharactersBuffer, _contentCharactersBufferPtr, length); 1.140 + _contentCharactersBufferPtr += length; 1.141 + } else if (length < CHAR_ARRAY_LENGTH_MEDIUM_SIZE) { 1.142 + storeStructure(type | CHAR_ARRAY_LENGTH_MEDIUM); 1.143 + storeStructure(length >> 8); 1.144 + storeStructure(length & 255); 1.145 + System.arraycopy(ch, start, _contentCharactersBuffer, _contentCharactersBufferPtr, length); 1.146 + _contentCharactersBufferPtr += length; 1.147 + } else { 1.148 + storeStructure(type | CONTENT_TYPE_CHAR_ARRAY_COPY); 1.149 + storeContentCharactersCopy(ch, start, length); 1.150 + } 1.151 + } 1.152 + 1.153 + protected final void resizeContentCharacters() { 1.154 + _contentCharactersBufferPtr = 0; 1.155 + if (_currentContentCharactersBufferFragment.getNext() != null) { 1.156 + _currentContentCharactersBufferFragment = _currentContentCharactersBufferFragment.getNext(); 1.157 + _contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray(); 1.158 + } else { 1.159 + _contentCharactersBuffer = new char[_contentCharactersBuffer.length]; 1.160 + _currentContentCharactersBufferFragment = new FragmentedArray(_contentCharactersBuffer, 1.161 + _currentContentCharactersBufferFragment); 1.162 + } 1.163 + } 1.164 + 1.165 + protected final void storeContentCharactersCopy(char[] ch, int start, int length) { 1.166 + char[] copyOfCh = new char[length]; 1.167 + System.arraycopy(ch, start, copyOfCh, 0, length); 1.168 + storeContentObject(copyOfCh); 1.169 + } 1.170 + 1.171 + protected final Object peekAtContentObject() { 1.172 + return _contentObjects[_contentObjectsPtr]; 1.173 + } 1.174 + 1.175 + protected final void storeContentObject(Object s) { 1.176 + _contentObjects[_contentObjectsPtr++] = s; 1.177 + if (_contentObjectsPtr == _contentObjects.length) { 1.178 + resizeContentObjects(); 1.179 + } 1.180 + } 1.181 + 1.182 + protected final void resizeContentObjects() { 1.183 + _contentObjectsPtr = 0; 1.184 + if (_currentContentObjectFragment.getNext() != null) { 1.185 + _currentContentObjectFragment = _currentContentObjectFragment.getNext(); 1.186 + _contentObjects = _currentContentObjectFragment.getArray(); 1.187 + } else { 1.188 + _contentObjects = new Object[_contentObjects.length]; 1.189 + _currentContentObjectFragment = new FragmentedArray(_contentObjects, _currentContentObjectFragment); 1.190 + } 1.191 + } 1.192 +}