001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010:
011: package org.mmbase.bridge;
012:
013: import org.mmbase.datatypes.DataType;
014:
015: /**
016: * This interface represents a node's field type information object.
017: *
018: * @author Pierre van Rooden
019: * @author Jaco de Groot
020: * @version $Id: Field.java,v 1.37 2007/02/10 15:47:42 nklasens Exp $
021: */
022: public interface Field extends Descriptor, Comparable<Field> {
023:
024: /** MMBase base type identifier for the String data type */
025: public final static int TYPE_STRING = 1;
026: /** MMBase base type identifier for the Integer data type */
027: public final static int TYPE_INTEGER = 2;
028: /** MMBase base type identifier for the binary (byte[]) data type */
029: public final static int TYPE_BINARY = 4;
030: /**
031: * MMBase base type identifier for the binary (byte[]) data type
032: * @deprecated use {@link #TYPE_BINARY}
033: */
034: @Deprecated
035: public final static int TYPE_BYTE = TYPE_BINARY;
036: /** MMBase base type identifier for the Float data type */
037: public final static int TYPE_FLOAT = 5;
038: /** MMBase base type identifier for the Double data type */
039: public final static int TYPE_DOUBLE = 6;
040: /** MMBase base type identifier for the Long data type */
041: public final static int TYPE_LONG = 7;
042: /** MMBase base type identifier for the DOM Document data type */
043: public final static int TYPE_XML = 8;
044: /** MMBase base type identifier for the Node data type */
045: public final static int TYPE_NODE = 9;
046: /**
047: * MMBase base type identifier for the Date data type
048: * @since MMBase-1.8
049: */
050: public final static int TYPE_DATETIME = 10;
051: /**
052: * MMBase base type identifier for the Boolean data type
053: * @since MMBase-1.8
054: */
055: public final static int TYPE_BOOLEAN = 11;
056: /**
057: * MMBase base type identifier for the List data type
058: * @since MMBase-1.8
059: */
060: public final static int TYPE_LIST = 12;
061: /** MMBase base type identifier for data types whose type is unknown */
062: public final static int TYPE_UNKNOWN = -1;
063:
064: /** A field's state is 'virtual' if it is not persistent in storage. */
065: public final static int STATE_VIRTUAL = 0;
066: /** A field's state is 'persistent' if it is persistent in storage, and editable. */
067: public final static int STATE_PERSISTENT = 2;
068: /** A field's state is 'system' if it is persistent in storage, but not editable by users. */
069: public final static int STATE_SYSTEM = 3;
070: /** A field's state is 'system virtual' if it is not persistent in storage, nor editable by users.
071: * @todo reserved but not used yet
072: */
073: public final static int STATE_SYSTEM_VIRTUAL = 4;
074: /** The field's state when it is not (yet) known. */
075: public final static int STATE_UNKNOWN = -1;
076:
077: /**
078: * Returns the node manager this field belongs to.
079: *
080: * @return the node manager this field belongs to
081: */
082: public NodeManager getNodeManager();
083:
084: /**
085: * Returns this field's state identifier (virtual, persistent, system, systemvirtual).
086: *
087: * @return an <code>int</code> which identifies the state of this field
088: */
089: public int getState();
090:
091: /**
092: * Returns the data type this field contains.
093: *
094: * @return a <code>DataType</code> object describing the constraints on this field.
095: * @since MMBase-1.8
096: */
097: public DataType getDataType();
098:
099: /**
100: * Returns whether this field is part of a unique key (a set of fields whose combined content should
101: * occur only once).
102: * Note that MMBase lets the storage layer handle this. If your storage implementation or configuration does
103: * not support this the uniqueness may not be enforced.
104: *
105: * @return <code>true</code> if the field is part of a unique key
106: * @since MMBase-1.6
107: */
108: public boolean isUnique();
109:
110: /**
111: * Returns whether this field is a key field, meaning that the storage layer should define an index for it, allowing
112: * optimization with search and sort actions.
113: * Note that MMBase lets the storage layer decide whether an index is actually defined.
114: * Some implementations or configurations may not do this.
115: * Note: Currently, this method only returns true if the field is the primary key (number field) or a Node field.
116: *
117: * @return <code>true</code> if the field has a key defined
118: * @since MMBase-1.7
119: */
120: public boolean hasIndex();
121:
122: /**
123: * Returns the identifier for the MMBase base type for this field.
124: * This represents one of field type constants. This basic type determines how data is stored in MMBase.
125: * Note that it is possible that the datatype for a field (used for validation and in/out put) can be of a different
126: * basic type than how it is stored in the database. This shoudl not occur often, but is possible in some cases, such
127: * as when you use older clod models (which used INTEGER fields for dates).
128: * In general this should not prove a [problem - however you shoudl not assumeto know the classtype iof data of a
129: * field based on this method.
130: * To acquire the datatype's type, use <code>getDataType.getBaseType()</code> instead.
131: * @return an <code>int</code> which identifies the base type
132: */
133: public int getType();
134:
135: /**
136: * If the type of this field is TYPE_LIST, this method returns the MMBase base type for the list elements.
137: * This represents one of field type constants. This basic type determines how data is stored in MMBase.
138: * For any field types other that TYPE_LIST, this method returns TYPE_UNKNOWN.
139: * @return an <code>int</code> which identifies the base type
140: */
141: public int getListItemType();
142:
143: /**
144: * Retrieve the position of the field when searching.
145: * A value of -1 indicates the field is unavailable during search.
146: * @since MMBase-1.8
147: */
148: public int getSearchPosition();
149:
150: /**
151: * Retrieve the position of the field when listing.
152: * A value of -1 indicates the field is unavailable in a list.
153: * @since MMBase-1.8
154: */
155: public int getListPosition();
156:
157: /**
158: * Retrieve the position of the field when editing.
159: * A value of -1 indicates the field cannot be edited.
160: * @since MMBase-1.8
161: */
162: public int getEditPosition();
163:
164: /**
165: * Retrieve the position of the field in the database table.
166: * @since MMBase-1.8
167: */
168: public int getStoragePosition();
169:
170: /**
171: * Returns the GUI name for the data type this field contains.
172: * @deprecated use {@link #getDataType } and {@link DataType#getName}
173: * @see #getDataType
174: */
175: @Deprecated
176: public String getGUIType();
177:
178: /**
179: * Returns whether this field is required (should have content).
180: * Note that MMBase does not generally enforce required fields to be filled -
181: * If not provided, a default value (generally an empty string or the integer value -1)
182: * is filled in by the system.
183: * As such, isRequired will mostly be used as an indicator for (generic) editors.
184: *
185: * @return <code>true</code> if the field is required
186: * @since MMBase-1.6
187: */
188: public boolean isRequired();
189:
190: /**
191: * Returns the maximum length of data this field can contain.
192: * For example if a field contains characters the size indicates the
193: * maximum number of characters it can contain.
194: * If the field is a numeric field (such as an integer), the result is -1.
195: *
196: * @return the maximum length of data this field can contain
197: */
198: public int getMaxLength();
199:
200: /**
201: * Checks whether a given value is valid for this field.
202: * @return Collection of error-strings (describing the problem) in the current locale, or an empty collection if the value is ok.
203: * @since MMBase-1.8
204: */
205: public java.util.Collection validate(Object value);
206:
207: /**
208: * A field's state is 'virtual' if it is not persistent in storage.
209: * @return <code>true</code> when a field is virtual
210: * @since MMBase-1.8
211: */
212: public boolean isVirtual();
213:
214: /**
215: * Returns whether a field is 'read only' - that is, a user cannot edit it.
216: * In general, fields with state SYSTEM or SYSTEM_VIRTUAL are defined as read only, while others are not.
217: * It is possible to override this behaviour per field.
218: * @return <code>true</code> when a field is read only
219: * @since MMBase-1.8
220: */
221: public boolean isReadOnly();
222:
223: }
|