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

COVERAGE SUMMARY FOR SOURCE FILE [BindNodeConfigurationToXmlPayload.java]

nameclass, %method, %block, %line, %
BindNodeConfigurationToXmlPayload.java100% (1/1)75%  (3/4)88%  (82/93)76%  (13/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindNodeConfigurationToXmlPayload100% (1/1)75%  (3/4)88%  (82/93)76%  (13/17)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/5)0%   (0/1)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)57%  (8/14)25%  (1/4)
BindNodeConfigurationToXmlPayload (String, BindToStringPayload): void 100% (1/1)100% (9/9)100% (4/4)
generateXml (Map): String 100% (1/1)100% (65/65)100% (8/8)

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.trmk.vcloud_0_8.binders;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
23 
24import java.util.Map;
25import java.util.Properties;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30import javax.xml.parsers.FactoryConfigurationError;
31import javax.xml.parsers.ParserConfigurationException;
32import javax.xml.transform.TransformerException;
33 
34import org.jclouds.http.HttpRequest;
35import org.jclouds.rest.MapBinder;
36import org.jclouds.rest.binders.BindToStringPayload;
37 
38import com.google.common.base.Throwables;
39import com.jamesmurty.utils.XMLBuilder;
40 
41/**
42 * 
43 * @author Adrian Cole
44 * 
45 */
46@Singleton
47public class BindNodeConfigurationToXmlPayload implements MapBinder {
48 
49   private final String ns;
50   private final BindToStringPayload stringBinder;
51 
52   @Inject
53   BindNodeConfigurationToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns, BindToStringPayload stringBinder) {
54      this.ns = ns;
55      this.stringBinder = stringBinder;
56   }
57 
58   protected String generateXml(Map<String, String> postParams) throws ParserConfigurationException,
59         FactoryConfigurationError, TransformerException {
60      XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", ns).a("xmlns:xsi",
61            "http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
62      rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name"));
63      rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled"));
64      if (postParams.containsKey("description") && postParams.get("description") != null)
65         rootBuilder.e("Description").t(postParams.get("description"));
66      Properties outputProperties = new Properties();
67      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
68      return rootBuilder.asString(outputProperties);
69   }
70 
71   @Override
72   public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
73      try {
74         return stringBinder.bindToRequest(request, generateXml(postParams));
75      } catch (Exception e) {
76         Throwables.propagate(e);
77      }
78      return request;
79   }
80 
81   @Override
82   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
83      throw new IllegalArgumentException("this is a map binder");
84   }
85}

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