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