Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ExternalRecordImpl |
|
| 0.0;0 |
1 | package org.naftulin.configmgr.content; | |
2 | ||
3 | import java.util.Collections; | |
4 | import java.util.LinkedList; | |
5 | import java.util.List; | |
6 | ||
7 | import org.naftulin.configmgr.ConfigurationManagerException; | |
8 | import org.naftulin.configmgr.parsers.ConfigEntryParser; | |
9 | import org.naftulin.configmgr.parsers.ExternalConfigurationParserImpl; | |
10 | ||
11 | /** | |
12 | * Represents an external entry, with it's key, name-value pairs and parser class. | |
13 | * Intended to mirror master configuration rules for external configuration. | |
14 | * The external configuraton xml is: | |
15 | * <pre> | |
16 | * <external key="the key" configEntryAdatorClass="the fully qualified parser class"> | |
17 | <param name="key1" value="value1" /> | |
18 | ..... | |
19 | <param name="keyn" value="valuen" /> | |
20 | </external> | |
21 | * </pre> | |
22 | * where <code>configEntryParserClass</code> is a class implementing {@link org.naftulin.configmgr.parsers.ExternalRecordAdapter | |
23 | * ExternalRecordAdapter} interface. | |
24 | * @author Henry Henry | |
25 | * @since 1.0 | |
26 | */ | |
27 | 20 | public class ExternalRecordImpl extends AbstractRecordImpl { |
28 | 10 | private final List<NameValuePairImpl> nameValuePairs = new LinkedList<NameValuePairImpl>(); |
29 | private String configEntryAdaptorClass; | |
30 | 10 | private final ExternalConfigurationParserImpl parser = new ExternalConfigurationParserImpl(); |
31 | ||
32 | /** | |
33 | * Adds a name-value pair as it is read from the master configuration. | |
34 | * @param nameValuePair the name value pair. | |
35 | */ | |
36 | public void addNameValuePair(final NameValuePairImpl nameValuePair) { | |
37 | 20 | nameValuePairs.add(nameValuePair); |
38 | 20 | } |
39 | ||
40 | /** | |
41 | * Sets the configuration entry adapter class. This class will handle | |
42 | * adapting the loading and reloading of the configurations by calling | |
43 | * load and reload methods on the original, exteral interface. | |
44 | * @param adaptor the fully qualified name of the adaptor implementation class. | |
45 | */ | |
46 | public void setConfigEntryAdaptorClass(final String adaptor) { | |
47 | 10 | configEntryAdaptorClass = adaptor; |
48 | 10 | } |
49 | ||
50 | /** | |
51 | * Returns an instance of {@link ExternalConfigurationParserImpl parser} that can parse the file to extract the configuration. | |
52 | * @return the parser that can parse the file to extract the configuration. | |
53 | * @throws ConfigurationManagerException if an error occured while instantiating the parser. | |
54 | */ | |
55 | public ConfigEntryParser getParser() throws ConfigurationManagerException { | |
56 | 0 | parser.setNameValuePairs(Collections.unmodifiableList(nameValuePairs)); |
57 | 0 | parser.setExternalRecordAdapterClass(configEntryAdaptorClass); |
58 | 0 | return parser; |
59 | } | |
60 | } |