EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.vcloud.binders]

COVERAGE SUMMARY FOR SOURCE FILE [BindNetworkConnectionSectionToXmlPayload.java]

nameclass, %method, %block, %line, %
BindNetworkConnectionSectionToXmlPayload.java100% (1/1)100% (2/2)76%  (151/200)79%  (27/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindNetworkConnectionSectionToXmlPayload100% (1/1)100% (2/2)76%  (151/200)79%  (27/34)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)74%  (139/188)76%  (22/29)
BindNetworkConnectionSectionToXmlPayload (BindToStringPayload, String, String... 100% (1/1)100% (12/12)100% (5/5)

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 */
19package org.jclouds.vcloud.binders;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
24import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
25 
26import java.util.Properties;
27 
28import javax.annotation.Resource;
29import javax.inject.Named;
30import javax.inject.Singleton;
31 
32import org.jclouds.http.HttpRequest;
33import org.jclouds.logging.Logger;
34import org.jclouds.rest.binders.BindToStringPayload;
35import org.jclouds.vcloud.domain.NetworkConnection;
36import org.jclouds.vcloud.domain.NetworkConnectionSection;
37 
38import com.google.common.base.Throwables;
39import com.google.inject.Inject;
40import com.jamesmurty.utils.XMLBuilder;
41 
42/**
43 * 
44 * @author Adrian Cole
45 * 
46 */
47@Singleton
48public class BindNetworkConnectionSectionToXmlPayload extends BindToStringPayload {
49   @Resource
50   protected Logger logger = Logger.NULL;
51 
52   protected final String ns;
53   protected final String schema;
54 
55   @Inject
56   public BindNetworkConnectionSectionToXmlPayload(BindToStringPayload stringBinder,
57         @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
58      this.ns = ns;
59      this.schema = schema;
60   }
61 
62   @Override
63   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
64      checkArgument(checkNotNull(payload, "NetworkConnectionSection") instanceof NetworkConnectionSection,
65            "this binder is only valid for NetworkConnectionSection!");
66      NetworkConnectionSection net = NetworkConnectionSection.class.cast(payload);
67      XMLBuilder networkConnectionSection;
68      try {
69         networkConnectionSection = XMLBuilder.create("NetworkConnectionSection").a("xmlns", ns)
70               .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("type", net.getType())
71               .a("href", net.getHref().toASCIIString()).a("ovf:required", "false");
72         networkConnectionSection.e("ovf:Info").t(net.getInfo());
73 
74         if (net.getPrimaryNetworkConnectionIndex() != null)
75            networkConnectionSection.e("PrimaryNetworkConnectionIndex").t(
76                  net.getPrimaryNetworkConnectionIndex().toString());
77         for (NetworkConnection networkConnection : net.getConnections()) {
78            XMLBuilder networkConnectionSectionChild = networkConnectionSection.e("NetworkConnection").a("network",
79                  networkConnection.getNetwork());
80            networkConnectionSectionChild.e("NetworkConnectionIndex").t(
81                  networkConnection.getNetworkConnectionIndex() + "");
82            if (networkConnection.getExternalIpAddress() != null)
83               networkConnectionSectionChild.e("ExternalIpAddress").t(networkConnection.getExternalIpAddress());
84            if (networkConnection.getIpAddress() != null)
85               networkConnectionSectionChild.e("IpAddress").t(networkConnection.getIpAddress());
86            networkConnectionSectionChild.e("IsConnected").t(networkConnection.isConnected() + "");
87            if (networkConnection.getMACAddress() != null)
88               networkConnectionSectionChild.e("MACAddress").t(networkConnection.getMACAddress());
89            if (networkConnection.getIpAddressAllocationMode() != null)
90               networkConnectionSectionChild.e("IpAddressAllocationMode").t(
91                     networkConnection.getIpAddressAllocationMode().toString());
92         }
93 
94         if (net.getEdit() != null)
95            networkConnectionSection.e("Link").a("rel", "edit").a("type", net.getType())
96                  .a("href", net.getHref().toASCIIString());
97 
98         Properties outputProperties = new Properties();
99         outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
100         request = super.bindToRequest(request, networkConnectionSection.asString(outputProperties));
101         request.getPayload().getContentMetadata().setContentType(net.getType());
102      } catch (Exception e) {
103         Throwables.propagate(e);
104      }
105      return request;
106   }
107 
108}

[all classes][org.jclouds.vcloud.binders]
EMMA 2.0.5312 (C) Vladimir Roubtsov