KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > util > XMLAttributesIteratorImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://jaxp.dev.java.net/CDDLv1.0.html.
9  * See the License for the specific language governing
10  * permissions and limitations under the License.
11  *
12  * When distributing Covered Code, include this CDDL
13  * HEADER in each file and include the License file at
14  * https://jaxp.dev.java.net/CDDLv1.0.html
15  * If applicable add the following below this CDDL HEADER
16  * with the fields enclosed by brackets "[]" replaced with
17  * your own identifying information: Portions Copyright
18  * [year] [name of copyright owner]
19  */

20
21 /*
22  * $Id: XMLEntityReader.java,v 1.3 2005/11/03 17:02:21 jeffsuttor Exp $
23  * @(#)XMLAttributesIteratorImpl.java 1.6 05/11/17
24  *
25  * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package com.sun.org.apache.xerces.internal.util;
29
30 //java imports
31
import java.util.Iterator JavaDoc ;
32 import java.util.NoSuchElementException JavaDoc;
33
34 //xerces imports
35
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl ;
36
37 /**
38  *
39  * @author Neeraj Bajaj, Sun Microsystems
40  */

41
42 /**
43  * Its better to extend the functionality of existing XMLAttributesImpl and also make it of type Iterator.
44  * We can directly give an object of type iterator from StartElement event. We should also have
45  * Attribute object of type javax.xml.stream.Attribute internally. It would avoid the need of creating
46  * new javax.xml.stream.Attribute object at the later stage.
47  *
48  * Should we change XMLAttributes interface to implement Iteraotr ? I think its better avoid touching XNI as
49  * much as possible. - NB.
50  */

51
52 public class XMLAttributesIteratorImpl extends XMLAttributesImpl implements Iterator JavaDoc {
53     
54     //pointer to current position.
55
protected int fCurrent = 0 ;
56     
57     protected XMLAttributesImpl.Attribute fLastReturnedItem ;
58     
59     /** Creates a new instance of XMLAttributesIteratorImpl */
60     public XMLAttributesIteratorImpl() {
61     }
62     
63     public boolean hasNext() {
64         return fCurrent < getLength() ? true : false ;
65     }//hasNext()
66

67     public Object JavaDoc next() {
68         if(hasNext()){
69             // should this be of type javax.xml.stream.Attribute ?
70
return fLastReturnedItem = fAttributes[fCurrent++] ;
71         }
72         else{
73             throw new NoSuchElementException JavaDoc() ;
74         }
75     }//next
76

77     public void remove() {
78         //make sure that only last returned item can be removed.
79
if(fLastReturnedItem == fAttributes[fCurrent - 1]){
80             //remove the attribute at current index and lower the current position by 1.
81
removeAttributeAt(fCurrent--) ;
82         }
83         else {
84             //either the next method has been called yet, or the remove method has already been called
85
//after the last call to the next method.
86
throw new IllegalStateException JavaDoc();
87         }
88     }//remove
89

90     public void removeAllAttributes() {
91         super.removeAllAttributes() ;
92         fCurrent = 0 ;
93     }
94     /** xxx: should we be doing this way ? Attribute event defines so many functions which doesn't make any sense
95      *for Attribute.
96      *
97      */

98     /*
99     class AttributeImpl extends com.sun.org.apache.xerces.internal.util.XMLAttributesImpl.Attribute implements javax.xml.stream.events.Attribute{
100      
101     }
102      */

103     
104 } //XMLAttributesIteratorImpl
105
Popular Tags