1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.cim.xml;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 import static org.jclouds.util.SaxUtils.currentOrNull;
41 import static org.jclouds.util.SaxUtils.equalsOrSuffix;
42
43 import org.jclouds.cim.ResourceAllocationSettingData;
44 import org.jclouds.cim.ResourceAllocationSettingData.ConsumerVisibility;
45 import org.jclouds.cim.ResourceAllocationSettingData.MappingBehavior;
46 import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
47 import org.jclouds.http.functions.ParseSax;
48 import org.xml.sax.Attributes;
49
50
51
52
53 public class ResourceAllocationSettingDataHandler extends ParseSax.HandlerWithResult<ResourceAllocationSettingData> {
54 protected StringBuilder currentText = new StringBuilder();
55
56 protected ResourceAllocationSettingData.Builder builder = ResourceAllocationSettingData.builder();
57
58 public ResourceAllocationSettingData getResult() {
59 try {
60 return builder.build();
61 } finally {
62 builder = ResourceAllocationSettingData.builder();
63 }
64 }
65
66 @Override
67 public void startElement(String uri, String localName, String qName, Attributes attrs) {
68 }
69
70 @Override
71 public void endElement(String uri, String localName, String qName) {
72 String current = currentOrNull(currentText);
73 if (current != null) {
74 if (equalsOrSuffix(qName, "ElementName")) {
75 builder.elementName(current);
76 } else if (equalsOrSuffix(qName, "InstanceID")) {
77 builder.instanceID(current);
78 } else if (equalsOrSuffix(qName, "Caption")) {
79 builder.caption(current);
80 } else if (equalsOrSuffix(qName, "Description")) {
81 builder.description(current);
82 } else if (equalsOrSuffix(qName, "Address")) {
83 builder.address(current);
84 } else if (equalsOrSuffix(qName, "AddressOnParent")) {
85 builder.addressOnParent(current);
86 } else if (equalsOrSuffix(qName, "AllocationUnits")) {
87 builder.allocationUnits(current);
88 } else if (equalsOrSuffix(qName, "AutomaticAllocation")) {
89 builder.automaticAllocation(new Boolean(current));
90 } else if (equalsOrSuffix(qName, "AutomaticDeallocation")) {
91 builder.automaticDeallocation(new Boolean(current));
92 } else if (equalsOrSuffix(qName, "ConsumerVisibility")) {
93 builder.consumerVisibility(ConsumerVisibility.fromValue(current));
94 } else if (equalsOrSuffix(qName, "Limit")) {
95 builder.limit(new Long(current));
96 } else if (equalsOrSuffix(qName, "MappingBehavior")) {
97 builder.mappingBehavior(MappingBehavior.fromValue(current));
98 } else if (equalsOrSuffix(qName, "OtherResourceType")) {
99 builder.otherResourceType(current);
100 } else if (equalsOrSuffix(qName, "Parent")) {
101 builder.parent(current);
102 } else if (equalsOrSuffix(qName, "PoolID")) {
103 builder.poolID(current);
104 } else if (equalsOrSuffix(qName, "Reservation")) {
105 builder.reservation(new Long(current));
106 } else if (equalsOrSuffix(qName, "ResourceSubType")) {
107 builder.resourceSubType(current);
108 } else if (equalsOrSuffix(qName, "ResourceType")) {
109 builder.resourceType(ResourceType.fromValue(current));
110 } else if (equalsOrSuffix(qName, "VirtualQuantity")) {
111 builder.virtualQuantity(new Long(current));
112 } else if (equalsOrSuffix(qName, "VirtualQuantityUnits")) {
113 builder.virtualQuantityUnits(current);
114 } else if (equalsOrSuffix(qName, "Weight")) {
115 builder.weight(new Integer(current));
116 } else if (equalsOrSuffix(qName, "Connection")) {
117 builder.connection(current);
118 } else if (equalsOrSuffix(qName, "HostResource")) {
119 builder.hostResource(current);
120 }
121 }
122 currentText = new StringBuilder();
123 }
124
125 public void characters(char ch[], int start, int length) {
126 currentText.append(ch, start, length);
127 }
128
129 }