1 | |
---|
2 | package eu.clarin.cmdi.vlo.config; |
---|
3 | |
---|
4 | /** |
---|
5 | * Parameter configuration<br><br> |
---|
6 | * |
---|
7 | * Add parameters to an application by extending this class. The read method |
---|
8 | * assigns values to the new members by reading an XML definition from a file. |
---|
9 | * |
---|
10 | * Configuration is the process of reading the definitions and assigning values. |
---|
11 | * A configuration, the set of members extending this class, is the result of |
---|
12 | * this process.<br><br> |
---|
13 | * |
---|
14 | * Next to reading parameter values from a file, by means of the write method, |
---|
15 | * a ConfigFileParam class object can also reflect the assigned values back to |
---|
16 | * an XML file.<br><br> |
---|
17 | * |
---|
18 | * Note: {@literal maven} can also control parameters. This type of control |
---|
19 | * applies to the source level, and in that sense not visible to the parameter |
---|
20 | * mechanism defined here.<br><br> |
---|
21 | * |
---|
22 | * Checklist.<br><br> |
---|
23 | * |
---|
24 | * An extending class needs to implement the getFileName method. |
---|
25 | * |
---|
26 | * @author keeloo |
---|
27 | */ |
---|
28 | public abstract class ConfigFileParam { |
---|
29 | |
---|
30 | /** |
---|
31 | * Empty constructor |
---|
32 | */ |
---|
33 | public ConfigFileParam() { |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * Constraint on a deriving class<br><br> |
---|
38 | * |
---|
39 | * Ask a deriving class to implement a method that returns the name of the |
---|
40 | * file the persister object can read from or write to.<br><br> |
---|
41 | * |
---|
42 | * @return the name of an XML file |
---|
43 | */ |
---|
44 | public abstract String getFileName(); |
---|
45 | |
---|
46 | /** |
---|
47 | * Configure by reading from an XML file |
---|
48 | * |
---|
49 | * @param config the object whose annotated members will be assigned a value |
---|
50 | * in accordance with the definition read from the XML file. |
---|
51 | * |
---|
52 | * @return the object with values assigned to annotated members |
---|
53 | */ |
---|
54 | public static synchronized ConfigFileParam read(ConfigFileParam config) { |
---|
55 | |
---|
56 | ConfigFilePersister persister; |
---|
57 | // config itself might not reference a file name |
---|
58 | persister = new ConfigFilePersister(config, config.getFileName ()); |
---|
59 | |
---|
60 | // assign the members their values |
---|
61 | config = (ConfigFileParam) persister.ConfigFromFile(); |
---|
62 | return config; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Write a assigned values to an XML file. |
---|
67 | * |
---|
68 | * @param config the object whose annotated members and values will be |
---|
69 | * written to a file in the form of an XML definition. |
---|
70 | */ |
---|
71 | public static void write(ConfigFileParam config) { |
---|
72 | |
---|
73 | ConfigFilePersister persister; |
---|
74 | // config itself might not reference a file name |
---|
75 | persister = new ConfigFilePersister(config, config.getFileName ()); |
---|
76 | |
---|
77 | // create the definition |
---|
78 | persister.ConfigToFile(); |
---|
79 | } |
---|
80 | } |
---|