| 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.vcloud.terremark.xml; |
| 20 | |
| 21 | import static org.jclouds.util.SaxUtils.cleanseAttributes; |
| 22 | |
| 23 | import java.util.Map; |
| 24 | |
| 25 | import javax.inject.Inject; |
| 26 | |
| 27 | import org.jclouds.vcloud.VCloudExpressMediaType; |
| 28 | import org.jclouds.vcloud.domain.ReferenceType; |
| 29 | import org.jclouds.vcloud.domain.VDC; |
| 30 | import org.jclouds.vcloud.terremark.domain.TerremarkVDC; |
| 31 | import org.jclouds.vcloud.terremark.domain.internal.TerremarkVDCImpl; |
| 32 | import org.jclouds.vcloud.util.Utils; |
| 33 | import org.jclouds.vcloud.xml.TaskHandler; |
| 34 | import org.jclouds.vcloud.xml.VDCHandler; |
| 35 | import org.xml.sax.Attributes; |
| 36 | import org.xml.sax.SAXException; |
| 37 | |
| 38 | /** |
| 39 | * @author Adrian Cole |
| 40 | */ |
| 41 | public class TerremarkVDCHandler extends VDCHandler { |
| 42 | |
| 43 | @Inject |
| 44 | public TerremarkVDCHandler(TaskHandler taskHandler) { |
| 45 | super(taskHandler); |
| 46 | } |
| 47 | |
| 48 | private ReferenceType catalog; |
| 49 | private ReferenceType publicIps; |
| 50 | private ReferenceType internetServices; |
| 51 | |
| 52 | public TerremarkVDC getResult() { |
| 53 | VDC vDC = super.getResult(); |
| 54 | return new TerremarkVDCImpl(vDC.getName(), vDC.getType(), vDC.getHref(), status, org, description, tasks, |
| 55 | allocationModel, storageCapacity, cpuCapacity, memoryCapacity, resourceEntities, availableNetworks, |
| 56 | nicQuota, networkQuota, vmQuota, isEnabled, catalog, publicIps, internetServices); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { |
| 61 | Map<String, String> attributes = cleanseAttributes(attrs); |
| 62 | super.startElement(uri, localName, qName, attrs); |
| 63 | if (qName.equals("Link")) { |
| 64 | String name = attributes.get("name"); |
| 65 | if (name.equals("Internet Services")) { |
| 66 | internetServices = Utils.newReferenceType(attributes); |
| 67 | } else if (name.equals("Public IPs")) { |
| 68 | publicIps = Utils.newReferenceType(attributes); |
| 69 | } else { |
| 70 | String type = attributes.get("type"); |
| 71 | if (type.equals(VCloudExpressMediaType.CATALOG_XML)) { |
| 72 | catalog = Utils.newReferenceType(attributes); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | } |