01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13: package org.rapla.entities.dynamictype;
14:
15: import org.rapla.entities.Annotatable;
16: import org.rapla.entities.MultiLanguageNamed;
17: import org.rapla.entities.RaplaObject;
18: import org.rapla.entities.RaplaType;
19:
20: /** Attributes are to DynamicTypes, what properties are to Beans.
21: Currently Rapla supports the following types:
22: <li>string</li>
23: <li>int</li>
24: <li>date</li>
25: <li>boolean</li>
26: <li>rapla:category</li>
27: @see DynamicType */
28: public interface Attribute extends RaplaObject, MultiLanguageNamed,
29: Annotatable {
30:
31: final RaplaType TYPE = new RaplaType(Attribute.class, "attribute");
32:
33: AttributeType getType();
34:
35: /** Set the type of the Attribute.
36: <strong>Warning:</strong> Changing the type after initialization can lead to data loss,
37: if there are already classifications that use this attribute and the classification value
38: can't be converted to the new type. Example a non numerical string can't be converted to an int.*/
39: void setType(AttributeType type);
40:
41: void setKey(String key);
42:
43: /** The Key is identifier in string-form. Keys could be helpfull
44: for interaction with other modules. An Invoice-Plugin could
45: work on attributes with a "price" key. Keys also allow for a
46: better readability of the XML-File. Changing of a key is
47: possible, but should be used with care.
48: */
49: String getKey();
50:
51: Object defaultValue();
52:
53: /** converts the passed value to fit the attributes type.
54: Example Conversions are:
55: <ul>
56: <li>to string: The result of the method toString() will be the new value.</li>
57: <li>boolean to int: The new value will be 1 when the oldValue is true. Otherwise it is 0.</li>
58: <li>other types to int: First the value will be converted to string-type. And then the
59: trimmed string will be parsed for Integer-values. If that is not possible the new value will
60: be null</li>
61: <li>to boolean: First the value will be converted to string-type. If the trimmed string equals
62: "0" or "false" the new value is false. Otherwise it is true</li>
63: </ul>
64:
65: */
66: Object convertValue(Object oldValue);
67:
68: /** Checks if the passed value matches the attribute type or needs conversion.
69: @see #convertValue
70: */
71: boolean needsChange(Object value);
72:
73: boolean isValid(Object object);
74:
75: boolean isOptional();
76:
77: void setOptional(boolean bOptional);
78:
79: Object getConstraint(String key);
80:
81: Class getConstraintClass(String key);
82:
83: void setConstraint(String key, Object constraint);
84:
85: String[] getConstraintKeys();
86:
87: DynamicType getDynamicType();
88:
89: public static final Attribute[] ATTRIBUTE_ARRAY = new Attribute[0];
90:
91: }
|