KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > corebuilders > FieldDefs


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 package org.mmbase.module.corebuilders;
11
12 import java.util.*;
13
14 import org.mmbase.datatypes.DataType;
15 import org.mmbase.bridge.NodeManager;
16 import org.mmbase.datatypes.DataTypes;
17 import org.mmbase.core.CoreField;
18 import org.mmbase.core.util.Fields;
19 import org.mmbase.storage.util.Index;
20
21 /**
22  * One of the core objects. It is not itself a builder, but is used by builders. Defines one field
23  * of a object type / builder.
24  *
25  * @author Daniel Ockeloen
26  * @author Hans Speijer
27  * @author Pierre van Rooden
28  * @version $Id: FieldDefs.java,v 1.56 2005/12/10 13:10:08 michiel Exp $
29  * @see org.mmbase.bridge.Field
30  * @deprecated use {@link CoreField}
31  */

32 public class FieldDefs extends org.mmbase.core.CoreField {
33
34     public final static int DBSTATE_VIRTUAL = 0;
35     public final static int DBSTATE_PERSISTENT = 2;
36     public final static int DBSTATE_SYSTEM = 3;
37
38     public final static int DBSTATE_UNKNOWN = -1;
39
40
41     public final static int ORDER_CREATE = NodeManager.ORDER_CREATE;
42     public final static int ORDER_EDIT = NodeManager.ORDER_EDIT;
43     public final static int ORDER_LIST = NodeManager.ORDER_LIST;
44     public final static int ORDER_SEARCH = NodeManager.ORDER_SEARCH;
45
46     public FieldDefs(String JavaDoc name, int type, int listItemType, int state, DataType dataType ) {
47         super(name, type, listItemType, state, dataType);
48     }
49
50     /**
51      * Constructor for FieldDefs with partially initialized fields.
52      * @param guiName the default GUIName for a field
53      * @param guiType the GUI type (i.e. "integer' or 'field')
54      * @param searchPos position in the editor for this field when searching
55      * @param listPos position in the editor for this field when listing
56      * @param name the actual name of the field in the database
57      * @param type the basic MMBase type of the field
58      */

59     public FieldDefs(String JavaDoc guiName, String JavaDoc guiType, int searchPos, int listPos, String JavaDoc name, int type) {
60         this(guiName, guiType, searchPos, listPos, name, type, -1, STATE_PERSISTENT);
61     }
62
63     /**
64      * Constructor for FieldDefs with partially initialized fields.
65      * @param guiName the default GUIName for a field
66      * @param guiType the GUI type (i.e. "integer' or 'field')
67      * @param searchPos position in the editor for this field when searching
68      * @param listPos position in the editor for this field when listing
69      * @param name the actual name of the field in the database
70      * @param type the basic MMBase type of the field
71      * @param guiPos position in the editor for this field when editing
72      * @param state the state of the field (persistent, virtual, etc.)
73      */

74     public FieldDefs(String JavaDoc guiName, String JavaDoc guiType, int searchPos, int listPos, String JavaDoc name, int type, int guiPos, int state) {
75         super(name, type, TYPE_UNKNOWN, state, (DataType)DataTypes.getDataTypeInstance(guiType,type));
76         setGUIName(guiName);
77         setSearchPosition(searchPos);
78         setEditPosition(guiPos);
79         setListPosition(listPos);
80     }
81
82     /**
83      * Retrieve the database name of the field.
84      * @deprecated use {@link #getName}
85      */

86     public String JavaDoc getDBName() {
87         return getName();
88     }
89
90     /**
91      * Retrieves the basic MMBase type of the field.
92      *
93      * @return The type, this is one of the values defined in this class.
94      * @deprecated to access type constraints, use {@link #getDataType}
95      */

96     public int getDBType() {
97         return getType();
98     }
99
100     /**
101      * Retrieve size of the field.
102      * This may not be specified for some field types.
103      * @deprecated Use {@link #getMaxLength}
104      */

105     public int getDBSize() {
106         return getMaxLength();
107     }
108
109     /**
110      * Retrieve whether the field can be left blank.
111      * @deprecated use {@link #isRequired}
112      */

113     public boolean getDBNotNull() {
114         return getDataType().isRequired();
115     }
116
117     /**
118      * Retrieve whether the field is a key and thus need be 'unique'.
119      * @deprecated use {@link #isUnique} to determine if a field is unique,
120      * use getIndexes() to return set of Index objects to which this key belongs
121      */

122     public boolean isKey() {
123         return getParent() != null && getParent().getStorageConnector().isInIndex(Index.MAIN,this);
124     }
125     /**
126      * Temporary implementation for backwards-compatibility.
127      * I18n stuff in FieldDefs used to use String->String maps. We now have Locale->String maps
128      * available.
129      * This maps new situation to old situation.
130      */

131     protected class LocaleToStringMap extends AbstractMap {
132         private final Map map;
133         public LocaleToStringMap(Map m) {
134             map = m;
135         }
136         public Set entrySet() {
137             return new AbstractSet() {
138                     public Iterator iterator() {
139                         return new Iterator() {
140                                 private final Iterator i = map.entrySet().iterator();
141                                 public boolean hasNext() {
142                                     return i.hasNext();
143                                 }
144                                 public void remove() {
145                                     throw new UnsupportedOperationException JavaDoc("");
146                                 }
147                                 public Object JavaDoc next() {
148                                     final Map.Entry entry = (Map.Entry) i.next();
149                                     return new Map.Entry() {
150                                             public Object JavaDoc getKey() {
151                                                 return ((Locale) entry.getKey()).getLanguage();
152                                             }
153                                             public Object JavaDoc getValue() {
154                                                 return entry.getValue();
155                                             }
156                                             public Object JavaDoc setValue(Object JavaDoc o) {
157                                                 return entry.setValue(o);
158                                             }
159                                         };
160
161                                 }
162                             };
163                     }
164                     public int size() {
165                         return map.size();
166                     }
167                 };
168         }
169     }
170
171     /**
172      * @deprecated use {@link #getGUIName(Locale locale)}
173      */

174     public String JavaDoc getGUIName(String JavaDoc lang) {
175         return getGUIName(new Locale(lang, ""));
176     }
177     /**
178      * @deprecated use {@link #getGUIName()}
179      */

180     public Map getGUINames() {
181         return new LocaleToStringMap(getLocalizedGUIName().asMap());
182     }
183
184     /**
185      * @deprecated use {@link #getDescription()}
186      */

187     public Map getDescriptions() {
188         return new LocaleToStringMap(getLocalizedDescription().asMap());
189     }
190
191     /**
192      * @deprecated use {@link #getDescription(Locale locale)}
193      */

194     public String JavaDoc getDescription(String JavaDoc lang) {
195         return getDescription(new Locale(lang, ""));
196     }
197
198     /**
199      * @deprecated use {@link #getState}
200      */

201     public int getDBState() {
202         return getState();
203     }
204
205     /**
206      * @deprecated should not be called, name need be specified in the constructor
207      */

208     /*
209     public void setDBName(String name) {
210         key = name;
211         setLocalizedDescription(new org.mmbase.util.LocalizedString(key));
212         setLocalizedGUIName(new org.mmbase.util.LocalizedString(key));
213     }
214     */

215
216     /**
217      * SetUI the GUI name of the field for a specified langauge.
218      * @param lang the language to set the name for
219      * @param value the value to set
220      * @deprecated to access type constraints, use {@link #getDataType}
221      */

222     public void setGUIName(String JavaDoc lang, String JavaDoc value) {
223         setGUIName(value, new Locale(lang, ""));
224     }
225
226     /**
227      * Set the description of the field for a specified langauge.
228      * @param lang the language to set the description for
229      * @param value the value to set
230      * @deprecated use {@link #getLocalizedDescription}
231      */

232     public void setDescription(String JavaDoc lang, String JavaDoc value) {
233         setDescription(value, new Locale(lang, ""));
234     }
235
236     /**
237      * Set size of the field.
238      * @param value the value to set
239      * @deprecated use {@link CoreField#setMaxLength}
240      */

241     public void setDBSize(int value) {
242         setMaxLength(value);
243     }
244
245
246     /**
247      * Set the position of the field in the database table.
248      * @param value the value to set
249      * @deprecated use {@link #setStoragePosition}
250      */

251     public void setDBPos(int value) {
252         setStoragePosition(value);
253     }
254
255     /**
256      * @deprecated use {@link #getStoragePosition}
257      */

258     public int getDBPos() {
259         return getStoragePosition();
260     }
261
262     /**
263      * Set the position of the field when listing.
264      * A value of -1 indicates teh field is unavailable in a list.
265      * @param value the value to set
266      * @deprecated use {@link #setListPosition}
267      */

268     public void setGUIList(int value) {
269         setListPosition(value);
270     }
271
272     /**
273      * @deprecated use {@link #getListPosition}
274      */

275     public int getGUIList() {
276         return getListPosition();
277     }
278
279     /**
280      * Set the position of the field when editing.
281      * A value of -1 indicates the field cannot be edited.
282      * @param value the value to set
283      * @deprecated use {@link #setEditPosition}
284      */

285     public void setGUIPos(int value) {
286         setEditPosition(value);
287     }
288
289     /**
290      * @deprecated use {@link #getEditPosition}
291      */

292     public int getGUIPos() {
293         return getEditPosition();
294     }
295     /**
296      * Set the position of the field when searching.
297      * A value of -1 indicates teh field is unavailable during search.
298      * @param value the value to set
299      * @deprecated use {@link #setSearchPosition}
300      */

301     public void setGUISearch(int value) {
302         setSearchPosition(value);
303     }
304
305     /**
306      * @deprecated use {@link #getSearchPosition}
307      */

308     public int getGUISearch() {
309         return getSearchPosition();
310     }
311
312     /**
313      * Set the basic MMBase state of the field, using the state description
314      * @param value the name of the state
315      * @deprecated use {@link #setState}
316      */

317     public void setDBState(String JavaDoc value) {
318         setState(Fields.getState(value));
319     }
320
321     /**
322      * @deprecated use {@link #getState}
323      */

324     public void setDBState(int i) {
325         setState(i);
326     }
327
328     /**
329      * Set whether the field is a key and thus needs to be 'unique'.
330      * @param value the value to set
331      * @deprecated use {@link CoreField#setUnique} to make a field unique.
332      */

333     //use {@link org.mmbase.module.core.MMTable#addToIndex} to make the field part of an index
334
public void setDBKey(boolean value) {
335         if (getParent() != null) {
336             getParent().getStorageConnector().addToIndex(Index.MAIN, this);
337         }
338     }
339
340     /**
341      * Set whether the field can be left blank.
342      * @param value the value to set
343      * @deprecated to access type constraints, use {@link #getDataType}
344      */

345     public void setDBNotNull(boolean value) {
346         getDataType().setRequired(value);
347     }
348
349     /**
350      * Sorts a list with FieldDefs objects, using the default order (ORDER_CREATE)
351      * @param fielddefs the list to sort
352      * @deprecated use Collections.sort
353      */

354     public static void sort(List fielddefs) {
355         Collections.sort(fielddefs);
356     }
357
358     /**
359      * Sorts a list with FieldDefs objects, using the specified order
360      * @param fielddefs the list to sort
361      * @param order one of ORDER_CREATE, ORDER_EDIT, ORDER_LIST,ORDER_SEARCH
362      * @deprecated use {@link Fields#sort}
363      */

364     public static void sort(List fielddefs, int order) {
365         Fields.sort(fielddefs, order);
366     }
367
368 }
369
Popular Tags