View Javadoc

1   package org.naftulin.configmgr.content;
2   
3   import org.apache.commons.lang.builder.ToStringBuilder;
4   import org.naftulin.configmgr.ConfigurationManagerException;
5   import org.naftulin.configmgr.parsers.ConfigEntryParser;
6   
7   /***
8    * Abstract Record implementation combines the most common attributes of the record: file name and key.
9    * A record is described in the master configuraion: current implementations include
10   * property record, log4j xml or property and external record, all sub-classed from the
11   * abstract record.
12   * 
13   * @author Henry Naftulin
14   * @since 1.0
15   */
16  public abstract class AbstractRecordImpl {
17  	private String fileName;
18  	private String key;
19  
20  	/***
21  	 * If configuration is file-base, we need to get the file to be parsed.
22  	 * Most of the configurations are file-based.
23  	 * @return true.
24  	 */
25  	public boolean isGetUrlForFile() {
26  		return true;
27  	}
28  
29  
30  	/***
31  	 * Constructs a record without specifying the key or file name.
32  	 */
33  	public AbstractRecordImpl() {		
34  	}
35  	
36  	/***
37  	 * Constructs a record with the key and file name specified.
38  	 * @param key the key associated with the record.
39  	 * @param fileName the file name associated with the record.
40  	 */
41  	public AbstractRecordImpl(String key, String fileName) {
42  		this.fileName = fileName;
43  		this.key = key;
44  	}
45  	
46  	/***
47  	 * Returns the file name associated with the record.
48  	 * @return the file name associated with the record.
49  	 */
50  	public String getFileName() {
51  		return fileName;
52  	}
53  	
54  	/***
55  	 * Sets the file name for the reoord.
56  	 * @param fileName the file name for the record.
57  	 */
58  	public void setFileName(final String fileName) {
59  		this.fileName = fileName;
60  	}
61  	
62  	/***
63  	 * Returns the key associated with the record. 
64  	 * @return the key associated with the record.
65  	 */
66  	public String getKey() {
67  		return key;
68  	}
69  	
70  	/***
71  	 * Sets the key associated with the record.
72  	 * @param key the key associated with the record.
73  	 */
74  	public void setKey(final String key) {
75  		this.key = key;
76  	}
77  	
78  	/***
79  	 * Returns the parser that can parse the file to extract the configuration.
80  	 * @return the parser that can parse the file to extract the configuration.
81  	 * @throws ConfigurationManagerException if an error occured while instantiating the parser.
82  	 */
83  	public abstract ConfigEntryParser getParser() throws ConfigurationManagerException;
84  	/***
85  	 * Returns the string representation of the record.
86  	 * @return the string representation of the record.
87  	 */
88  	public String toString() {
89  		return new ToStringBuilder(this).append("key", this.key).append(
90  				"fileName", this.fileName).toString();
91  	}
92  }