1/*2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.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 it6 * under the terms of the GNU General Public License version 2 only, as7 * published by the Free Software Foundation. Oracle designates this8 * particular file as subject to the "Classpath" exception as provided9 * 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 WITHOUT12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License14 * version 2 for more details (a copy is included in the LICENSE file that15 * accompanied this code).16 *17 * You should have received a copy of the GNU General Public License version18 * 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 USA22 * or visit www.oracle.com if you need additional information or have any23 * questions.24 */2526package com.sun.org.apache.xerces.internal.util;
2728//java imports29import java.util.Iterator ;
30import java.util.NoSuchElementException;
3132//xerces imports33import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl ;
3435/**36 *37 * @author Neeraj Bajaj, Sun Microsystems38 */3940/**41 * Its better to extend the functionality of existing XMLAttributesImpl and also make it of type Iterator.42 * We can directly give an object of type iterator from StartElement event. We should also have43 * Attribute object of type javax.xml.stream.Attribute internally. It would avoid the need of creating44 * new javax.xml.stream.Attribute object at the later stage.45 *46 * Should we change XMLAttributes interface to implement Iteraotr ? I think its better avoid touching XNI as47 * much as possible. - NB.48 */4950publicclassXMLAttributesIteratorImplextendsXMLAttributesImplimplementsIterator {
5152//pointer to current position.53protectedint fCurrent = 0 ;
5455protected XMLAttributesImpl.Attribute fLastReturnedItem ;
5657/** Creates a new instance of XMLAttributesIteratorImpl */58publicXMLAttributesIteratorImpl() {
59 }
6061publicboolean hasNext() {
62return fCurrent < getLength() ? true : false ;
63 }//hasNext()6465publicObject next() {
66if(hasNext()){
67// should this be of type javax.xml.stream.Attribute ?68return fLastReturnedItem = fAttributes[fCurrent++] ;
69 }
70else{
71thrownewNoSuchElementException() ;
72 }
73 }//next7475publicvoid remove() {
76//make sure that only last returned item can be removed.77if(fLastReturnedItem == fAttributes[fCurrent - 1]){
78//remove the attribute at current index and lower the current position by 1.79 removeAttributeAt(fCurrent--) ;
80 }
81else {
82//either the next method has been called yet, or the remove method has already been called83//after the last call to the next method.84thrownewIllegalStateException();
85 }
86 }//remove8788publicvoid removeAllAttributes() {
89super.removeAllAttributes() ;
90 fCurrent = 0 ;
91 }
92/** xxx: should we be doing this way ? Attribute event defines so many functions which doesn't make any sense93 *for Attribute.94 *95 */96/*97 class AttributeImpl extends com.sun.org.apache.xerces.internal.util.XMLAttributesImpl.Attribute implements javax.xml.stream.events.Attribute{9899 }100 */101102 } //XMLAttributesIteratorImpl