View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }