Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log for javapos-config-loader

## 5.0.0

- replaced legacy logging implementation by the logging facade SLF4J version 1, see https://www.slf4j.org/ for details on how to integrate

## 4.0.2

- fixed resource loading from JAR file on the class-path (contributed by @art-and-co through [PR #13](https://github.com/JavaPOSWorkingGroup/javapos-config-loader/issues/13))
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ wrapper {

def artifactName = 'javapos-config-loader'
group='org.javapos'
version='4.0.2-SNAPSHOT' // if version is going to be changed, first add "-SNAPSHOT" to test publishing to MavenCentral's Snapshot repo
version='5.0.0-SNAPSHOT' // if version is going to be changed, first add "-SNAPSHOT" to test publishing to MavenCentral's Snapshot repo


///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -65,9 +65,11 @@ def testResourceDir = file("${System.properties['java.io.tmpdir']}/javapos-confi

dependencies {
api 'org.javapos:javapos-contracts:1.6.0'
implementation 'org.slf4j:slf4j-api:1.7.36'

testImplementation("junit:junit:4.13.2")

testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.36'
testRuntimeOnly files(testResourceDir)
}

Expand Down
50 changes: 19 additions & 31 deletions src/main/java/jpos/config/DefaultCompositeRegPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import jpos.loader.*;
import jpos.util.*;
import jpos.util.tracing.Tracer;
import jpos.util.tracing.TracerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Default implementation of the CompositeRegPopulator interface
Expand All @@ -34,6 +34,8 @@
*/
public class DefaultCompositeRegPopulator implements CompositeRegPopulator
{
private static final Logger log = LoggerFactory.getLogger(DefaultCompositeRegPopulator.class);

//-------------------------------------------------------------------------
// Ctor(s)
//
Expand Down Expand Up @@ -91,27 +93,23 @@ private JposRegPopulator createPopulator( String popName, String className )
}
catch( ClassNotFoundException cnfe )
{
tracer.println( "Could not find populator class with name: " +
className + " exception message = " +
cnfe.getMessage() );
log.error( "Could not find populator class with name: {} exception message = {}",
className, cnfe.getMessage() );
}
catch( NoSuchMethodException nsme )
{
tracer.println( "Populator by class name: " +
className +
" must define a no-arg ctor or a 1-arg ctor with String param as the unique ID" );
log.error( "Populator by class name: {} must define a no-arg ctor or a 1-arg ctor with String param as the unique ID",
className );
}
catch( InstantiationException ie )
{
tracer.println( "Could not instantiate populator class with name: " +
className + " exception message = " +
ie.getMessage() );
log.error( "Could not instantiate populator class with name: {} exception message = {}",
className, ie.getMessage() );
}
catch( Exception e )
{
tracer.println( "Could not instantiate populator class with name: " +
className + " exception message = " +
e.getMessage() );
log.error( "Could not instantiate populator class with name: {} exception message = {}",
className, e.getMessage() );
}

return populator;
Expand Down Expand Up @@ -187,9 +185,7 @@ public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exc
List<JposEntry> entryList = popEntriesMap.get( populator.getUniqueId() );

if( entryList == null )
tracer.println( "Trying to save entry with logicalName = " +
entry.getLogicalName() +
" and populator with" );
log.debug( "Trying to save entry with logicalName = {} and populator with entry list null", entry.getLogicalName() );
else
entryList.add( entry );
}
Expand All @@ -214,8 +210,7 @@ public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exc
catch( Exception e )
{
exception = e;
tracer.println( "Error while saving to populator with unique ID:" +
populator.getUniqueId() );
log.error( "Error while saving to populator with unique ID: {}", populator.getUniqueId() );
}
}

Expand Down Expand Up @@ -254,7 +249,7 @@ public void load()

if( populatorClassMultiProp == null || populatorClassMultiProp.getNumberOfProperties() == 0 )
{
tracer.println( "CompositeRegPopulator.load() w/o any defined multi-property" );
log.error( "CompositeRegPopulator.load() w/o any defined multi-property" );
throw new IllegalArgumentException( "CompositeRegPopulator.load() w/o any defined multi-property" );
}

Expand All @@ -281,8 +276,7 @@ public void load()
}
else
{
tracer.println( "Created default populator with name = " + defaultPopName +
" OK but populator file is null" );
log.debug( "Created default populator with name = {} OK but populator file is null", defaultPopName );
defaultPopulator.load();
lastLoadException = defaultPopulator.getLastLoadException();
}
Expand All @@ -296,8 +290,7 @@ public void load()
setDefaultPopulator( defaultPopulator );
}
else
tracer.println( "Did not add default populator by <name, className>: " +
"<" + defaultPopName + ", " + defaultPopClass + ">" );
log.debug( "Did not add default populator by <name, className>: <{}, {}>", defaultPopName, defaultPopClass);
while( popClasses.hasNext() )
{
String popName = popClasses.next();
Expand All @@ -316,17 +309,15 @@ public void load()
}
else
{
tracer.println( "Created populator with name = " + popName +
" OK but populator file is null" );
log.debug( "Created populator with name = {} OK but populator file is null", popName );
populator.load();
lastLoadException = populator.getLastLoadException();
}

add( populator );
}
else
tracer.println( "Did not add populator by <name, className>: " +
"<" + popName + ", " + popClass + ">" );
log.debug( "Did not add populator by <name, className>: <{}, {}>", popName, popClass );
}
}

Expand Down Expand Up @@ -432,7 +423,4 @@ public JposRegPopulator getPopulator( String uniqueId )
private HashMap<String, String> popFileMap = new HashMap<>();
private JposRegPopulator defaultPop = null;
private Exception lastLoadException = null;

private Tracer tracer = TracerFactory.getInstance().
createTracer( "DefaultCompositeRegPopulator" );
}
31 changes: 12 additions & 19 deletions src/main/java/jpos/config/simple/AbstractRegPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import jpos.loader.JposServiceLoader;
import jpos.util.JposProperties;
import jpos.util.JposPropertiesConst;
import jpos.util.tracing.Tracer;
import jpos.util.tracing.TracerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Common abstract superclass to help in the implementation of the
Expand All @@ -39,6 +39,8 @@
*/
public abstract class AbstractRegPopulator implements JposRegPopulator
{
private static final Logger log = LoggerFactory.getLogger(AbstractRegPopulator.class);

//-------------------------------------------------------------------------
// Ctor(s)
//
Expand Down Expand Up @@ -115,8 +117,7 @@ protected URL createURLFromFile( File file )
{ url = new URL( "file", "", file.getAbsolutePath() ); }
catch( Exception e )
{
tracer.println( "Error creating URL: Exception.message=" +
e.getMessage() );
log.error( "Error creating URL: Exception.message={}", e.getMessage() );
}

return url;
Expand All @@ -138,8 +139,7 @@ protected URL createURLFromFile( ZipFile zipFile )
}
catch( Exception e )
{
tracer.println( "Error creating URL: Exception.message=" +
e.getMessage() );
log.error( "Error creating URL: Exception.message={}", e.getMessage() );
}

return url;
Expand Down Expand Up @@ -213,8 +213,7 @@ protected InputStream getPopulatorFileIS() throws Exception
jposProperties.getPropertyString(
JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME );

tracer.println( "getPopulatorFileIS(): populatorFileName=" +
populatorFileName );
log.debug( "getPopulatorFileIS(): populatorFileName={}", populatorFileName );

populatorIS = new FileInputStream( populatorFileName );
}
Expand All @@ -229,15 +228,14 @@ protected InputStream getPopulatorFileIS() throws Exception

populatorIS = url.openStream();

tracer.println( "getPopulatorFileIS(): populatorFileURL=" +
populatorFileURL );
log.debug( "getPopulatorFileIS(): populatorFileURL={}", populatorFileURL );
}
else
{
String msg = "jpos.config.populatorFile OR " +
" jpos.config.populatorFileURL properties not defined";

tracer.println( msg );
log.error( msg );

throw new Exception( msg );
}
Expand Down Expand Up @@ -284,7 +282,7 @@ protected OutputStream getPopulatorFileOS() throws Exception
String msg = "jpos.config.populatorFile OR " +
"jpos.config.populatorFileURL properties not defined";

tracer.println( msg );
log.error( msg );

throw new Exception( msg );
}
Expand Down Expand Up @@ -338,8 +336,7 @@ protected InputStream findFileInClasspath( String fileName )
{
is = null;

tracer.println( "findFileInClasspath: IOException.msg=" +
ioe.getMessage() );
log.error( "findFileInClasspath: IOException.msg={}", ioe.getMessage() );
}

return is;
Expand Down Expand Up @@ -438,8 +435,7 @@ private InputStream findFileInJarZipFiles( String fileName, List<String> jarZipF
}
catch( Exception e )
{
tracer.println( "findInJarZipFiles: Exception.message=" +
e.getMessage() );
log.error( "findInJarZipFiles: Exception.message={}", e.getMessage() );
}
}

Expand All @@ -458,7 +454,4 @@ private InputStream findFileInJarZipFiles( String fileName, List<String> jarZipF
private String uniqueId = "";

protected Exception lastLoadException = null;

private Tracer tracer = TracerFactory.getInstance().
createTracer( "AbstractRegPopulator" );
}
38 changes: 17 additions & 21 deletions src/main/java/jpos/config/simple/SimpleEntryRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import jpos.config.*;

import jpos.util.tracing.Tracer;
import jpos.util.tracing.TracerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is a simple implementation for the JposEntryRegistry using a Hashtable
Expand All @@ -35,6 +35,8 @@
*/
public class SimpleEntryRegistry implements JposEntryRegistry
{
private static final Logger log = LoggerFactory.getLogger(SimpleEntryRegistry.class);

/**
* One-argument constructor
* @param populator the JposRegPopulator used by the registry
Expand Down Expand Up @@ -89,7 +91,7 @@ public void modifyJposEntry( String logicalName, JposEntry newEntry )
{
jposEntries.put( logicalName, newEntry );

tracer.println( "Modified entry.logicalName = " + logicalName );
log.debug( "Modified entry.logicalName = {}", logicalName );

fireJposEntryRegistryEventModified( new JposEntryRegistryEvent(
this, newEntry ) );
Expand All @@ -104,7 +106,7 @@ public void addJposEntry( String logicalName, JposEntry entry )
{
jposEntries.put( logicalName, entry );

tracer.println( "Added entry.logicalName = " + logicalName );
log.debug( "Added entry.logicalName = {}", logicalName );

fireJposEntryRegistryEventAdded( new JposEntryRegistryEvent(
this, entry ) );
Expand Down Expand Up @@ -141,8 +143,7 @@ public void removeJposEntry( JposEntry entry )
jposEntries.remove( entry.getPropertyValue( JposEntry.
LOGICAL_NAME_PROP_NAME ) );

tracer.println( "Removed entry.logicalName = " +
entry.getLogicalName() );
log.debug( "Removed entry.logicalName = {}", entry.getLogicalName() );

fireJposEntryRegistryEventRemoved( new JposEntryRegistryEvent(
this, removedEntry ) );
Expand All @@ -151,8 +152,7 @@ public void removeJposEntry( JposEntry entry )
}
}

tracer.println( "Could not find entry to remove entry.logicalName = " +
entry.getLogicalName() );
log.debug( "Could not find entry to remove entry.logicalName = {}", entry.getLogicalName() );
}

/**
Expand Down Expand Up @@ -236,7 +236,9 @@ public void load()

jposEntries.put( jposEntry.getLogicalName(), jposEntry );
}
catch( Exception e ) { tracer.print( e ); }
catch( Exception e ) {
log.error( e.getMessage() );
}
}

loaded = true;
Expand Down Expand Up @@ -305,9 +307,8 @@ public String toString()
*/
protected void fireJposEntryRegistryEventAdded( JposEntryRegistryEvent e )
{
tracer.println( "fireJposEntryRegistryEventAdded: " +
"e.getJposEntry().logicalName = " +
e.getJposEntry().getLogicalName() );
log.debug( "fireJposEntryRegistryEventAdded: e.getJposEntry().logicalName = {}",
e.getJposEntry().getLogicalName() );

@SuppressWarnings("unchecked")
Vector<JposEntryRegistryListener> listenersClone = (Vector<JposEntryRegistryListener>) listeners.clone();
Expand All @@ -327,9 +328,8 @@ protected void fireJposEntryRegistryEventAdded( JposEntryRegistryEvent e )
*/
protected void fireJposEntryRegistryEventRemoved( JposEntryRegistryEvent e )
{
tracer.println( "fireJposEntryRegistryEventRemoved: " +
"e.getJposEntry().logicalName = " +
e.getJposEntry().getLogicalName() );
log.debug( "fireJposEntryRegistryEventRemoved: e.getJposEntry().logicalName = {}",
e.getJposEntry().getLogicalName() );

@SuppressWarnings("unchecked")
Vector<JposEntryRegistryListener> listenersClone = (Vector<JposEntryRegistryListener>) listeners.clone();
Expand All @@ -348,9 +348,8 @@ protected void fireJposEntryRegistryEventRemoved( JposEntryRegistryEvent e )
*/
protected void fireJposEntryRegistryEventModified( JposEntryRegistryEvent e )
{
tracer.println( "fireJposEntryRegistryEventModified: " +
"e.getJposEntry().logicalName = " +
e.getJposEntry().getLogicalName() );
log.debug( "fireJposEntryRegistryEventModified: e.getJposEntry().logicalName = {}",
e.getJposEntry().getLogicalName() );

@SuppressWarnings("unchecked")
Vector<JposEntryRegistryListener> listenersClone = (Vector<JposEntryRegistryListener>) listeners.clone();
Expand All @@ -370,7 +369,4 @@ protected void fireJposEntryRegistryEventModified( JposEntryRegistryEvent e )
private final Vector<JposEntryRegistryListener> listeners = new Vector<>();
private JposRegPopulator regPopulator = null;
private boolean loaded = false;

private Tracer tracer = TracerFactory.getInstance().
createTracer( "SimpleEntryRegistry" );
}
Loading
Loading