325N/A/*
325N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A *
325N/A * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.fastinfoset.util;
325N/A
325N/Aimport com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
325N/Aimport com.sun.xml.internal.fastinfoset.CommonResourceBundle;
325N/A
325N/A
325N/Apublic class DuplicateAttributeVerifier {
325N/A public static final int MAP_SIZE = 256;
325N/A
325N/A public int _currentIteration;
325N/A
325N/A public static class Entry {
325N/A private int iteration;
325N/A private int value;
325N/A
325N/A private Entry hashNext;
325N/A
325N/A private Entry poolNext;
325N/A }
325N/A
325N/A private Entry[] _map;
325N/A
325N/A public final Entry _poolHead;
325N/A public Entry _poolCurrent;
325N/A private Entry _poolTail;
325N/A
325N/A
325N/A public DuplicateAttributeVerifier() {
325N/A _poolTail = _poolHead = new Entry();
325N/A }
325N/A
325N/A public final void clear() {
325N/A _currentIteration = 0;
325N/A
325N/A Entry e = _poolHead;
325N/A while (e != null) {
325N/A e.iteration = 0;
325N/A e = e.poolNext;
325N/A }
325N/A
325N/A reset();
325N/A }
325N/A
325N/A public final void reset() {
325N/A _poolCurrent = _poolHead;
325N/A if (_map == null) {
325N/A _map = new Entry[MAP_SIZE];
325N/A }
325N/A }
325N/A
325N/A private final void increasePool(int capacity) {
325N/A if (_map == null) {
325N/A _map = new Entry[MAP_SIZE];
325N/A _poolCurrent = _poolHead;
325N/A } else {
325N/A final Entry tail = _poolTail;
325N/A for (int i = 0; i < capacity; i++) {
325N/A final Entry e = new Entry();
325N/A _poolTail.poolNext = e;
325N/A _poolTail = e;
325N/A }
325N/A
325N/A _poolCurrent = tail.poolNext;
325N/A }
325N/A }
325N/A
325N/A public final void checkForDuplicateAttribute(int hash, int value) throws FastInfosetException {
325N/A if (_poolCurrent == null) {
325N/A increasePool(16);
325N/A }
325N/A
325N/A // Get next free entry
325N/A final Entry newEntry = _poolCurrent;
325N/A _poolCurrent = _poolCurrent.poolNext;
325N/A
325N/A final Entry head = _map[hash];
325N/A if (head == null || head.iteration < _currentIteration) {
325N/A newEntry.hashNext = null;
325N/A _map[hash] = newEntry;
325N/A newEntry.iteration = _currentIteration;
325N/A newEntry.value = value;
325N/A } else {
325N/A Entry e = head;
325N/A do {
325N/A if (e.value == value) {
325N/A reset();
325N/A throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateAttribute"));
325N/A }
325N/A } while ((e = e.hashNext) != null);
325N/A
325N/A newEntry.hashNext = head;
325N/A _map[hash] = newEntry;
325N/A newEntry.iteration = _currentIteration;
325N/A newEntry.value = value;
325N/A }
325N/A }
325N/A}