1 package org.apache.maven.project.harness;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.commons.jxpath.ri.QName;
28 import org.apache.commons.jxpath.ri.model.NodeIterator;
29 import org.apache.commons.jxpath.ri.model.NodePointer;
30 import org.codehaus.plexus.util.xml.Xpp3Dom;
31
32
33
34
35
36
37
38 class Xpp3DomAttributeIterator
39 implements NodeIterator
40 {
41
42 private NodePointer parent;
43
44 private Xpp3Dom node;
45
46 private List<Map.Entry<String, String>> attributes;
47
48 private Map.Entry<String, String> attribute;
49
50 private int position;
51
52 public Xpp3DomAttributeIterator( NodePointer parent, QName qname )
53 {
54 this.parent = parent;
55 this.node = (Xpp3Dom) parent.getNode();
56
57 Map<String, String> map = new LinkedHashMap<String, String>();
58 for ( String name : this.node.getAttributeNames() )
59 {
60 if ( name.equals( qname.getName() ) || "*".equals( qname.getName() ) )
61 {
62 String value = this.node.getAttribute( name );
63 map.put( name, value );
64 }
65 }
66 this.attributes = new ArrayList<Map.Entry<String, String>>( map.entrySet() );
67 }
68
69 public NodePointer getNodePointer()
70 {
71 if ( position == 0 )
72 {
73 setPosition( 1 );
74 }
75 return ( attribute == null ) ? null : new Xpp3DomAttributePointer( parent, attribute );
76 }
77
78 public int getPosition()
79 {
80 return position;
81 }
82
83 public boolean setPosition( int position )
84 {
85 this.position = position;
86 attribute = ( position > 0 && position <= attributes.size() ) ? attributes.get( position - 1 ) : null;
87 return attribute != null;
88 }
89
90 }