|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| EnterpriseConfig.java | 87.5% | 85.7% | 75% | 83.8% |
|
||||||||||||||
| 1 | /** | |
| 2 | * JTRunner is free software; you can redistribute it and/or modify it under the | |
| 3 | * terms of the GNU General Public License as published by the Free Software | |
| 4 | * Foundation; either version 2, or (at your option) any later version. | |
| 5 | */ | |
| 6 | ||
| 7 | package jtr.config.enterprise; | |
| 8 | ||
| 9 | import java.io.Serializable; | |
| 10 | import java.util.*; | |
| 11 | ||
| 12 | import jtr.config.TestConfig; | |
| 13 | import org.apache.log4j.Logger; | |
| 14 | ||
| 15 | /** | |
| 16 | * An <code>EnterpriseConfig</code> provides the JTR framework with | |
| 17 | * information such as the properties needed to correctly perform the lookup of | |
| 18 | * enterprise resources. All these operations can be transparently performed by | |
| 19 | * the <code>ServiceLocator</code> provided implementation on behalf of the | |
| 20 | * <code>IRunner</code>s provided by the test developer.<br> | |
| 21 | * A single <code>TestConfig</code> is allowed to contain 0, 1 or more | |
| 22 | * <code>EnterpriseConfig</code>s, and each of them is required to expose a | |
| 23 | * unique name.<br> | |
| 24 | * An <code>EnterpriseConfig</code> consists of a set of | |
| 25 | * <code>EnterpriseProperty</code>. | |
| 26 | * | |
| 27 | * @author Francesco Russo (frusso@dev.java.net) | |
| 28 | * @version 4.0 | |
| 29 | * @since 1.0 | |
| 30 | * @see jtr.config.enterprise.EnterpriseProperty | |
| 31 | */ | |
| 32 | public class EnterpriseConfig implements Serializable { | |
| 33 | /** | |
| 34 | * Constructor. | |
| 35 | */ | |
| 36 | 2 | public EnterpriseConfig() { |
| 37 | 2 | properties = new Vector<EnterpriseProperty>(); |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * Sets the enterprise configuration's unique name. | |
| 42 | * | |
| 43 | * @param uniqueName | |
| 44 | * String | |
| 45 | */ | |
| 46 | 2 | public void setUniqueName(String uniqueName) { |
| 47 | 2 | this.uniqueName = uniqueName; |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Gets the enterprise configuration's unique name. | |
| 52 | * | |
| 53 | * @return String | |
| 54 | */ | |
| 55 | 14902 | public String getUniqueName() { |
| 56 | 14902 | return uniqueName; |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * Adds a new <code>EnterpriseProperty</code> to the current | |
| 61 | * <code>EnterpriseConfig</code> | |
| 62 | * | |
| 63 | * @param property | |
| 64 | * EnterpriseProperty | |
| 65 | */ | |
| 66 | 8 | public void addEnterpriseProperty(final EnterpriseProperty property) { |
| 67 | 8 | properties.add(property); |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Ties the current <code>EnterpriseConfig</code> with the given | |
| 72 | * <code>TestConfig</code> instance. | |
| 73 | * | |
| 74 | * @param parent | |
| 75 | * TestConfig | |
| 76 | */ | |
| 77 | 0 | public void setParent(TestConfig parent) { |
| 78 | 0 | this.parent = parent; |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Returns the <code>TestConfig</code> instance this | |
| 83 | * <code>EnterpriseConfig</code> is tied to. | |
| 84 | * | |
| 85 | * @return TestConfig | |
| 86 | */ | |
| 87 | 0 | public TestConfig getParent() { |
| 88 | 0 | return parent; |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * @see java.lang.Object#toString() | |
| 93 | */ | |
| 94 | 10024 | public String toString() { |
| 95 | 10027 | String res = "EnterpriseConfig {"; |
| 96 | 10031 | if (uniqueName != null) { |
| 97 | 10029 | res = res + "UniqueName: " + uniqueName + ", "; |
| 98 | } else { | |
| 99 | 0 | res = res + "UniqueName: null, "; |
| 100 | } | |
| 101 | 10034 | Iterator iter = properties.iterator(); |
| 102 | 10033 | while (iter.hasNext()) { |
| 103 | 30140 | res = res + iter.next().toString() + " "; |
| 104 | } | |
| 105 | 10038 | return res + "}"; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Provides an <code>Hashtable<String,String></code> representation of | |
| 110 | * the properties associated with this <i>enterprise configuration</i>. | |
| 111 | * @return Hashtable<String,String> | |
| 112 | */ | |
| 113 | 20036 | public Hashtable<String,String> toHashtable() { |
| 114 | // an EnterpriseConfig is a Vector<EnterpriseProperty>: each | |
| 115 | // EnterpriseProperty | |
| 116 | // has to become a key-value pair in the resulting Hashtable | |
| 117 | 20033 | if (ht == null) { |
| 118 | 4 | ht = new Hashtable<String,String>(); |
| 119 | 4 | Iterator iter = properties.iterator(); |
| 120 | 4 | while (iter.hasNext()) { |
| 121 | 16 | EnterpriseProperty ep = (EnterpriseProperty) iter.next(); |
| 122 | 16 | ht.put(ep.getName(), ep.getValue()); |
| 123 | } | |
| 124 | } | |
| 125 | 20039 | return ht; |
| 126 | } | |
| 127 | ||
| 128 | private String uniqueName; | |
| 129 | ||
| 130 | private Collection<EnterpriseProperty> properties; | |
| 131 | ||
| 132 | private Hashtable<String,String> ht; | |
| 133 | ||
| 134 | private TestConfig parent; | |
| 135 | ||
| 136 | private static Logger logger = Logger.getLogger(EnterpriseConfig.class); | |
| 137 | } |
|
||||||||||