@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkArgument(checkNotNull(payload, "NetworkConnectionSection") instanceof NetworkConnectionSection,
"this binder is only valid for NetworkConnectionSection!");
NetworkConnectionSection net = NetworkConnectionSection.class.cast(payload);
XMLBuilder networkConnectionSection;
try {
networkConnectionSection = XMLBuilder.create("NetworkConnectionSection").a("xmlns", ns)
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("type", net.getType())
.a("href", net.getHref().toASCIIString()).a("ovf:required", "false");
networkConnectionSection.e("ovf:Info").t(net.getInfo());
if (net.getPrimaryNetworkConnectionIndex() != null)
networkConnectionSection.e("PrimaryNetworkConnectionIndex").t(
net.getPrimaryNetworkConnectionIndex().toString());
for (NetworkConnection networkConnection : net.getConnections()) {
XMLBuilder networkConnectionSectionChild = networkConnectionSection.e("NetworkConnection").a("network",
networkConnection.getNetwork());
networkConnectionSectionChild.e("NetworkConnectionIndex").t(
networkConnection.getNetworkConnectionIndex() + "");
if (networkConnection.getExternalIpAddress() != null)
networkConnectionSectionChild.e("ExternalIpAddress").t(networkConnection.getExternalIpAddress());
if (networkConnection.getIpAddress() != null)
networkConnectionSectionChild.e("IpAddress").t(networkConnection.getIpAddress());
networkConnectionSectionChild.e("IsConnected").t(networkConnection.isConnected() + "");
if (networkConnection.getMACAddress() != null)
networkConnectionSectionChild.e("MACAddress").t(networkConnection.getMACAddress());
if (networkConnection.getIpAddressAllocationMode() != null)
networkConnectionSectionChild.e("IpAddressAllocationMode").t(
networkConnection.getIpAddressAllocationMode().toString());
}
if (net.getEdit() != null)
networkConnectionSection.e("Link").a("rel", "edit").a("type", net.getType())
.a("href", net.getHref().toASCIIString());
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
request = super.bindToRequest(request, networkConnectionSection.asString(outputProperties));
request.getPayload().getContentMetadata().setContentType(net.getType());
} catch (Exception e) {
Throwables.propagate(e);
}
return request;
}