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.parsers.ConfigEntryParser;
8 import org.naftulin.configmgr.parsers.MasterRecordParser;
9 import org.apache.commons.lang.builder.ToStringBuilder;
10
11 /***
12 * Parses config.xml file: properties file, log4j xml or log4j properties.
13 * Once a master record is created, parsers are called for each of the entries
14 * to be parsed and stored in config manager. Entry is similar to config manager
15 * entry, yet there is no content (since the entry was not parsed yet).
16 *
17 * @author Henry Naftulin
18 * @since 1.0
19 */
20 public class MasterRecordImpl extends AbstractRecordImpl {
21 private static final ConfigEntryParser PARSER = new MasterRecordParser();
22 private boolean jmx = true;
23 private final List<AbstractRecordImpl> records = new LinkedList<AbstractRecordImpl>();
24
25 /***
26 * Constructs a record without specifying the key or file name.
27 */
28 public MasterRecordImpl() {
29 super();
30 }
31
32 /***
33 * Constructs a record with the key and file name specified.
34 * @param key the key associated with the record.
35 * @param fileName the file name associated with the record.
36 */
37 public MasterRecordImpl(final String key, final String fileName) {
38 super(key, fileName);
39 }
40
41 /***
42 * Returns Jmx setting for configuration manager. By defaul the jmx
43 * setting is true, which means that configuration manager will try to
44 * connect to JMX MBean server.
45 * @return returns Jmx setting for configuration manager.
46 */
47 public boolean isJmx() {
48 return jmx;
49 }
50
51 /***
52 * Sets Jmx setting for configuration manager. When Jmx
53 * setting equals true, configuration manager will try to
54 * connect to JMX MBean server.
55 * @param jmx jmx setting
56 */
57 public void setJmx(boolean jmx) {
58 this.jmx = jmx;
59 }
60
61 /***
62 * Adds a record to the list of records to be processed. Mirrors the
63 * master file which consists of configuration records.
64 * @param record the record to be processed, read from the master configuration file
65 */
66 public void addRecord(final AbstractRecordImpl record) {
67 records.add(record);
68 }
69
70 /***
71 * Returns the unmodifiable list of {@link AbstractRecordImpl records} from the cofiguration file.
72 * @return a list of {@link AbstractRecordImpl records} from the cofiguration file.
73 */
74 public List<AbstractRecordImpl> getRecords() {
75 return Collections.unmodifiableList(records);
76 }
77
78 /***
79 * Returns master record parser. The master record is
80 * processed by configuration manager with a special parser; and is
81 * not re-parsed when transofrmed to configuration manager entry.
82 * @return Returns master record parser.
83 */
84 public ConfigEntryParser getParser() {
85 return PARSER;
86 }
87
88 /***
89 * Returns the string representation of the master record.
90 * @return the string representation of the master record.
91 */
92 public String toString() {
93 return new ToStringBuilder(this)
94 .append("key", this.getKey())
95 .append("jmx", this.isJmx())
96 .append("parser", this.getParser())
97 .append("fileName",this.getFileName())
98 .append("records", this.records).toString();
99 }
100
101 }