34
34
35
35
import de .cubeisland .engine .reflect .Section ;
36
36
import de .cubeisland .engine .reflect .annotations .Comment ;
37
+ import de .cubeisland .engine .reflect .annotations .Converter ;
37
38
import de .cubeisland .engine .reflect .annotations .Name ;
38
39
import de .cubeisland .engine .reflect .codec .ConverterManager ;
39
40
import de .cubeisland .engine .reflect .exception .ConversionException ;
@@ -94,7 +95,7 @@ protected final ReflectedPath getPathFor(Field field)
94
95
}
95
96
else
96
97
{
97
- path = ReflectedPath .forName (StringUtils .fieldNameToPath (field .getName ()));
98
+ path = ReflectedPath .forName (StringUtils .fieldNameToPath (field .getName ())); // TODO configurable Naming convention #20
98
99
}
99
100
this .paths .put (field , path );
100
101
}
@@ -122,7 +123,7 @@ public Node toNode(Section section, ConverterManager manager) throws ConversionE
122
123
}
123
124
try
124
125
{
125
- Node newNode = manager . convertToNode ( field . get ( section ) );
126
+ Node newNode = toNode ( section , manager , field );
126
127
addComment (newNode , field );
127
128
128
129
Node prevNode = baseNode .getNodeAt (getPathFor (field ));
@@ -154,6 +155,21 @@ public Node toNode(Section section, ConverterManager manager) throws ConversionE
154
155
return baseNode ;
155
156
}
156
157
158
+ @ SuppressWarnings ("unchecked" )
159
+ private Node toNode (Section section , ConverterManager manager , Field field ) throws ConversionException , IllegalAccessException
160
+ {
161
+ Node newNode ;
162
+ if (field .isAnnotationPresent (Converter .class ))
163
+ {
164
+ newNode = manager .getAnnotationConverter (field .getAnnotation (Converter .class ).value ()).toNode (field .get (section ), manager );
165
+ }
166
+ else
167
+ {
168
+ newNode = manager .convertToNode (field .get (section ));
169
+ }
170
+ return newNode ;
171
+ }
172
+
157
173
/**
158
174
* Adds a comment to the given Node
159
175
*
@@ -212,8 +228,7 @@ else if (e instanceof ConversionException)
212
228
* @param manager the manager
213
229
*/
214
230
@ SuppressWarnings ("unchecked" )
215
- public void fromNode (Section section , MapNode node , MapNode defaultNode ,
216
- ConverterManager manager ) throws ConversionException
231
+ public void fromNode (Section section , MapNode node , MapNode defaultNode , ConverterManager manager ) throws ConversionException
217
232
{
218
233
for (Field field : this .getReflectedFields (section .getClass ()))
219
234
{
@@ -240,10 +255,13 @@ public void fromNode(Section section, MapNode node, MapNode defaultNode,
240
255
}
241
256
}
242
257
243
- if (Section .class .isAssignableFrom (field .getType ()))
258
+ if (field .isAnnotationPresent (Converter .class ))
259
+ {
260
+ value = manager .getAnnotationConverter (field .getAnnotation (Converter .class ).value ()).fromNode (fieldNode , manager );
261
+ }
262
+ else if (Section .class .isAssignableFrom (field .getType ()))
244
263
{
245
- Section fillSection = SectionFactory .newSectionInstance ((Class <? extends Section >)field .getType (),
246
- section );
264
+ Section fillSection = SectionFactory .newSectionInstance ((Class <? extends Section >)field .getType (), section );
247
265
manager .convertFromNode ((MapNode )fieldNode , (MapNode )defaultNode .getNodeAt (fieldPath ), fillSection );
248
266
value = fillSection ;
249
267
}
0 commit comments