|
@@ -4,56 +4,46 @@ |
4 |
4 |
|
import org.litesoft.aokeyhole.objects.support.*; |
5 |
5 |
|
import org.litesoft.aokeyhole.persist.*; |
6 |
6 |
|
|
7 |
|
- |
public class Property extends AbstractBase |
8 |
|
- |
{ |
|
7 |
+ |
public class Property extends AbstractBase { |
9 |
8 |
|
private PropertyMetaData mMetaData; |
10 |
9 |
|
private boolean mEditable; |
11 |
10 |
|
private Object mValue; |
12 |
11 |
|
|
13 |
|
- |
public Property( PropertyMetaData pMetaData, boolean pEditable ) |
14 |
|
- |
{ |
|
12 |
+ |
public Property( PropertyMetaData pMetaData, boolean pEditable ) { |
15 |
13 |
|
mMetaData = pMetaData; |
16 |
14 |
|
mEditable = pEditable; |
17 |
15 |
|
mValue = pMetaData.getInitialValue(); |
18 |
16 |
|
} |
19 |
17 |
|
|
20 |
|
- |
public PropertyMetaData getMetaData() |
21 |
|
- |
{ |
|
18 |
+ |
public PropertyMetaData getMetaData() { |
22 |
19 |
|
return mMetaData; |
23 |
20 |
|
} |
24 |
21 |
|
|
25 |
|
- |
public boolean isEditable() |
26 |
|
- |
{ |
|
22 |
+ |
public boolean isEditable() { |
27 |
23 |
|
return mEditable; |
28 |
24 |
|
} |
29 |
25 |
|
|
30 |
|
- |
public String getName() |
31 |
|
- |
{ |
|
26 |
+ |
public String getName() { |
32 |
27 |
|
return mMetaData.getName(); |
33 |
28 |
|
} |
34 |
29 |
|
|
35 |
|
- |
public Object getValue() |
36 |
|
- |
{ |
|
30 |
+ |
public Object getValue() { |
37 |
31 |
|
return mValue; |
38 |
32 |
|
} |
39 |
33 |
|
|
40 |
|
- |
public String getValueAsString() |
41 |
|
- |
{ |
|
34 |
+ |
public String getValueAsString() { |
42 |
35 |
|
return mMetaData.valueToString( mValue ); |
43 |
36 |
|
} |
44 |
37 |
|
|
45 |
|
- |
public void unpersistValue( Object pValue ) |
46 |
|
- |
{ |
|
38 |
+ |
public void unpersistValue( Object pValue ) { |
47 |
39 |
|
updateValue( pValue ); |
48 |
40 |
|
} |
49 |
41 |
|
|
50 |
42 |
|
/** |
51 |
43 |
|
* @return true if Value actually changed |
52 |
44 |
|
*/ |
53 |
|
- |
public boolean setValue( Object pValue ) |
54 |
|
- |
{ |
55 |
|
- |
if ( !mEditable ) |
56 |
|
- |
{ |
|
45 |
+ |
public boolean setValue( Object pValue ) { |
|
46 |
+ |
if ( !mEditable ) { |
57 |
47 |
|
throw new IllegalStateException( getName() + " is Not Editable" ); |
58 |
48 |
|
} |
59 |
49 |
|
return updateValue( pValue ); |
|
@@ -62,18 +52,14 @@ |
62 |
52 |
|
/** |
63 |
53 |
|
* @return true if Value actually changed |
64 |
54 |
|
*/ |
65 |
|
- |
protected boolean updateValue( Object pValue ) |
66 |
|
- |
{ |
67 |
|
- |
if ( pValue instanceof String ) |
68 |
|
- |
{ |
|
55 |
+ |
protected boolean updateValue( Object pValue ) { |
|
56 |
+ |
if ( pValue instanceof String ) { |
69 |
57 |
|
pValue = ((String) pValue).trim(); |
70 |
|
- |
if ( "".equals( pValue ) ) |
71 |
|
- |
{ |
|
58 |
+ |
if ( "".equals( pValue ) ) { |
72 |
59 |
|
pValue = null; |
73 |
60 |
|
} |
74 |
61 |
|
} |
75 |
|
- |
if ( areEqual( mValue, pValue ) ) |
76 |
|
- |
{ |
|
62 |
+ |
if ( areEqual( mValue, pValue ) ) { |
77 |
63 |
|
return false; |
78 |
64 |
|
} |
79 |
65 |
|
mValue = pValue; |
|
@@ -83,40 +69,33 @@ |
83 |
69 |
|
/** |
84 |
70 |
|
* @return true if Value actually changed |
85 |
71 |
|
*/ |
86 |
|
- |
public boolean reset() |
87 |
|
- |
{ |
|
72 |
+ |
public boolean reset() { |
88 |
73 |
|
return setValue( mMetaData.getInitialValue() ); |
89 |
74 |
|
} |
90 |
75 |
|
|
91 |
|
- |
public void addTo( PropertyableBuilder pBuilder ) |
92 |
|
- |
{ |
|
76 |
+ |
public void addTo( PropertyableBuilder pBuilder ) { |
93 |
77 |
|
PropertyMetaData md = getMetaData(); |
94 |
78 |
|
Object value = getValue(); |
95 |
|
- |
if ( pBuilder.recordAllProperties() || !areEqual( md.getInitialValue(), value ) ) |
96 |
|
- |
{ |
|
79 |
+ |
if ( pBuilder.recordAllProperties() || !areEqual( md.getInitialValue(), value ) ) { |
97 |
80 |
|
pBuilder.addProperty( getName(), md.valueToString( value ) ); |
98 |
81 |
|
} |
99 |
82 |
|
} |
100 |
83 |
|
|
101 |
|
- |
public void setRehydrated() |
102 |
|
- |
{ |
|
84 |
+ |
public void setRehydrated() { |
103 |
85 |
|
} |
104 |
86 |
|
|
105 |
87 |
|
/** |
106 |
88 |
|
* @return null or Error |
107 |
89 |
|
*/ |
108 |
|
- |
public String validatePersistable() |
109 |
|
- |
{ |
110 |
|
- |
if ( getMetaData().getRequired().isData() && (getValue() == null) ) |
111 |
|
- |
{ |
|
90 |
+ |
public String validatePersistable() { |
|
91 |
+ |
if ( getMetaData().getRequired().isData() && (getValue() == null) ) { |
112 |
92 |
|
return getName() + " is Required"; |
113 |
93 |
|
} |
114 |
94 |
|
return null; |
115 |
95 |
|
} |
116 |
96 |
|
|
117 |
97 |
|
@Override |
118 |
|
- |
public String toString() |
119 |
|
- |
{ |
|
98 |
+ |
public String toString() { |
120 |
99 |
|
return "" + getMetaData() + ":" + getValueAsString(); |
121 |
100 |
|
} |
122 |
101 |
|
} |