Statistics
| Revision:

root / branches / Mobile1.0 / org.gvsig.gpe / src-test / org / gvsig / gpe / containers / AttributesIterator.java @ 79

History | View | Annotate | Download (3.05 KB)

1
package org.gvsig.gpe.containers;
2

    
3
import java.io.IOException;
4
import java.util.HashMap;
5
import java.util.Iterator;
6

    
7
import javax.xml.namespace.QName;
8

    
9
import org.gvsig.gpe.parser.IAttributesIterator;
10
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
11
*
12
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
13
*
14
* This program is free software; you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License
16
* as published by the Free Software Foundation; either version 2
17
* of the License, or (at your option) any later version.
18
*
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
* GNU General Public License for more details.
23
*
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
27
*
28
* For more information, contact:
29
*
30
*  Generalitat Valenciana
31
*   Conselleria d'Infraestructures i Transport
32
*   Av. Blasco Ib??ez, 50
33
*   46010 VALENCIA
34
*   SPAIN
35
*
36
*      +34 963862235
37
*   gvsig@gva.es
38
*      www.gvsig.gva.es
39
*
40
*    or
41
*
42
*   IVER T.I. S.A
43
*   Salamanca 50
44
*   46005 Valencia
45
*   Spain
46
*
47
*   +34 963163400
48
*   dac@iver.es
49
*/
50
/* CVS MESSAGES:
51
*
52
* $Id$
53
* $Log$
54
*
55
*/
56
/**
57
* @author Carlos S?nchez Peri??n
58
*/
59
public class AttributesIterator implements IAttributesIterator{
60
        private HashMap attributes;
61
        private Iterator keys = null;
62
        private QName currentAttibuteName = null;
63
        
64
        public AttributesIterator(QName name, Object value){
65
                attributes = new HashMap();
66
                attributes.put(name, value);
67
                initialize();
68
        }
69
        
70
        public AttributesIterator(QName[] names, String[] values){
71
                attributes = new HashMap();
72
                for (int i=0 ; i<names.length ; i++){
73
                        attributes.put(names[i], values[i]);
74
                }
75
                initialize();
76
        }        
77
        
78
        /*
79
         * (non-Javadoc)
80
         * @see org.gvsig.gpe.parser.IAttributesIterator#hasNext()
81
         */
82
        public boolean hasNext() throws IOException {
83
                currentAttibuteName = null;
84
                return (keys.hasNext());
85
        }
86

    
87
        /*
88
         * (non-Javadoc)
89
         * @see org.gvsig.gpe.parser.IAttributesIterator#getNumAttributes()
90
         */
91
        public int getNumAttributes() {
92
                return attributes.size();
93
        }
94

    
95
        /* (non-Javadoc)
96
         * @see org.gvsig.gpe.parser.IAttributesIterator#nextAttribute()
97
         */
98
        public Object nextAttribute() throws IOException {
99
                setAttributeName();
100
                return attributes.get(currentAttibuteName);        
101
        }
102

    
103
        /* (non-Javadoc)
104
         * @see org.gvsig.gpe.parser.IAttributesIterator#nextAttributeName()
105
         */
106
        public QName nextAttributeName() {
107
                setAttributeName();
108
                return currentAttibuteName;
109
        }
110
        
111
        private void setAttributeName(){
112
                if (currentAttibuteName == null){
113
                        currentAttibuteName = (QName)keys.next();
114
                }
115
        }
116

    
117
        /* (non-Javadoc)
118
         * @see org.gvsig.gpe.parser.IAttributesIterator#initialize()
119
         */
120
        public void initialize() {
121
                keys = attributes.keySet().iterator();                
122
        }
123

    
124
}