Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / loadbalancer / api / parsers / NodesXMLParser.java @ b722cab3

History | View | Annotate | Download (2.3 kB)

1
/**
2
 * 
3
 */
4
package com.rackspace.cloud.loadbalancer.api.parsers;
5

    
6
import java.util.ArrayList;
7
import org.xml.sax.Attributes;
8
import org.xml.sax.helpers.DefaultHandler;
9
import android.util.Log;
10

    
11
import com.rackspace.cloud.loadbalancer.api.client.Node;
12

    
13
public class NodesXMLParser extends DefaultHandler {
14

    
15
        private Node node;
16
        private ArrayList<Node> nodes;
17
        private StringBuffer currentData;
18

    
19
        public void startDocument() {
20
        }
21

    
22
        public void endDocument() {
23
        }
24

    
25
        public void startElement(String uri, String name, String qName,
26
                        Attributes atts) {
27

    
28
                currentData = new StringBuffer();
29
                if ("nodes".equalsIgnoreCase(name)) {
30
                        nodes = new ArrayList<Node>();
31
                } else if ("node".equalsIgnoreCase(name)) {
32
                        node = new Node();
33
                        node.setId(atts.getValue("id"));
34
                        node.setAddress(atts.getValue("address"));
35
                        node.setPort(atts.getValue("port"));
36
                        node.setCondition(atts.getValue("condition"));
37
                        node.setStatus(atts.getValue("status"));
38
                        node.setWeight(atts.getValue("weight"));
39
                } 
40
        }
41

    
42
        public void endElement(String uri, String name, String qName) {
43
                if ("nodes".equalsIgnoreCase(name)) {
44
                        // do nothing
45
                } else if ("node".equalsIgnoreCase(name)) {
46
                        if (nodes != null) {
47
                                nodes.add(node);
48
                        }
49
                }
50
        }
51

    
52
        public void characters(char ch[], int start, int length) {
53
                Log.d("Rackspace-Cloud", "Characters:    \"");
54
                for (int i = start; i < start + length; i++) {
55
                        switch (ch[i]) {
56
                        case '\\':
57
                                Log.d("Rackspace-Cloud", "\\\\");
58
                                break;
59
                        case '"':
60
                                Log.d("Rackspace-Cloud", "\\\"");
61
                                break;
62
                        case '\n':
63
                                Log.d("Rackspace-Cloud", "\\n");
64
                                break;
65
                        case '\r':
66
                                Log.d("Rackspace-Cloud", "\\r");
67
                                break;
68
                        case '\t':
69
                                Log.d("Rackspace-Cloud", "\\t");
70
                                break;
71
                        default:
72
                                Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
73
                                break;
74
                        }
75
                }
76
                Log.d("Rackspace-Cloud", "\"\n");
77

    
78
                for (int i = start; i < (start + length); i++) {
79
                        currentData.append(ch[i]);
80
                }
81
        }
82

    
83
        public Node getNode() {
84
                return node;
85
        }
86

    
87
        public void setNode(Node node) {
88
                this.node = node;
89
        }
90

    
91
        public ArrayList<Node> getNodes() {
92
                return nodes;
93
        }
94

    
95
        public void setNodes(ArrayList<Node> nodes) {
96
                this.nodes = nodes;
97
        }
98

    
99
        public StringBuffer getCurrentData() {
100
                return currentData;
101
        }
102

    
103
        public void setCurrentData(StringBuffer currentData) {
104
                this.currentData = currentData;
105
        }
106
}