package de.jpaw.bonaparte.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Specifies the backreferencing strategy for some serializers.
 * The possible values are
 * <li>NONE - do not check for recurring objects (will destroy identities)
 * <li>BY_REFERENCE - check for recurring objects using the object reference identity (leaves identities untouched)
 * <li>BY_CONTENTS - check for recurring objects using object equality (possibly creates new identities)
 * It depends on the data, which approach is the fastest. In any case, the serialized size is smallest for BY_CONTENTS, followed by BY_REFERENCE.
 *
 */
public enum ObjectReuseStrategy {
    NONE, BY_REFERENCE, BY_CONTENTS;
    
    private static final Logger LOGGER = LoggerFactory.getLogger(ObjectReuseStrategy.class);
    static public ObjectReuseStrategy defaultStrategy = NONE;
    static {
        // read the system default via property, if allowed
        try {
            String sysDefault = System.getProperty("bonaparte.defaultReuseStrategy");
            if (sysDefault != null) {
                if ("BY_REFERENCE".equals(sysDefault))
                    defaultStrategy = BY_REFERENCE;
                else if ("BY_CONTENTS".equals(sysDefault))
                    defaultStrategy = BY_CONTENTS;
                else if ("BY_CONTENTS".equals(sysDefault))
                    defaultStrategy = BY_CONTENTS;
                else if ("NONE".equals(sysDefault))
                    defaultStrategy = NONE;
                else
                    LOGGER.warn("Unknown system default reuseStrategy: {}", sysDefault);
            }
        } catch (Exception e) {
            // low log level, as this is an optional feature and warnings may be annoying
            LOGGER.debug("cannot access system properties");
        }
    }
}

@@ -26,16 +26,74 @@
 .core;%0A%0A
+import java.io.InputStream;%0Aimport java.util.Properties;%0A%0A
 import o
@@ -109,16 +109,16 @@
 Logger;%0A
-
 import o
@@ -927,16 +927,690 @@
 tatic %7B%0A
+        // read from properties file%0A        String path = %22/META-INF/maven/de.jpaw/bonaparte-core/pom.properties%22;%0A        String version = %22UNKNOWN%22;%0A        %0A        Properties prop = new Properties();%0A        InputStream in = ObjectReuseStrategy.class.getResourceAsStream(path );%0A        try %7B%0A            prop.load(in);%0A            version = prop.getProperty(%22version%22);%0A        %7D catch (Exception e) %7B%0A            // have no properties =%3E version is unknown%0A            LOGGER.debug(%22cannot access maven properties: %22, e);%0A        %7D finally %7B%0A            try %7B%0A                in.close();%0A            %7D catch (Exception ex) %7B%0A                %0A            %7D%0A        %7D%0A%0A
         
@@ -2525,24 +2525,24 @@
 operties%22);%0A
-
         %7D%0A  
@@ -2535,20 +2535,129 @@
 ;%0A        %7D%0A
+        LOGGER.info(%22Starting BONAPARTE-java version %7B%7D using reuse strategy %7B%7D%22, version, defaultStrategy);%0A
     %7D%0A%7D%0A

add info log