1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.database.data;
20
21 import net.sf.magicproject.database.Proxy;
22 import net.sf.magicproject.database.propertyconfig.PropertyConfig;
23
24 /***
25 * Represents a translatable data. A data contains a key and a value. The key is
26 * always translated, but the value may not.
27 *
28 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
29 * @since 0.90
30 */
31 public abstract class TranslatableData {
32
33 /***
34 * The property configuration of this data.
35 */
36 protected PropertyConfig propertyConfig;
37
38 /***
39 * Default public constructor.
40 *
41 * @param propertyConfig
42 * the property configuration of this data to use
43 */
44 public TranslatableData(PropertyConfig propertyConfig) {
45 this.propertyConfig = propertyConfig;
46 }
47
48 /***
49 * Returns the translated property name. The translation is done only during
50 * the first call.
51 *
52 * @return the translated property name
53 */
54 public final String getTranslatedPropertyName() {
55 return propertyConfig.getTranslatedName();
56 }
57
58 /***
59 * Returns the translated value. The translation is done only during the first
60 * call.
61 *
62 * @param proxy
63 * is the proxy this data come from. Is used to translate from
64 * private-proxy to public-tbs value.
65 * @return the translated value
66 */
67 public abstract String getTranslatedValue(Proxy proxy);
68
69 /***
70 * The key.
71 *
72 * @return the key of this data
73 */
74 public final String getPropertyName() {
75 return propertyConfig.getName();
76 }
77
78 /***
79 * The value.
80 *
81 * @return the value associated to the key of this data
82 */
83 public abstract String getValue();
84
85 @Override
86 public String toString() {
87 return getPropertyName() + "='" + getTranslatedValue(null) + "'";
88 }
89 }