| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.cim.xml; |
| 20 | |
| 21 | /** |
| 22 | * |
| 23 | * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 24 | * |
| 25 | * ==================================================================== |
| 26 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 27 | * you may not use this file except in compliance with the License. |
| 28 | * You may obtain a copy of the License at |
| 29 | * |
| 30 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 31 | * |
| 32 | * Unless required by applicable law or agreed to in writing, software |
| 33 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 34 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 35 | * See the License for the specific language governing permissions and |
| 36 | * limitations under the License. |
| 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 | * @author Adrian Cole |
| 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 | } |