|
@@ -1,270 +1,270 @@ |
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 |
|
- |
import org.litesoft.aokeyhole.toolkit.*; |
7 |
|
- |
import org.litesoft.core.simpletypes.nonpublic.*; |
8 |
|
- |
|
9 |
|
- |
public abstract class AttributeMetaData extends AbstractNamedMetaData<ObjectMetaData> implements MinimalAttributeMetaData, |
10 |
|
- |
ViewSupportable, |
11 |
|
- |
Comparable<AttributeMetaData> { |
12 |
|
- |
public static final String ID_NAME = "ID"; |
13 |
|
- |
|
14 |
|
- |
private final AttributeSet mAttributeSet; |
15 |
|
- |
private final boolean mVirtual; |
16 |
|
- |
private final PropertyManager mPropertyManager; |
17 |
|
- |
private String mNotes = null; |
18 |
|
- |
|
19 |
|
- |
protected AttributeMetaData( AttributeSet pAttributeSet, Mode pMode, boolean pEditable, boolean pVirtual, PropertyMetaData[] pPropertyMetaDatas, |
20 |
|
- |
IdentifierValidator pNameValidator, String pName ) { |
21 |
|
- |
super( pAttributeSet.getType().toString(), pMode, pEditable, pNameValidator, pName ); |
22 |
|
- |
|
23 |
|
- |
mAttributeSet = pAttributeSet; |
24 |
|
- |
mVirtual = pVirtual; |
25 |
|
- |
mPropertyManager = new PropertyManager( this, pEditable, pPropertyMetaDatas ); |
26 |
|
- |
} |
27 |
|
- |
|
28 |
|
- |
@Override |
29 |
|
- |
public int compareTo( AttributeMetaData them ) { |
30 |
|
- |
int zDiff = this.getAttributeSet().getSortIndex() - them.getAttributeSet().getSortIndex(); |
31 |
|
- |
if ( zDiff != 0 ) { |
32 |
|
- |
return zDiff; |
33 |
|
- |
} |
34 |
|
- |
return CompareSupport.compare( this.getName(), them.getName() ); |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
public AttributeSet getAttributeSet() { |
38 |
|
- |
return mAttributeSet; |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
abstract public boolean isRelated(); |
42 |
|
- |
|
43 |
|
- |
public boolean isVirtual() { |
44 |
|
- |
return mVirtual; |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
@Override |
48 |
|
- |
public Class getSimpleDataType() { |
49 |
|
- |
return getAttributeSetType().getSimpleDataType(); |
50 |
|
- |
} |
51 |
|
- |
|
52 |
|
- |
@Override |
53 |
|
- |
public AttributeType getAttributeSetType() { |
54 |
|
- |
return getAttributeSet().getType(); |
55 |
|
- |
} |
56 |
|
- |
|
57 |
|
- |
public String getNotes() { |
58 |
|
- |
return mNotes; |
59 |
|
- |
} |
60 |
|
- |
|
61 |
|
- |
public void unpersistNotes( String pNotes ) { |
62 |
|
- |
mNotes = pNotes; |
63 |
|
- |
} |
64 |
|
- |
|
65 |
|
- |
public void setNotes( String pNotes ) { |
66 |
|
- |
verifyEditability(); |
67 |
|
- |
if ( !areEqual( mNotes, pNotes ) ) { |
68 |
|
- |
mNotes = pNotes; |
69 |
|
- |
changed(); |
70 |
|
- |
} |
71 |
|
- |
} |
72 |
|
- |
|
73 |
|
- |
@SuppressWarnings("UnusedDeclaration") |
74 |
|
- |
public Object getPropertyValue( String pName ) { |
75 |
|
- |
Property property = mPropertyManager.getProperty( pName ); |
76 |
|
- |
return (property == null) ? null : property.getValue(); |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
public PropertyManager getPropertyManager() { |
80 |
|
- |
return mPropertyManager; |
81 |
|
- |
} |
82 |
|
- |
|
83 |
|
- |
@SuppressWarnings("UnusedDeclaration") |
84 |
|
- |
public Property[] getProperties() { |
85 |
|
- |
return mPropertyManager.getProperties(); |
86 |
|
- |
} |
87 |
|
- |
|
88 |
|
- |
@SuppressWarnings("UnusedDeclaration") |
89 |
|
- |
public void unpersistProperty( String pName, String pValueAsString ) { |
90 |
|
- |
mPropertyManager.unpersistProperty( pName, pValueAsString ); |
91 |
|
- |
} |
92 |
|
- |
|
93 |
|
- |
/** |
94 |
|
- |
* @return null or Error |
95 |
|
- |
*/ |
96 |
|
- |
@SuppressWarnings("UnusedDeclaration") |
97 |
|
- |
public String setPropertyValue( String pName, Object pValue ) { |
98 |
|
- |
return mPropertyManager.updatePropertyValue( pName, pValue ); |
99 |
|
- |
} |
100 |
|
- |
|
101 |
|
- |
public void populateFrom( AttributeReader pReader ) { |
102 |
|
- |
for ( PropertyReader zReader; null != (zReader = pReader.nextProperty()); ) { |
103 |
|
- |
String zWhat = zReader.getWhat(); |
104 |
|
- |
String zData = zReader.getData(); |
105 |
|
- |
if ( ObjectNames.NOTES.equals( zWhat ) ) { |
106 |
|
- |
unpersistNotes( zData ); |
107 |
|
- |
} else { |
108 |
|
- |
mPropertyManager.unpersistProperty( zWhat, zData ); |
109 |
|
- |
} |
110 |
|
- |
} |
111 |
|
- |
} |
112 |
|
- |
|
113 |
|
- |
@Override |
114 |
|
- |
public void setRehydrated() { |
115 |
|
- |
super.setRehydrated(); |
116 |
|
- |
mPropertyManager.setRehydrated(); |
117 |
|
- |
} |
118 |
|
- |
|
119 |
|
- |
/** |
120 |
|
- |
* @return null or Error |
121 |
|
- |
*/ |
122 |
|
- |
@Override |
123 |
|
- |
public String validatePersistable() { |
124 |
|
- |
String error = super.validatePersistable(); |
125 |
|
- |
return (error != null) ? error : mPropertyManager.validatePersistable(); |
126 |
|
- |
} |
127 |
|
- |
|
128 |
|
- |
public void addTo( ObjectBuilder pBuilder ) { |
129 |
|
- |
AttributeBuilder zBuilder = pBuilder.createAttributeBuilder( getMetaDataType(), isVirtual(), getName(), |
130 |
|
- |
SingleLineNotes.convertStringToLines( getNotes() ), |
131 |
|
- |
getAdditionalValues() ); |
132 |
|
- |
mPropertyManager.addTo( zBuilder ); |
133 |
|
- |
zBuilder.done(); |
134 |
|
- |
} |
135 |
|
- |
|
136 |
|
- |
abstract protected String[] getAdditionalValues(); |
137 |
|
- |
|
138 |
|
- |
@Override |
139 |
|
- |
public void setUpView( NameValuesComponent pNameValuesComponent ) { |
140 |
|
- |
pNameValuesComponent.setValue( AttribNames.NAME, getName() ); |
141 |
|
- |
pNameValuesComponent.setValue( ObjectNames.NOTES, getNotes() ); |
142 |
|
- |
mPropertyManager.setUpView( pNameValuesComponent ); |
143 |
|
- |
} |
144 |
|
- |
|
145 |
|
- |
protected void saveFromViewCollectChanges( ChangeHandler pChanges, NameValuesComponent pNameValuesComponent ) { |
146 |
|
- |
pChanges.add( checkNameChange( pNameValuesComponent.getValue( AttribNames.NAME ) ) ); |
147 |
|
- |
pChanges.add( checkNotesChange( pNameValuesComponent.getValue( ObjectNames.NOTES ) ) ); |
148 |
|
- |
mPropertyManager.saveFromView( pChanges, pNameValuesComponent ); |
149 |
|
- |
} |
150 |
|
- |
|
151 |
|
- |
/** |
152 |
|
- |
* @return null or Error |
153 |
|
- |
*/ |
154 |
|
- |
@Override |
155 |
|
- |
public final String saveFromView( NameValuesComponent pNameValuesComponent ) { |
156 |
|
- |
ChangeHandler zChanges = new ChangeHandler(); |
157 |
|
- |
try { |
158 |
|
- |
saveFromViewCollectChanges( zChanges, pNameValuesComponent ); |
159 |
|
- |
} |
160 |
|
- |
catch ( RuntimeException e ) { |
161 |
|
- |
return e.getMessage(); |
162 |
|
- |
} |
163 |
|
- |
|
164 |
|
- |
zChanges.commitChanges(); |
165 |
|
- |
return null; |
166 |
|
- |
} |
167 |
|
- |
|
168 |
|
- |
/** |
169 |
|
- |
* @return null or Error |
170 |
|
- |
*/ |
171 |
|
- |
public final String deleteExisting() { |
172 |
|
- |
ChangeHandler zChanges = new ChangeHandler(); |
173 |
|
- |
try { |
174 |
|
- |
deleteExistingCollectChanges( zChanges ); |
175 |
|
- |
} |
176 |
|
- |
catch ( RuntimeException e ) { |
177 |
|
- |
return e.getMessage(); |
178 |
|
- |
} |
179 |
|
- |
|
180 |
|
- |
zChanges.commitChanges(); |
181 |
|
- |
return null; |
182 |
|
- |
} |
183 |
|
- |
|
184 |
|
- |
public void deleteExistingCollectChanges( ChangeHandler pChanges ) { |
185 |
|
- |
pChanges.add( new DeleteAttribute( this ) ); |
186 |
|
- |
} |
187 |
|
- |
|
188 |
|
- |
public ObjectMetaData getObjectMetaData() { |
189 |
|
- |
return getOwner(); |
190 |
|
- |
} |
191 |
|
- |
|
192 |
|
- |
public void clearRelatedToIf( ObjectMetaData pObjectMetaData, ChangeHandler pChanges ) { |
193 |
|
- |
} |
194 |
|
- |
|
195 |
|
- |
protected abstract static class AbstractChangeFragment implements ChangeFragment { |
196 |
|
- |
protected AttributeMetaData mCaller; |
197 |
|
- |
|
198 |
|
- |
protected AbstractChangeFragment( AttributeMetaData pCaller ) { |
199 |
|
- |
mCaller = pCaller; |
200 |
|
- |
} |
201 |
|
- |
} |
202 |
|
- |
|
203 |
|
- |
protected ChangeFragment checkNameChange( String pNewName ) { |
204 |
|
- |
String zError = getNameValidator().validateIdentifier( pNewName, "Attribute Name" ); |
205 |
|
- |
if ( zError != null ) { |
206 |
|
- |
throw new RuntimeException( zError ); |
207 |
|
- |
} |
208 |
|
- |
String zCurName = getName(); |
209 |
|
- |
if ( !areEqual( zCurName, pNewName ) ) { |
210 |
|
- |
ObjectMetaData zOwner = getObjectMetaData(); |
211 |
|
- |
if ( zOwner.isUsedOwnedName( pNewName ) ) { |
212 |
|
- |
throw new RuntimeException( "Duplicate Name" ); |
213 |
|
- |
} |
214 |
|
- |
return createChangeNameFragment( pNewName ); |
215 |
|
- |
} |
216 |
|
- |
return null; |
217 |
|
- |
} |
218 |
|
- |
|
219 |
|
- |
protected ChangeFragment createChangeNameFragment( String pNewName ) { |
220 |
|
- |
return new ChangeName( this, pNewName ); |
221 |
|
- |
} |
222 |
|
- |
|
223 |
|
- |
protected static class ChangeName extends AbstractChangeFragment { |
224 |
|
- |
private String mNewName; |
225 |
|
- |
|
226 |
|
- |
public ChangeName( AttributeMetaData pCaller, String pNewName ) { |
227 |
|
- |
super( pCaller ); |
228 |
|
- |
mNewName = pNewName; |
229 |
|
- |
} |
230 |
|
- |
|
231 |
|
- |
@Override |
232 |
|
- |
public void commitChange() { |
233 |
|
- |
mCaller.setName( mNewName ); |
234 |
|
- |
} |
235 |
|
- |
} |
236 |
|
- |
|
237 |
|
- |
protected ChangeFragment checkNotesChange( String pNewNotes ) { |
238 |
|
- |
String zCurNotes = getNotes(); |
239 |
|
- |
return !areEqual( zCurNotes, pNewNotes ) ? createChangeNotesFragment( pNewNotes ) : null; |
240 |
|
- |
} |
241 |
|
- |
|
242 |
|
- |
protected ChangeFragment createChangeNotesFragment( String pNewNotes ) { |
243 |
|
- |
return new ChangeNotes( this, pNewNotes ); |
244 |
|
- |
} |
245 |
|
- |
|
246 |
|
- |
protected static class ChangeNotes extends AbstractChangeFragment { |
247 |
|
- |
private String mNewNotes; |
248 |
|
- |
|
249 |
|
- |
public ChangeNotes( AttributeMetaData pCaller, String pNewNotes ) { |
250 |
|
- |
super( pCaller ); |
251 |
|
- |
mNewNotes = pNewNotes; |
252 |
|
- |
} |
253 |
|
- |
|
254 |
|
- |
@Override |
255 |
|
- |
public void commitChange() { |
256 |
|
- |
mCaller.setNotes( mNewNotes ); |
257 |
|
- |
} |
258 |
|
- |
} |
259 |
|
- |
|
260 |
|
- |
protected static class DeleteAttribute extends AbstractChangeFragment { |
261 |
|
- |
public DeleteAttribute( AttributeMetaData pCaller ) { |
262 |
|
- |
super( pCaller ); |
263 |
|
- |
} |
264 |
|
- |
|
265 |
|
- |
@Override |
266 |
|
- |
public void commitChange() { |
267 |
|
- |
mCaller.getObjectMetaData().remove( mCaller ); |
268 |
|
- |
} |
269 |
|
- |
} |
270 |
|
- |
} |
|
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 |
+ |
import org.litesoft.aokeyhole.toolkit.*; |
|
7 |
+ |
import org.litesoft.core.simpletypes.nonpublic.*; |
|
8 |
+ |
|
|
9 |
+ |
public abstract class AttributeMetaData extends AbstractNamedMetaData<ObjectMetaData> implements MinimalAttributeMetaData, |
|
10 |
+ |
ViewSupportable, |
|
11 |
+ |
Comparable<AttributeMetaData> { |
|
12 |
+ |
public static final String ID_NAME = "ID"; |
|
13 |
+ |
|
|
14 |
+ |
private final AttributeSet mAttributeSet; |
|
15 |
+ |
private final boolean mVirtual; |
|
16 |
+ |
private final PropertyManager mPropertyManager; |
|
17 |
+ |
private String mNotes = null; |
|
18 |
+ |
|
|
19 |
+ |
protected AttributeMetaData( AttributeSet pAttributeSet, Mode pMode, boolean pEditable, boolean pVirtual, PropertyMetaData[] pPropertyMetaDatas, |
|
20 |
+ |
IdentifierValidator pNameValidator, String pName ) { |
|
21 |
+ |
super( pAttributeSet.getType().toString(), pMode, pEditable, pNameValidator, pName ); |
|
22 |
+ |
|
|
23 |
+ |
mAttributeSet = pAttributeSet; |
|
24 |
+ |
mVirtual = pVirtual; |
|
25 |
+ |
mPropertyManager = new PropertyManager( this, pEditable, pPropertyMetaDatas ); |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
@Override |
|
29 |
+ |
public int compareTo( AttributeMetaData them ) { |
|
30 |
+ |
int zDiff = this.getAttributeSet().getSortIndex() - them.getAttributeSet().getSortIndex(); |
|
31 |
+ |
if ( zDiff != 0 ) { |
|
32 |
+ |
return zDiff; |
|
33 |
+ |
} |
|
34 |
+ |
return CompareSupport.compare( this.getName(), them.getName() ); |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
public AttributeSet getAttributeSet() { |
|
38 |
+ |
return mAttributeSet; |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
abstract public boolean isRelated(); |
|
42 |
+ |
|
|
43 |
+ |
public boolean isVirtual() { |
|
44 |
+ |
return mVirtual; |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
@Override |
|
48 |
+ |
public Class getSimpleDataType() { |
|
49 |
+ |
return getAttributeSetType().getSimpleDataType(); |
|
50 |
+ |
} |
|
51 |
+ |
|
|
52 |
+ |
@Override |
|
53 |
+ |
public AttributeType getAttributeSetType() { |
|
54 |
+ |
return getAttributeSet().getType(); |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
public String getNotes() { |
|
58 |
+ |
return mNotes; |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
public void unpersistNotes( String pNotes ) { |
|
62 |
+ |
mNotes = pNotes; |
|
63 |
+ |
} |
|
64 |
+ |
|
|
65 |
+ |
public void setNotes( String pNotes ) { |
|
66 |
+ |
verifyEditability(); |
|
67 |
+ |
if ( !areEqual( mNotes, pNotes ) ) { |
|
68 |
+ |
mNotes = pNotes; |
|
69 |
+ |
changed(); |
|
70 |
+ |
} |
|
71 |
+ |
} |
|
72 |
+ |
|
|
73 |
+ |
@SuppressWarnings("UnusedDeclaration") |
|
74 |
+ |
public Object getPropertyValue( String pName ) { |
|
75 |
+ |
Property property = mPropertyManager.getProperty( pName ); |
|
76 |
+ |
return (property == null) ? null : property.getValue(); |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
public PropertyManager getPropertyManager() { |
|
80 |
+ |
return mPropertyManager; |
|
81 |
+ |
} |
|
82 |
+ |
|
|
83 |
+ |
@SuppressWarnings("UnusedDeclaration") |
|
84 |
+ |
public Property[] getProperties() { |
|
85 |
+ |
return mPropertyManager.getProperties(); |
|
86 |
+ |
} |
|
87 |
+ |
|
|
88 |
+ |
@SuppressWarnings("UnusedDeclaration") |
|
89 |
+ |
public void unpersistProperty( String pName, String pValueAsString ) { |
|
90 |
+ |
mPropertyManager.unpersistProperty( pName, pValueAsString ); |
|
91 |
+ |
} |
|
92 |
+ |
|
|
93 |
+ |
/** |
|
94 |
+ |
* @return null or Error |
|
95 |
+ |
*/ |
|
96 |
+ |
@SuppressWarnings("UnusedDeclaration") |
|
97 |
+ |
public String setPropertyValue( String pName, Object pValue ) { |
|
98 |
+ |
return mPropertyManager.updatePropertyValue( pName, pValue ); |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
public void populateFrom( AttributeReader pReader ) { |
|
102 |
+ |
for ( PropertyReader zReader; null != (zReader = pReader.nextProperty()); ) { |
|
103 |
+ |
String zWhat = zReader.getWhat(); |
|
104 |
+ |
String zData = zReader.getData(); |
|
105 |
+ |
if ( ObjectNames.NOTES.equals( zWhat ) ) { |
|
106 |
+ |
unpersistNotes( zData ); |
|
107 |
+ |
} else { |
|
108 |
+ |
mPropertyManager.unpersistProperty( zWhat, zData ); |
|
109 |
+ |
} |
|
110 |
+ |
} |
|
111 |
+ |
} |
|
112 |
+ |
|
|
113 |
+ |
@Override |
|
114 |
+ |
public void setRehydrated() { |
|
115 |
+ |
super.setRehydrated(); |
|
116 |
+ |
mPropertyManager.setRehydrated(); |
|
117 |
+ |
} |
|
118 |
+ |
|
|
119 |
+ |
/** |
|
120 |
+ |
* @return null or Error |
|
121 |
+ |
*/ |
|
122 |
+ |
@Override |
|
123 |
+ |
public String validatePersistable() { |
|
124 |
+ |
String error = super.validatePersistable(); |
|
125 |
+ |
return (error != null) ? error : mPropertyManager.validatePersistable(); |
|
126 |
+ |
} |
|
127 |
+ |
|
|
128 |
+ |
public void addTo( ObjectBuilder pBuilder ) { |
|
129 |
+ |
AttributeBuilder zBuilder = pBuilder.createAttributeBuilder( getMetaDataType(), isVirtual(), getName(), |
|
130 |
+ |
SingleLineNotes.convertStringToLines( getNotes() ), |
|
131 |
+ |
getAdditionalValues() ); |
|
132 |
+ |
mPropertyManager.addTo( zBuilder ); |
|
133 |
+ |
zBuilder.done(); |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
abstract protected String[] getAdditionalValues(); |
|
137 |
+ |
|
|
138 |
+ |
@Override |
|
139 |
+ |
public void setUpView( NameValuesComponent pNameValuesComponent ) { |
|
140 |
+ |
pNameValuesComponent.setValue( AttribNames.NAME, getName() ); |
|
141 |
+ |
pNameValuesComponent.setValue( ObjectNames.NOTES, getNotes() ); |
|
142 |
+ |
mPropertyManager.setUpView( pNameValuesComponent ); |
|
143 |
+ |
} |
|
144 |
+ |
|
|
145 |
+ |
protected void saveFromViewCollectChanges( ChangeHandler pChanges, NameValuesComponent pNameValuesComponent ) { |
|
146 |
+ |
pChanges.add( checkNameChange( pNameValuesComponent.getValue( AttribNames.NAME ) ) ); |
|
147 |
+ |
pChanges.add( checkNotesChange( pNameValuesComponent.getValue( ObjectNames.NOTES ) ) ); |
|
148 |
+ |
mPropertyManager.saveFromView( pChanges, pNameValuesComponent ); |
|
149 |
+ |
} |
|
150 |
+ |
|
|
151 |
+ |
/** |
|
152 |
+ |
* @return null or Error |
|
153 |
+ |
*/ |
|
154 |
+ |
@Override |
|
155 |
+ |
public final String saveFromView( NameValuesComponent pNameValuesComponent ) { |
|
156 |
+ |
ChangeHandler zChanges = new ChangeHandler(); |
|
157 |
+ |
try { |
|
158 |
+ |
saveFromViewCollectChanges( zChanges, pNameValuesComponent ); |
|
159 |
+ |
} |
|
160 |
+ |
catch ( RuntimeException e ) { |
|
161 |
+ |
return e.getMessage(); |
|
162 |
+ |
} |
|
163 |
+ |
|
|
164 |
+ |
zChanges.commitChanges(); |
|
165 |
+ |
return null; |
|
166 |
+ |
} |
|
167 |
+ |
|
|
168 |
+ |
/** |
|
169 |
+ |
* @return null or Error |
|
170 |
+ |
*/ |
|
171 |
+ |
public final String deleteExisting() { |
|
172 |
+ |
ChangeHandler zChanges = new ChangeHandler(); |
|
173 |
+ |
try { |
|
174 |
+ |
deleteExistingCollectChanges( zChanges ); |
|
175 |
+ |
} |
|
176 |
+ |
catch ( RuntimeException e ) { |
|
177 |
+ |
return e.getMessage(); |
|
178 |
+ |
} |
|
179 |
+ |
|
|
180 |
+ |
zChanges.commitChanges(); |
|
181 |
+ |
return null; |
|
182 |
+ |
} |
|
183 |
+ |
|
|
184 |
+ |
public void deleteExistingCollectChanges( ChangeHandler pChanges ) { |
|
185 |
+ |
pChanges.add( new DeleteAttribute( this ) ); |
|
186 |
+ |
} |
|
187 |
+ |
|
|
188 |
+ |
public ObjectMetaData getObjectMetaData() { |
|
189 |
+ |
return getOwner(); |
|
190 |
+ |
} |
|
191 |
+ |
|
|
192 |
+ |
public void clearRelatedToIf( ObjectMetaData pObjectMetaData, ChangeHandler pChanges ) { |
|
193 |
+ |
} |
|
194 |
+ |
|
|
195 |
+ |
protected abstract static class AbstractChangeFragment implements ChangeFragment { |
|
196 |
+ |
protected AttributeMetaData mCaller; |
|
197 |
+ |
|
|
198 |
+ |
protected AbstractChangeFragment( AttributeMetaData pCaller ) { |
|
199 |
+ |
mCaller = pCaller; |
|
200 |
+ |
} |
|
201 |
+ |
} |
|
202 |
+ |
|
|
203 |
+ |
protected ChangeFragment checkNameChange( String pNewName ) { |
|
204 |
+ |
String zError = getNameValidator().validateIdentifier( pNewName, "Attribute Name" ); |
|
205 |
+ |
if ( zError != null ) { |
|
206 |
+ |
throw new RuntimeException( zError ); |
|
207 |
+ |
} |
|
208 |
+ |
String zCurName = getName(); |
|
209 |
+ |
if ( !areEqual( zCurName, pNewName ) ) { |
|
210 |
+ |
ObjectMetaData zOwner = getObjectMetaData(); |
|
211 |
+ |
if ( zOwner.isUsedOwnedName( pNewName ) ) { |
|
212 |
+ |
throw new RuntimeException( "Duplicate Name" ); |
|
213 |
+ |
} |
|
214 |
+ |
return createChangeNameFragment( pNewName ); |
|
215 |
+ |
} |
|
216 |
+ |
return null; |
|
217 |
+ |
} |
|
218 |
+ |
|
|
219 |
+ |
protected ChangeFragment createChangeNameFragment( String pNewName ) { |
|
220 |
+ |
return new ChangeName( this, pNewName ); |
|
221 |
+ |
} |
|
222 |
+ |
|
|
223 |
+ |
protected static class ChangeName extends AbstractChangeFragment { |
|
224 |
+ |
private String mNewName; |
|
225 |
+ |
|
|
226 |
+ |
public ChangeName( AttributeMetaData pCaller, String pNewName ) { |
|
227 |
+ |
super( pCaller ); |
|
228 |
+ |
mNewName = pNewName; |
|
229 |
+ |
} |
|
230 |
+ |
|
|
231 |
+ |
@Override |
|
232 |
+ |
public void commitChange() { |
|
233 |
+ |
mCaller.setName( mNewName ); |
|
234 |
+ |
} |
|
235 |
+ |
} |
|
236 |
+ |
|
|
237 |
+ |
protected ChangeFragment checkNotesChange( String pNewNotes ) { |
|
238 |
+ |
String zCurNotes = getNotes(); |
|
239 |
+ |
return !areEqual( zCurNotes, pNewNotes ) ? createChangeNotesFragment( pNewNotes ) : null; |
|
240 |
+ |
} |
|
241 |
+ |
|
|
242 |
+ |
protected ChangeFragment createChangeNotesFragment( String pNewNotes ) { |
|
243 |
+ |
return new ChangeNotes( this, pNewNotes ); |
|
244 |
+ |
} |
|
245 |
+ |
|
|
246 |
+ |
protected static class ChangeNotes extends AbstractChangeFragment { |
|
247 |
+ |
private String mNewNotes; |
|
248 |
+ |
|
|
249 |
+ |
public ChangeNotes( AttributeMetaData pCaller, String pNewNotes ) { |
|
250 |
+ |
super( pCaller ); |
|
251 |
+ |
mNewNotes = pNewNotes; |
|
252 |
+ |
} |
|
253 |
+ |
|
|
254 |
+ |
@Override |
|
255 |
+ |
public void commitChange() { |
|
256 |
+ |
mCaller.setNotes( mNewNotes ); |
|
257 |
+ |
} |
|
258 |
+ |
} |
|
259 |
+ |
|
|
260 |
+ |
protected static class DeleteAttribute extends AbstractChangeFragment { |
|
261 |
+ |
public DeleteAttribute( AttributeMetaData pCaller ) { |
|
262 |
+ |
super( pCaller ); |
|
263 |
+ |
} |
|
264 |
+ |
|
|
265 |
+ |
@Override |
|
266 |
+ |
public void commitChange() { |
|
267 |
+ |
mCaller.getObjectMetaData().remove( mCaller ); |
|
268 |
+ |
} |
|
269 |
+ |
} |
|
270 |
+ |
} |