2020
2121import net .sourceforge .easyml .marshalling .CompositeStrategy ;
2222import net .sourceforge .easyml .marshalling .SimpleStrategy ;
23- import net .sourceforge .easyml .marshalling .custom .NodeListStrategy ;
24- import net .sourceforge .easyml .marshalling .custom .NodeStrategy ;
2523import org .xmlpull .v1 .XmlPullParser ;
2624
2725import java .lang .reflect .Field ;
4240 * .withCustomRootTag("Persons")
4341 * .withAlias(Person.class, "Person")
4442 * .withAlias(Person.class, "name", "Name")
43+ * .withStrategy(PersonStrategy.INSTANCE)
44+ * .withoutStrategy(CharsStrategy.INSTANCE)
4545 * .build();
4646 * </pre> Not all possible customizations are accessible through this builder.
4747 * Hence, in some cases, one must use the {@linkplain XMLReader}s and
48- * {@linkplain XMLWriter}s directly, for example:
49- * <br/>
50- * <pre>
51- * final XMLWriter w= easyml.newWriter(new FileWriter(FILE_NAME));
52- * w.writeInt(1);
53- * w.writeInt(2);
54- * w.write(obj1);
55- * //..
56- * w.write(objN);
57- * w.close();
58- * </pre>
59- * <br/>
48+ * {@linkplain XMLWriter}s directly.
49+ *
6050 * <b>Note:</b> this builder implementation is <b>not</b> thread-safe
6151 *
6252 * @author Victor Cordis ( cordis.victor at gmail.com)
63- * @version 1.5.0
53+ * @version 1.5.1
6454 * @see EasyML
6555 * @see XMLReader
6656 * @see XMLWriter
6757 * @since 1.4.0
6858 */
69- public final class EasyMLBuilder {
59+ public final class EasyMLBuilder implements Supplier < EasyML > {
7060
71- private EasyML .Profile profile ;
7261 private EasyML .Style style ;
7362 private Supplier <XmlPullParser > xmlPullParserProvider ;
7463 private String dateFormat ;
7564 private String customRootTag ;
76- private NodeListStrategy customArrayTag ;
77- private NodeStrategy customStringTag ;
7865 private Map <Class , String > classToAlias ;
7966 private Map <Field , String > fieldToAlias ;
8067 private Set <Field > excludedFields ;
@@ -84,16 +71,6 @@ public final class EasyMLBuilder {
8471 private Set <SimpleStrategy > unregisteredSimple ;
8572 private Set <CompositeStrategy > unregisteredComposite ;
8673
87- /**
88- * Sets the EasyML profile.
89- *
90- * @param profile to use
91- */
92- public EasyMLBuilder withProfile (EasyML .Profile profile ) {
93- this .profile = profile ;
94- return this ;
95- }
96-
9774 /**
9875 * Sets the XML outputting style.
9976 *
@@ -140,27 +117,6 @@ public EasyMLBuilder withCustomRootTag(String customRootTag) {
140117 return this ;
141118 }
142119
143- /**
144- * Sets the given custom XML tag name for arrays.
145- *
146- * @param customArrayTag to be used for arrays
147- * @param arrayType class of the array to use this custom tag
148- */
149- public EasyMLBuilder withCustomArrayTag (String customArrayTag , Class arrayType ) {
150- this .customArrayTag = new NodeListStrategy (customArrayTag , arrayType );
151- return this ;
152- }
153-
154- /**
155- * Sets the given custom XML tag name for strings.
156- *
157- * @param customStringTag to be used for strings
158- */
159- public EasyMLBuilder withCustomStringTag (String customStringTag ) {
160- this .customStringTag = new NodeStrategy (customStringTag );
161- return this ;
162- }
163-
164120 /**
165121 * Sets the given alias form the given class.
166122 *
@@ -321,13 +277,10 @@ public EasyML build() {
321277 }
322278 // build:
323279 return new EasyML (
324- profile ,
325280 style ,
326281 xmlPullParserProvider ,
327282 dateFormat ,
328283 customRootTag ,
329- customArrayTag ,
330- customStringTag ,
331284 classToAlias ,
332285 fieldToAlias ,
333286 excludedFields ,
@@ -338,4 +291,12 @@ public EasyML build() {
338291 unregisteredComposite
339292 );
340293 }
294+
295+ /**
296+ * {@inheritDoc}
297+ */
298+ @ Override
299+ public EasyML get () {
300+ return this .build ();
301+ }
341302}
0 commit comments