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

COVERAGE SUMMARY FOR SOURCE FILE [BindMemoryToXmlPayload.java]

nameclass, %method, %block, %line, %
BindMemoryToXmlPayload.java100% (1/1)100% (2/2)96%  (107/111)91%  (20/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindMemoryToXmlPayload100% (1/1)100% (2/2)96%  (107/111)91%  (20/22)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)96%  (98/102)89%  (16/18)
BindMemoryToXmlPayload (BindToStringPayload, String, String): void 100% (1/1)100% (9/9)100% (4/4)

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.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
32import org.jclouds.http.HttpRequest;
33import org.jclouds.rest.binders.BindToStringPayload;
34 
35import com.google.common.base.Throwables;
36import com.google.inject.Inject;
37import com.jamesmurty.utils.XMLBuilder;
38 
39/**
40 * 
41 * @author Adrian Cole
42 * 
43 */
44@Singleton
45public class BindMemoryToXmlPayload extends BindToStringPayload {
46   protected final String ns;
47   protected final String schema;
48 
49   @Inject
50   public BindMemoryToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
51         @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
52      this.ns = ns;
53      this.schema = schema;
54   }
55 
56   private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
57 
58   @Override
59   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
60      checkArgument(checkNotNull(payload, "memoryInMB") instanceof Integer, "this binder is only valid for Integers!");
61      Integer memoryInMB = Integer.class.cast(payload);
62      XMLBuilder cpuItem;
63      try {
64         cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
65         cpuItem.e("rasd:AllocationUnits").t("byte * 2^20");
66         cpuItem.e("rasd:Description").t("Memory Size");
67         cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory");
68         cpuItem.e("rasd:InstanceID").t("5");
69         cpuItem.e("rasd:Reservation").t("0");
70         cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
71         cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString());
72         cpuItem.e("rasd:Weight").t("0");
73         Properties outputProperties = new Properties();
74         outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
75         request = super.bindToRequest(request, cpuItem.asString(outputProperties));
76      } catch (Exception e) {
77         Throwables.propagate(e);
78      }
79      return request;
80   }
81 
82}

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