KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > util > DataTypeField


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.bridge.util;
12
13 import java.util.*;
14 import org.mmbase.util.LocalizedString;
15 import org.mmbase.bridge.*;
16 import org.mmbase.datatypes.DataType;
17
18
19 /**
20  * Wraps a DataType object into a (virtual) Field object, with a Virtual NodeManager with only one field
21  * (itself). This also associates a Cloud object with the DataType.
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: DataTypeField.java,v 1.1 2006/07/18 15:17:00 michiel Exp $
25  * @since MMBase-1.8.2
26  */

27
28 public class DataTypeField extends org.mmbase.core.AbstractField {
29     protected final NodeManager nodeManager;
30     public DataTypeField(final Cloud cloud, final DataType dataType) {
31         super(dataType.getName(), dataType.getBaseType(), TYPE_UNKNOWN, Field.STATE_VIRTUAL, dataType);
32         nodeManager = new AbstractNodeManager(cloud) {
33                 private final Map fieldTypes = new HashMap();
34                 {
35                     fieldTypes.put(dataType.getName(), DataTypeField.this);
36                 }
37                 protected Map getFieldTypes() {
38                     return Collections.unmodifiableMap(fieldTypes);
39                 }
40             };
41     }
42     public NodeManager getNodeManager() {
43         return nodeManager;
44     }
45
46     public int getSearchPosition() {
47         return -1; // irrelevant, you cannot search
48
}
49
50     public int getListPosition() {
51         return -1; // irrelevant, you cannot do listings
52
}
53
54     public int getEditPosition() {
55         return 1;
56     }
57
58     public int getStoragePosition() {
59         return -1; // irrelevant, not stored
60
}
61
62     public int getMaxLength() {
63         return Integer.MAX_VALUE; // not stored, so no such restriction
64
}
65
66     public String JavaDoc getGUIType() {
67         return dataType.getName();
68     }
69     public Collection validate(Object JavaDoc value) {
70         Collection errors = dataType.validate(value, null, this);
71         return LocalizedString.toStrings(errors, nodeManager.getCloud().getLocale());
72     }
73
74
75 }
76
Popular Tags