01: /**
02: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
03: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
04: */package com.sun.xml.stream.xerces.util;
05:
06: //java imports
07: import java.util.Iterator;
08: import java.util.NoSuchElementException;
09:
10: //xerces imports
11: import com.sun.xml.stream.xerces.util.XMLAttributesImpl;
12:
13: /**
14: *
15: * @author Neeraj Bajaj, Sun Microsystems
16: */
17:
18: /**
19: * Its better to extend the functionality of existing XMLAttributesImpl and also make it of type Iterator.
20: * We can directly give an object of type iterator from StartElement event. We should also have
21: * Attribute object of type javax.xml.stream.Attribute internally. It would avoid the need of creating
22: * new javax.xml.stream.Attribute object at the later stage.
23: *
24: * Should we change XMLAttributes interface to implement Iteraotr ? I think its better avoid touching XNI as
25: * much as possible. - NB.
26: */
27:
28: public class XMLAttributesIteratorImpl extends XMLAttributesImpl
29: implements Iterator {
30:
31: //pointer to current position.
32: protected int fCurrent = 0;
33:
34: protected XMLAttributesImpl.Attribute fLastReturnedItem;
35:
36: /** Creates a new instance of XMLAttributesIteratorImpl */
37: public XMLAttributesIteratorImpl() {
38: }
39:
40: public boolean hasNext() {
41: return fCurrent < getLength() ? true : false;
42: }//hasNext()
43:
44: public Object next() {
45: if (hasNext()) {
46: // should this be of type javax.xml.stream.Attribute ?
47: return fLastReturnedItem = fAttributes[fCurrent++];
48: } else {
49: throw new NoSuchElementException();
50: }
51: }//next
52:
53: public void remove() {
54: //make sure that only last returned item can be removed.
55: if (fLastReturnedItem == fAttributes[fCurrent - 1]) {
56: //remove the attribute at current index and lower the current position by 1.
57: removeAttributeAt(fCurrent--);
58: } else {
59: //either the next method has been called yet, or the remove method has already been called
60: //after the last call to the next method.
61: throw new IllegalStateException();
62: }
63: }//remove
64:
65: public void removeAllAttributes() {
66: super .removeAllAttributes();
67: fCurrent = 0;
68: }
69: /** xxx: should we be doing this way ? Attribute event defines so many functions which doesn't make any sense
70: *for Attribute.
71: *
72: */
73: /*
74: class AttributeImpl extends com.sun.xml.stream.xerces.util.XMLAttributesImpl.Attribute implements javax.xml.stream.events.Attribute{
75:
76: }
77: */
78:
79: } //XMLAttributesIteratorImpl
|