| 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.trmk.vcloud_0_8.xml; |
| 20 | |
| 21 | import static org.jclouds.util.SaxUtils.currentOrNull; |
| 22 | import static org.jclouds.util.SaxUtils.equalsOrSuffix; |
| 23 | |
| 24 | import java.net.URI; |
| 25 | |
| 26 | import org.jclouds.http.functions.ParseSax.HandlerWithResult; |
| 27 | import org.jclouds.trmk.vcloud_0_8.domain.NetworkExtendedInfo; |
| 28 | import org.jclouds.trmk.vcloud_0_8.domain.NetworkExtendedInfo.Type; |
| 29 | |
| 30 | /** |
| 31 | * @author Adrian Cole |
| 32 | */ |
| 33 | public class NetworkExtendedInfoHandler extends HandlerWithResult<NetworkExtendedInfo> { |
| 34 | |
| 35 | private StringBuilder currentText = new StringBuilder(); |
| 36 | |
| 37 | private String id; |
| 38 | private URI href; |
| 39 | private String name; |
| 40 | private String rnatAddress; |
| 41 | private String address; |
| 42 | private String broadcastAddress; |
| 43 | private String gatewayAddress; |
| 44 | private Type networkType; |
| 45 | private String vlan; |
| 46 | private String friendlyName; |
| 47 | |
| 48 | @Override |
| 49 | public NetworkExtendedInfo getResult() { |
| 50 | return new NetworkExtendedInfo(id, href, name, rnatAddress, address, broadcastAddress, gatewayAddress, |
| 51 | networkType, vlan, friendlyName); |
| 52 | } |
| 53 | |
| 54 | public void endElement(String uri, String name, String qName) { |
| 55 | String current = currentOrNull(currentText); |
| 56 | if (current != null) { |
| 57 | if (equalsOrSuffix(qName, "Href")) { |
| 58 | href = URI.create(current); |
| 59 | } else if (equalsOrSuffix(qName, "Id")) { |
| 60 | id = current; |
| 61 | } else if (equalsOrSuffix(qName, "Name")) { |
| 62 | this.name = current; |
| 63 | } else if (equalsOrSuffix(qName, "RnatAddress")) { |
| 64 | rnatAddress = current; |
| 65 | } else if (equalsOrSuffix(qName, "Address")) { |
| 66 | address = current; |
| 67 | } else if (equalsOrSuffix(qName, "BroadcastAddress")) { |
| 68 | broadcastAddress = current; |
| 69 | } else if (equalsOrSuffix(qName, "GatewayAddress")) { |
| 70 | gatewayAddress = current; |
| 71 | } else if (equalsOrSuffix(qName, "NetworkType")) { |
| 72 | networkType = NetworkExtendedInfo.Type.fromValue(current); |
| 73 | } else if (equalsOrSuffix(qName, "Vlan")) { |
| 74 | vlan = current; |
| 75 | } else if (equalsOrSuffix(qName, "FriendlyName")) { |
| 76 | friendlyName = current; |
| 77 | } |
| 78 | } |
| 79 | currentText = new StringBuilder(); |
| 80 | } |
| 81 | |
| 82 | public void characters(char ch[], int start, int length) { |
| 83 | currentText.append(ch, start, length); |
| 84 | } |
| 85 | |
| 86 | } |