/*
 * Copyright 2016, 2017 by HeBIS (www.hebis.de).
 * 
 * This file is part of HeBIS project Gnd4Index.
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the code.  If not, see http://www.gnu.org/licenses/agpl>.
 */
package de.hebis.it.hds.gnd;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Model bean as singleton
 * 
 * @author Uwe Reh (uh), HeBIS-IT
 * @version 2017-05-12 uh initial version
 */
public class Model extends Properties {
   private static final long   serialVersionUID = 1L;
   private final static Logger LOG              = LogManager.getLogger(Model.class);
   private static Model        singleton        = null;
   private static final String configFileName   = "AutorityRecord.properties";

   /**
    * Private constructor, to avoid multiple instances. <br>
    * A reference can obtained from the factory {@link #getModel()}
    */
   private Model() {
      super();
      readConfigFile();
      LOG.debug("The model is created and initialized.");
   }

   /**
    * Factory to build exact on instance (Singelton)
    * 
    * @return The reference to the singelton.
    */
   public static synchronized Model getModel() {
      if (singleton == null) {
         LOG.debug("Build new instance.");
         singleton = new Model();
      }
      LOG.trace("Return the reference.");
      return singleton;
   }

   /**
    * Read the configuration file.
    */
   private void readConfigFile() {
      LOG.trace("Konfiguration einlesen");
      InputStream configStream = this.getClass().getClassLoader().getResourceAsStream(configFileName);
      if (configStream == null) System.class.getClassLoader().getResourceAsStream(configFileName);
      if (configStream == null) throw new RuntimeException("Config file \"" + configFileName + "\" couldn't be found in class path.");
      // config file found
      try {
         this.load(new InputStreamReader(configStream));
      } catch (IOException e) {
         e.printStackTrace();
         throw new RuntimeException("Error in loading: \"" + configFileName + "\".", e);
      }
      LOG.debug("Config file sucsessfully loaded");
      if (LOG.isTraceEnabled()) {
         for (Object key : this.keySet()) {
            LOG.trace("Konfig: " + key + " = " + this.getProperty((String) key));
         }
      }
   }
}

@@ -2170,52 +2170,8 @@
  %7B%0D%0A
-      LOG.trace(%22Konfiguration einlesen%22);%0D%0A
     
@@ -2203,27 +2203,8 @@
 m = 
-this.getClass().get
 Clas
@@ -2214,97 +2214,18 @@
 ader
-()
 .get
-ResourceAsStream(configFileName);%0D%0A      if (configStream == null) System.class.get
+System
 Clas
@@ -2303,16 +2303,28 @@
 == null)
+ %7B%0D%0A        
  throw n
@@ -2409,17 +2409,16 @@
 in class
- 
 path.%22);
@@ -2429,28 +2429,71 @@
     
-//
+%7D%0D%0A      LOG.debug(%22Found %22 +
  config
- file found
+FileName + %22in classpath%22);
 %0D%0A  
@@ -2668,18 +2668,21 @@
 (%22Error 
-in
+while
  loading
@@ -2951,24 +2951,24 @@
          %7D%0D%0A
-
       %7D%0D%0A   
@@ -2970,11 +2970,147 @@
 %0D%0A   %7D%0D%0A
+   %0D%0A   public static void main(String%5B%5D unused) %7B%0D%0A      Model me = Model.getModel();%0D%0A      System.out.println(me.toString());%0D%0A   %7D%0D%0A
 %7D%0D%0A

Switch from class.classloader to system.classloader