/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* {@link XmlOutput} for {@link LowLevelStAXDocumentSerializer}.
* <p>
* This class is responsible for managing the indexing of elements, attributes
* and local names that are known to JAXB by way of the JAXBContext (generated
* from JAXB beans or schema). The pre-encoded UTF-8 representations of known
* local names are also utilized.
* <p>
* The lookup of elements, attributes and local names with respect to a context
* is very efficient. It relies on an incrementing base line so that look up is
* performed in O(1) time and only uses static memory. When the base line reaches
* a point where integer overflow will occur the arrays and base line are reset
* (such an event is rare and will have little impact on performance).
* <p>
* A weak map of JAXB contexts to optimized tables for attributes, elements and
* local names is utilized and stored on the LowLevel StAX serializer. Thus,
* optimized serializing can work other multiple serializing of JAXB beans using
* the same LowLevel StAX serializer instance. This approach works best when JAXB
* contexts are only created once per schema or JAXB beans (which is the recommended
* practice as the creation JAXB contexts are expensive, they are thread safe and
* can be reused).
*
* @author Paul.Sandoz@Sun.Com
*/
/**
* Holder for the optimzed element, attribute and
* local name tables.
*/
final static class TablesPerJAXBContext {
final int[] elementIndexes;
final int[] elementIndexPrefixes;
final int[] attributeIndexes;
final int[] localNameIndexes;
/**
* The offset of the index
*/
int indexOffset;
/**
* The the maximum known value of an index
*/
int maxIndex;
/**
* True if the tables require clearing
*/
boolean requiresClear;
/**
* Create a new set of tables for a JAXB context.
* <p>
* @param content the JAXB context.
* @param initialIndexOffset the initial index offset to calculate
* the maximum possible index
*
*/
indexOffset = 1;
}
/**
* Require that tables are cleared.
*/
public void requireClearTables() {
requiresClear = true;
}
/**
* Clear or reset the tables.
* <p>
* @param initialIndexOffset the initial index offset to calculate
* the maximum possible index
*/
if (requiresClear) {
requiresClear = false;
// Increment offset to new position
indexOffset += maxIndex;
// Reset the maximum known value of an index
// Check if there is enough free space
// If overflow
clearAll();
}
} else {
// Reset the maximum known value of an index
// Check if there is enough free space
// If overflow
resetAll();
}
}
}
private void clearAll() {
indexOffset = 1;
}
array[i] = 0;
}
}
/**
* Increment the maximum know index value
* <p>
* The indexes are preserved.
*/
public void incrementMaxIndexValue() {
// Increment the maximum value of an index
maxIndex++;
// Check if there is enough free space
// If overflow
resetAll();
}
}
private void resetAll() {
indexOffset = 1;
}
if (array[i] > indexOffset) {
} else {
array[i] = 0;
}
}
}
}
/**
* Holder of JAXB contexts -> tables.
* <p>
* An instance will be registered with the
* {@link LowLevelStAXDocumentSerializer}.
*/
/**
* Clear all the tables.
*/
public void clear() {
for(TablesPerJAXBContext c : collectionOfContexts)
c.requireClearTables();
}
}
super(out);
} else {
}
if (tablesPerContext != null) {
/**
* Obtain the current local name index. Thus will be used to
* calculate the maximum index value when serializing for this context
*/
} else {
}
}
if (fragment)
}
super.endDocument(fragment);
}
if (qNameIndex >= 0 &&
} else {
name,
}
} else {
}
}
continue; // no point in definint xmlns='' on the root
}
if (qNameIndex >= 0 &&
} else {
name,
}
}
if (qNameIndex >= 0) {
} else {
if (namespaceURIId == -1) {
name,
"",
"");
} else {
name,
}
}
}
private void writeLiteral(int type, Name name, String prefix, String namespaceURI) throws IOException {
if (localNameIndex < 0) {
type,
} else {
type,
}
}
}
}
}
/*
* Check if the CharSequence is from a base64Binary data type
*/
if (!(value instanceof Base64Data)) {
} else {
}
} else {
// Write out the octets using the base64 encoding algorithm
}
}
}
continue; // no point in definint xmlns='' on the root
}
type= 0;
}
type,
if (!isIndexed)
}
boolean isIndexed;
if (prefix == -1)
else
if (!isIndexed)
}
}