EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.vcloud.binders]

COVERAGE SUMMARY FOR SOURCE FILE [BindParamsToXmlPayload.java]

nameclass, %method, %block, %line, %
BindParamsToXmlPayload.java100% (1/1)75%  (3/4)85%  (64/75)81%  (13/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindParamsToXmlPayload100% (1/1)75%  (3/4)85%  (64/75)81%  (13/16)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/5)0%   (0/1)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)57%  (8/14)33%  (1/3)
BindParamsToXmlPayload (String, BindToStringPayload, String): void 100% (1/1)100% (12/12)100% (5/5)
generateXml (Map): String 100% (1/1)100% (44/44)100% (7/7)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.vcloud.binders;
20 
21import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
22 
23import java.util.Map;
24import java.util.Properties;
25import java.util.Map.Entry;
26 
27import javax.inject.Named;
28import javax.inject.Singleton;
29import javax.xml.parsers.FactoryConfigurationError;
30import javax.xml.parsers.ParserConfigurationException;
31import javax.xml.transform.TransformerException;
32 
33import org.jclouds.http.HttpRequest;
34import org.jclouds.rest.MapBinder;
35import org.jclouds.rest.binders.BindToStringPayload;
36 
37import com.google.inject.Inject;
38import com.jamesmurty.utils.XMLBuilder;
39 
40/**
41 * 
42 * @author Adrian Cole
43 * 
44 */
45@Singleton
46public class BindParamsToXmlPayload implements MapBinder {
47 
48   protected final String ns;
49   protected final BindToStringPayload stringBinder;
50   protected final String element;
51 
52   @Inject
53   public BindParamsToXmlPayload(String element, BindToStringPayload stringBinder,
54            @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
55      this.element = element;
56      this.ns = ns;
57      this.stringBinder = stringBinder;
58   }
59   @Override
60   public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
61      try {
62         return stringBinder.bindToRequest(request, generateXml(postParams));
63      } catch (Exception e) {
64         throw new RuntimeException(e);
65      }
66   }
67 
68   private String generateXml(Map<String, String> postParams) throws ParserConfigurationException,
69            FactoryConfigurationError, TransformerException {
70      XMLBuilder rootBuilder = XMLBuilder.create(element);
71      for (Entry<String, String> entry : postParams.entrySet())
72         rootBuilder.a(entry.getKey(), entry.getValue());
73      rootBuilder.a("xmlns", ns);
74      Properties outputProperties = new Properties();
75      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
76      return rootBuilder.asString(outputProperties);
77   }
78 
79   @Override
80   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
81      throw new IllegalArgumentException("incorrect usage");
82   }
83}

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