KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > core > AbstractDescriptor


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.core;
12
13 import java.util.*;
14 import org.mmbase.bridge.Descriptor;
15 import org.mmbase.util.LocalizedString;
16 import org.mmbase.util.logging.*;
17
18 /**
19  * @javadoc
20  *
21  * @author Pierre van Rooden
22  * @since MMBase-1.8
23  * @version $Id: AbstractDescriptor.java,v 1.8.2.1 2006/10/12 11:35:59 pierre Exp $
24  */

25
26 abstract public class AbstractDescriptor implements Descriptor, Cloneable JavaDoc {
27
28     private static final Logger log = Logging.getLoggerInstance(AbstractDescriptor.class);
29
30     protected String JavaDoc key;
31     protected LocalizedString description;
32     protected LocalizedString guiName;
33
34     protected AbstractDescriptor() {}
35
36     /**
37      * Create a data type object
38      * @param name the name of the data type
39      */

40     protected AbstractDescriptor(String JavaDoc name) {
41         key = name;
42         setGUIName(name);
43         setDescription("");
44     }
45
46     /**
47      * Create a data type object
48      * @param name the name of the data type
49      * @param descriptor
50      */

51     protected AbstractDescriptor(String JavaDoc name, Descriptor descriptor, boolean cloneDataForRewrite) {
52         key = name;
53         if (cloneDataForRewrite) {
54             description = (LocalizedString)descriptor.getLocalizedDescription().clone();
55             guiName = (LocalizedString)descriptor.getLocalizedGUIName().clone();
56         } else {
57             description = (LocalizedString)descriptor.getLocalizedDescription();
58             guiName = (LocalizedString)descriptor.getLocalizedGUIName();
59         }
60     }
61
62     protected AbstractDescriptor(String JavaDoc name, Descriptor descriptor) {
63         this(name, descriptor, true);
64     }
65
66
67     /**
68      * The locale wihch must be used if no locale is specified . Returns <code>null</code> for the
69      * defaul of this. This method can be overriden if another more logical default is
70      * available. E.g. in BasicField, where the locale of the current cloud is returned here.
71      * @since MMBase-1.8.1
72      */

73     protected Locale getDefaultLocale() {
74         return null;
75     }
76
77     /**
78      * Returns the name or 'key' of this data type.
79      * @return the name as a String
80      */

81     public String JavaDoc getName() {
82         return key;
83     }
84
85     public String JavaDoc getDescription(Locale locale) {
86         if (description == null) description = new LocalizedString(key);
87         return description.get(locale == null ? getDefaultLocale() : locale);
88     }
89
90     public String JavaDoc getDescription() {
91         return getDescription(getDefaultLocale());
92     }
93
94     public LocalizedString getLocalizedDescription() {
95         return description;
96     }
97
98     protected void setLocalizedDescription(LocalizedString description) {
99         this.description = description;
100     }
101
102     public void setDescription(String JavaDoc desc, Locale locale) {
103         if (description == null) description = new LocalizedString(key);
104         description.set(desc, locale);
105     }
106
107     public void setDescription(String JavaDoc desc) {
108         setDescription(desc, getDefaultLocale());
109     }
110
111
112     /**
113      * Retrieve the GUI name of the field depending on specified langauge.
114      * If the language is not available, the "en" value is returned instead.
115      * If that one is unavailable the internal fieldname is returned.
116      * @return the GUI Name
117      */

118     public String JavaDoc getGUIName(Locale locale) {
119         if (guiName == null) guiName = new LocalizedString(key);
120         return guiName.get(locale == null ? getDefaultLocale() : locale);
121     }
122
123     /**
124      * Retrieve the GUI name of the field.
125      * If possible, the "en" value is returned.
126      * If that one is unavailable the internal fieldname is returned.
127      * @return the GUI Name
128      */

129     public String JavaDoc getGUIName() {
130         return getGUIName(getDefaultLocale());
131     }
132
133     public void setGUIName(String JavaDoc g, Locale locale) {
134         if (guiName == null) guiName = new LocalizedString(key);
135         guiName.set(g, locale);
136     }
137
138     public void setGUIName(String JavaDoc g) {
139         setGUIName(g, getDefaultLocale());
140     }
141
142     public LocalizedString getLocalizedGUIName() {
143         return guiName;
144     }
145
146     protected void setLocalizedGUIName(LocalizedString value) {
147         guiName = value;
148     }
149
150     public String JavaDoc toString() {
151         return key;
152     }
153
154     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
155         return clone(getName() + ".clone");
156     }
157
158     public Object JavaDoc clone(String JavaDoc name) throws CloneNotSupportedException JavaDoc {
159         AbstractDescriptor clone = (AbstractDescriptor)super.clone();
160         clone.description = (LocalizedString)description.clone();
161         clone.guiName = (LocalizedString)guiName.clone();
162         if (name != null) {
163             clone.key = name;
164             clone.description.setKey(name);
165             clone.guiName.setKey(name);
166         }
167         return clone;
168     }
169
170 }
171
Popular Tags