Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2006 TopCoder Inc., All Rights Reserved. | |
3 | */ | |
4 | package com.topcoder.testframework; | |
5 | ||
6 | import org.apache.tools.ant.DynamicElement; | |
7 | ||
8 | import java.util.HashMap; | |
9 | import java.util.Map; | |
10 | ||
11 | ||
12 | /** | |
13 | * This class represents a "credentials" XML element to be used in the Ant build file. The credentials can include user | |
14 | * name, password and other information needed to authenticate to the server. A particular Server implementation | |
15 | * should require the specific credentials. This element represents some kind of a property map, each property is | |
16 | * described by one nested element. The name of nested element represents the property key, the "value" attribute - | |
17 | * property value. | |
18 | * <p/> | |
19 | * <p>Example of the element:<p> | |
20 | * <pre> | |
21 | * <credentials> | |
22 | * <user_name value="topcoder" /> | |
23 | * <password value="some_password" /> | |
24 | * <some_other_property="some_value"/> | |
25 | * </credentials> | |
26 | * </pre> | |
27 | * <p/> | |
28 | * This class is mutable, i.e. not thread-safe. | |
29 | * | |
30 | * @author real_vg, TCSDEVELOPER | |
31 | * @version 1.0 | |
32 | */ | |
33 | public class CredentialsElement implements DynamicElement { | |
34 | ||
35 | /** | |
36 | * Stores the property map represented by the "credentials" element. Keys are String instances, values are also | |
37 | * String instances. They are set with call to the {@link CredentialProperty#setValue()}. | |
38 | */ | |
39 | 14 | private Map propertyMap = new HashMap(); |
40 | ||
41 | /** | |
42 | * Creates a CredentialsElement instance. | |
43 | */ | |
44 | 14 | public CredentialsElement() { |
45 | //this constructor is intentionally empty | |
46 | 14 | } |
47 | ||
48 | /** | |
49 | * This method creates a nested element with a specified name. Nested elements are of type {@link | |
50 | * CredentialProperty}. | |
51 | * | |
52 | * @param name the name of nested element to create | |
53 | * | |
54 | * @return the created CredentialProperty instance | |
55 | * | |
56 | * @throws org.apache.tools.ant.BuildException | |
57 | * when fails to create nested element | |
58 | * @throws IllegalArgumentException if name is <tt>null</tt> or empty (trim'd) string | |
59 | */ | |
60 | public Object createDynamicElement(final String name) { | |
61 | 4 | if (name == null) { |
62 | 1 | throw new IllegalArgumentException("The parameter named [name] was null."); |
63 | } | |
64 | 3 | if (name.trim().length() == 0) { |
65 | 1 | throw new IllegalArgumentException("The parameter named [name] was an empty String."); |
66 | } | |
67 | ||
68 | 2 | return new CredentialProperty(name, getPropertyMap()); |
69 | } | |
70 | ||
71 | /** | |
72 | * This method returns the property map represented by the <tt>credentials</tt> element. | |
73 | * | |
74 | * @return the property map represented by the "credentials" element, which is not a disconnected copy, as proper | |
75 | * usage of the map is expected | |
76 | */ | |
77 | public Map getPropertyMap() { | |
78 | 6 | return propertyMap; |
79 | } | |
80 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |