01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
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: * Wraps a DataType object into a (virtual) Field object, with a Virtual NodeManager with only one field
20: * (itself). This also associates a Cloud object with the DataType.
21: *
22: * @author Michiel Meeuwissen
23: * @version $Id: DataTypeField.java,v 1.3 2007/02/10 17:44:03 nklasens Exp $
24: * @since MMBase-1.8.2
25: */
26:
27: public class DataTypeField extends org.mmbase.core.AbstractField {
28: protected final NodeManager nodeManager;
29:
30: public DataTypeField(final Cloud cloud, final DataType dataType) {
31: super (dataType.getName(), dataType.getBaseType(), TYPE_UNKNOWN,
32: Field.STATE_VIRTUAL, dataType);
33: nodeManager = new AbstractNodeManager(cloud) {
34: private final Map<String, Field> fieldTypes = new HashMap<String, Field>();
35: {
36: fieldTypes.put(dataType.getName(), DataTypeField.this );
37: }
38:
39: @Override
40: protected Map<String, Field> getFieldTypes() {
41: return Collections.unmodifiableMap(fieldTypes);
42: }
43: };
44: }
45:
46: @Override
47: public NodeManager getNodeManager() {
48: return nodeManager;
49: }
50:
51: @Override
52: public int getSearchPosition() {
53: return -1; // irrelevant, you cannot search
54: }
55:
56: @Override
57: public int getListPosition() {
58: return -1; // irrelevant, you cannot do listings
59: }
60:
61: @Override
62: public int getEditPosition() {
63: return 1;
64: }
65:
66: @Override
67: public int getStoragePosition() {
68: return -1; // irrelevant, not stored
69: }
70:
71: @Override
72: public int getMaxLength() {
73: return Integer.MAX_VALUE; // not stored, so no such restriction
74: }
75:
76: @Override
77: public String getGUIType() {
78: return dataType.getName();
79: }
80:
81: public Collection validate(Object value) {
82: Collection<LocalizedString> errors = dataType.validate(value,
83: null, this);
84: return LocalizedString.toStrings(errors, nodeManager.getCloud()
85: .getLocale());
86: }
87:
88: }
|