01: package simpleorm.properties;
02:
03: /*
04: * Copyright (c) 2002 Southern Cross Software Limited (SCSQ). All rights
05: * reserved. See COPYRIGHT.txt included in this distribution.
06: */
07:
08: /** Represents the key to SPropertyMap. Each property is identified
09: * by its name, which is used to index the map. There is only one
10: * instance of this class for each type of property.
11: */
12: public class SProperty {
13: String name = null; // immutable
14:
15: /** Name of property (Must be globaly unique). */
16: public SProperty(String name) {
17: this .name = name;
18: }
19:
20: public String getName() {
21: return name;
22: }
23:
24: /** Equality is based only on the <code>name</code> */
25: public boolean equals(Object key2) {
26: if (this == key2)
27: return true;
28: if (key2 == null || !(key2 instanceof SProperty))
29: return false;
30: return ((SProperty) key2).name.equals(name);
31: }
32:
33: public int hashCode() {
34: return name.hashCode();
35: }
36:
37: /** Provides a default value for a property. Often specialized. */
38: protected Object defaultValue(SPropertyMap map) {
39: return null;
40: }
41:
42: /** Provides the value for a property. If this is specialized then
43: setting the property has no effect. */
44: protected Object theValue(SPropertyMap map) {
45: return null;
46: }
47:
48: /** Validates the property value, throw an exception if
49: invalid. specialized. */
50: protected void validate(SPropertyMap map, Object value) {
51: }
52:
53: /** Convenience routine that <code> return new SPropertyValue(this,
54: value);</code>. Used as a parameter to SField etc. eg.
55: <code>{MYPROP.pvalue("myvalue"), ...}</code> */
56: public SPropertyValue pvalue(Object value) {
57: return new SPropertyValue(this , value);
58: }
59:
60: /** Convienience routine that returns a PV with TRUE as the value.*/
61: public SPropertyValue ptrue() {
62: return new SPropertyValue(this );
63: }
64:
65: public String toString() {
66: return "[SProperty " + name + "]";
67: }
68:
69: }
|