| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.vcloud.xml.ovf; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import javax.inject.Inject; |
| 24 | |
| 25 | import org.jclouds.http.functions.ParseSax; |
| 26 | import org.jclouds.ovf.NetworkSection; |
| 27 | import org.jclouds.ovf.xml.NetworkSectionHandler; |
| 28 | import org.jclouds.util.SaxUtils; |
| 29 | import org.jclouds.vcloud.domain.ReferenceType; |
| 30 | import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; |
| 31 | import org.jclouds.vcloud.util.Utils; |
| 32 | import org.xml.sax.Attributes; |
| 33 | |
| 34 | /** |
| 35 | * @author Adrian Cole |
| 36 | */ |
| 37 | public class VCloudNetworkSectionHandler extends ParseSax.HandlerWithResult<VCloudNetworkSection> { |
| 38 | private final NetworkSectionHandler networkSectionHandler; |
| 39 | |
| 40 | @Inject |
| 41 | VCloudNetworkSectionHandler(NetworkSectionHandler networkSectionHandler) { |
| 42 | this.networkSectionHandler = networkSectionHandler; |
| 43 | } |
| 44 | |
| 45 | private ReferenceType net; |
| 46 | |
| 47 | public VCloudNetworkSection getResult() { |
| 48 | NetworkSection system = networkSectionHandler.getResult(); |
| 49 | return new VCloudNetworkSection(net.getType(), net.getHref(), system.getInfo(), system.getNetworks()); |
| 50 | } |
| 51 | |
| 52 | public void startElement(String uri, String localName, String qName, Attributes attrs) { |
| 53 | Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs); |
| 54 | if (qName.endsWith("NetworkSection")) { |
| 55 | this.net = Utils.newReferenceType(attributes); |
| 56 | } |
| 57 | networkSectionHandler.startElement(uri, localName, qName, attrs); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void endElement(String uri, String localName, String qName) { |
| 62 | networkSectionHandler.endElement(uri, localName, qName); |
| 63 | } |
| 64 | |
| 65 | public void characters(char ch[], int start, int length) { |
| 66 | networkSectionHandler.characters(ch, start, length); |
| 67 | } |
| 68 | |
| 69 | } |