3434import net .sourceforge .easyml .marshalling .java .util .*;
3535import net .sourceforge .easyml .marshalling .java .util .concurrent .ConcurrentHashMapStrategy ;
3636import net .sourceforge .easyml .marshalling .java .util .regex .PatternStrategy ;
37- import net .sourceforge .easyml .util .Caching ;
3837import org .w3c .dom .Document ;
3938import org .xmlpull .v1 .XmlPullParser ;
4039
4342import java .util .Map ;
4443import java .util .Set ;
4544import java .util .concurrent .ConcurrentHashMap ;
45+ import java .util .function .Supplier ;
4646
4747/**
4848 * EasyML class is the top-level facade, containing general functionality such
8181 * objects.<br/>
8282 *
8383 * @author Victor Cordis ( cordis.victor at gmail.com)
84- * @version 1.4.6
84+ * @version 1.5.0
8585 * @see XMLReader
8686 * @see XMLWriter
8787 * @since 1.0
@@ -383,32 +383,6 @@ public void configure(XMLReader reader) {
383383 public abstract void configure (XMLReader reader );
384384 }
385385
386- /**
387- * XmlPullParserProvider interface can be implemented to provide a custom
388- * {@linkplain XmlPullParser} to be used at deserializing XML, in text form.
389- * <br/>
390- * Since EasyML is thread-safe, it cannot reuse the user-specified
391- * pull-parser instance, like {@linkplain XMLReader} does. This interface
392- * implementation will be used by EasyML at each text XML
393- * <code>deserialize()</code> invocation.<br/>
394- * <br/>
395- * <b>Note:</b> implementations of this interface MUST be thread-safe.
396- *
397- * @author Victor Cordis ( cordis.victor at gmail.com)
398- * @version 1.3.0
399- * @since 1.3.0
400- */
401- public interface XmlPullParserProvider {
402-
403- /**
404- * Creates and configures a new user-specified
405- * <code>XmlPullParser</code> parser, to be used at text XML parsing.
406- *
407- * @return new xml pull-parser instance
408- */
409- XmlPullParser newXmlPullParser ();
410- }
411-
412386 /**
413387 * Constant defining the default EasyML profile setting.
414388 */
@@ -435,7 +409,7 @@ public interface XmlPullParserProvider {
435409 /**
436410 * The preferred parser configuration. Is optional.
437411 */
438- protected XmlPullParserProvider xmlPullParserProvider = null ;
412+ protected Supplier < XmlPullParser > xmlPullParserProvider = null ;
439413
440414 /**
441415 * Creates a new instance with the default settings and default reader and
@@ -446,28 +420,15 @@ public EasyML() {
446420 }
447421
448422 private EasyML (Profile profile ) {
449- final ConcurrentHashMap <Class , Object > commonCtorCache = new ConcurrentHashMap <>();
450- final ConcurrentHashMap <String , Object > readerFieldCache = new ConcurrentHashMap <>();
451-
452- this .writerPrototype = new XMLWriter (commonCtorCache , Caching .STRATEGY_PUT_IF_ABSENT );
453- this .readerPrototype = new XMLReader (commonCtorCache , readerFieldCache , Caching .STRATEGY_PUT_IF_ABSENT );
423+ this .writerPrototype = new XMLWriter ();
424+ this .readerPrototype = new XMLReader (new ConcurrentHashMap <>());
454425 profile .configure (this .writerPrototype );
455426 profile .configure (this .readerPrototype );
456- this .perThreadWriter = new ThreadLocal <XMLWriter >() {
457- @ Override
458- protected XMLWriter initialValue () {
459- return new XMLWriter (writerPrototype );
460- }
461- };
462- this .perThreadReader = new ThreadLocal <XMLReader >() {
463- @ Override
464- protected XMLReader initialValue () {
465- return new XMLReader (readerPrototype );
466- }
467- };
427+ this .perThreadWriter = ThreadLocal .withInitial (() -> new XMLWriter (writerPrototype ));
428+ this .perThreadReader = ThreadLocal .withInitial (() -> new XMLReader (readerPrototype ));
468429 }
469430
470- EasyML (Profile profile , Style style , XmlPullParserProvider xmlPullParserProvider ,
431+ EasyML (Profile profile , Style style , Supplier < XmlPullParser > xmlPullParserProvider ,
471432 String dateFormat , String customRootTag , NodeListStrategy customArrayTag , NodeStrategy customStringTag ,
472433 Map <Class , String > classToAlias , Map <Field , String > fieldToAlias , Set <Field > excludedFields ,
473434 XMLReader .SecurityPolicy deserializationSecurityPolicy ,
@@ -747,7 +708,7 @@ public void serialize(Object o, OutputStream out) {
747708 * @return the serialized object string
748709 */
749710 public String serialize (Object o ) {
750- final StringWriter sw = new StringWriter (32 );
711+ final StringWriter sw = new StringWriter ();
751712 this .serialize (o , sw );
752713 return sw .toString ();
753714 }
@@ -784,9 +745,7 @@ public Object deserialize(Reader in) {
784745 }
785746
786747 private XmlPullParser maybeProvidedXmlPullParser () {
787- return this .xmlPullParserProvider != null
788- ? this .xmlPullParserProvider .newXmlPullParser ()
789- : null ;
748+ return this .xmlPullParserProvider != null ? this .xmlPullParserProvider .get () : null ;
790749 }
791750
792751 /**
0 commit comments