Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3fc6ff6
Assignments of typed values via deprecated constructors replaced by
mjpcger Dec 18, 2023
f596e3d
Avoid IllegalArgumentExceptions if an optional URL related XML attribute
mjpcger Dec 22, 2023
24284a3
Using scalar types' .valueOf method instead of auto-boxing
kuniss May 27, 2024
9736fde
Code clean-up: Get rid of raw types and Vector usage at JposEntryUtility
kuniss May 27, 2024
1592d15
Code clean-up: simplified negated boolean expressions
kuniss May 27, 2024
8eee5d5
Avoiding file resources remaining unclosed for the SimpleRegPopulator
kuniss Jun 27, 2024
468949d
Fixing a NPE in case multi-prop definition is missing in jpos.properties
kuniss Jun 27, 2024
eb728a1
Code cleanup: Got rid of compile warning, introduce generics
kuniss Jun 27, 2024
68c6eae
Code cleanup: get rid of a dead code warning
kuniss Jun 28, 2024
32f5361
Code cleanup: get rid of some code smell
kuniss Jun 28, 2024
a7194eb
Removed deprecated constructors and deprecated Tracer class
kuniss Jun 28, 2024
abb4e30
Initial Javax based XML populator implementation to replace Xerces
mjpcger Dec 18, 2023
609ba00
Changes made after PR being reviewed
mjpcger Mar 15, 2024
f005370
Refactored out string as constants to XmlRegPopulator
mjpcger Mar 15, 2024
fd0a2f6
Replaced Xerces populator by new Javax populator.
mjpcger Dec 18, 2023
ef2e594
Code cleanup: get rid of some warnings
mjpcger Jun 28, 2024
881797b
Corrected an initialization error when reloading to the same populator
kuniss Jun 28, 2024
bcd9ee0
Code cleanup for the new JavaxRegPopulator test case.
kuniss Jun 28, 2024
e35f8ad
Added assertions checking getLastLoadException is null.
kuniss Jul 1, 2024
f1e9743
Re-implemented method insertJposPropertiesInElement
kuniss Jul 1, 2024
a67824b
Code cleanup: Get rid of all javadoc warnigs and errors.
kuniss Jul 1, 2024
a051805
Code cleanup: Replaced iterator loop by for-each loop.
kuniss Jul 1, 2024
c4a395a
Restricted access to DTD files while loading JavaPOS XML configuration.
kuniss Jul 1, 2024
faedec2
Avoiding XSD resource remains unclosed.
kuniss Jul 1, 2024
f0087c9
Rolled back 2 generic type improvements to ensure backward compatibility
kuniss Jul 1, 2024
5b281be
Code cleanup: some code formatting improvements.
kuniss Jul 2, 2024
888a23f
Get rid of Xerces in the ProfileFactory implementation.
kuniss Jul 2, 2024
c6b1785
Added test case for DefaultProfileFactory.
kuniss Jul 2, 2024
cd1c268
Finally, removed Xerces dependencies.
kuniss Jul 2, 2024
fa68e30
Code cleanup: Removed all "extends Object" declarations
kuniss Jul 3, 2024
4cf4ef8
Added change notes related to code improvements
kuniss Jul 3, 2024
a43f15f
Added change notes related to Xerces removal
kuniss Jul 3, 2024
2799f94
Merge xerces-replacement-from-pr7 into 4.0-improvements+without-xerces
kuniss Jul 3, 2024
996bc63
Deleted the conflicting Xerces2RegPopulator.java subsequently
kuniss Jul 3, 2024
de7fd8a
Code cleanup: get rid of deprecated method calls
kuniss Jul 3, 2024
44f81b8
Enabling for webstart environments by solving issue #1
kuniss Jul 3, 2024
f0d9516
Prepares versions for 4.0 releasing.
kuniss Jul 3, 2024
07d1d01
Code cleanup: I removed empty comments for serial UIDs
kuniss Jul 5, 2024
bc04607
Replaced legacy trace enabling at tests by new one.
kuniss Jul 12, 2024
46b6148
Enabled tracing at tests by default.
kuniss Jul 12, 2024
4c424d4
Revert "Enabled tracing at tests by default."
kuniss Jul 12, 2024
5777a90
Enabled tracing on tests by default.
kuniss Jul 12, 2024
fc0877a
Improved tracing to log the valuable information.
kuniss Jul 12, 2024
edff527
Code clean up for some generic type issues.
kuniss Jul 16, 2024
b579f60
Trim tracer names from jpos.util.tracing.TurnOnNamedTracers definition.
kuniss Jul 16, 2024
2307d19
Replaced XercesProfileFactory.java by DefaultProfileFactory.java
kuniss Jul 18, 2024
d87273a
load() at composite populators throw a more specific runtime exception
kuniss Jul 18, 2024
f075aaa
Code cleanup: made code less complex
kuniss Jul 18, 2024
24aea5a
Code improvements regarding try-with-resouce and Files.delete() in
kuniss Jul 18, 2024
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Change Log for javapos-config-loader

## 4.0.0

- jpos.config.DefaultCompositeRegPopulator.load() is throwing more specific IllegalArgument exception instead of RuntimeException
- added Javax XML parser based XML registry populator implementation (contributed by @mjpcger)
- removed Xerces based XML registry populator implementations, mainly
- `jpos.config.simple.xml.XercesRegPopulator`
- `jpos.config.simple.xml.Xerces2RegPopulator`
- removed Xerces dependency at all, thus, it does not appear as transitive dependency in the Maven POM anymore
- added JavaPOS XML node name, attribute name, and fixed file names as constants to `jpos.config.simple.xml.JavaxRegPopulator` making them available for all (proprietary) XML implementations
- restricted XML parser's DTD and XSD resources access for security reasons
- renamed `jpos.profile.XercesProfileFactory` to `jpos.profile.DefaultProfileFactory`
- ensure all resources are well closed by stringent use of try-with-resource clauses
- fixing a NPE in case multi-propo definition is missing
- removed deprecated constructors at
- `jpos.config.simple.SimpleEntryRegistry`, and
- `jpos.loader.simple.SimpleServiceManager`
- removed deprecated class `jpos.util.Tracer`
- ensure compatibility to webstart environments by using standard class-loader instead of the system class-loader (solves issue #1)

## 3.1.0

- Added missing devices to XML schema/DTD files and as DevCat interfaces (contribution by [@dougberkland](https://github.com/dougberkland))
Expand Down
3 changes: 1 addition & 2 deletions 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='3.1.0' // if version is going to be changed, first add "-SNAPSHOT" to test publishing to MavenCentral's Snapshot repo
version='4.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 @@ -64,7 +64,6 @@ if (System.getenv('CI') && null == findProperty('github.event.action'))
def testResourceDir = file("${System.properties['java.io.tmpdir']}/javapos-config-loader-test/resources")

dependencies {
api 'xerces:xerces:1.2.3'
api 'org.javapos:javapos-contracts:1.6.0'

testImplementation("junit:junit:4.13.2")
Expand Down
1 change: 1 addition & 0 deletions src/main/java/jpos/config/CompositeRegPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface CompositeRegPopulator extends JposRegPopulator
public void remove( JposRegPopulator populator );

/** @return an iterator over all populators in this composite */
@SuppressWarnings("rawtypes")
public Iterator getPopulators();

/**
Expand Down
120 changes: 60 additions & 60 deletions src/main/java/jpos/config/DefaultCompositeRegPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
* @since 1.3 (Washington DC 2001 meeting)
* @author E. Michael Maximilien (maxim@us.ibm.com)
*/
public class DefaultCompositeRegPopulator extends Object
implements CompositeRegPopulator
public class DefaultCompositeRegPopulator implements CompositeRegPopulator
{
//-------------------------------------------------------------------------
// Ctor(s)
Expand Down Expand Up @@ -73,19 +72,19 @@ private JposRegPopulator createPopulator( String popName, String className )

try
{
Class popClass = Class.forName( className );
Class<?> popClass = Class.forName( className );

try
{
Class[] ctorParamTypes = { String.class };
Constructor ctor = popClass.getConstructor( ctorParamTypes );
Class<?>[] ctorParamTypes = { String.class };
Constructor<?> ctor = popClass.getConstructor( ctorParamTypes );

Object[] args = { popName };
populator = (JposRegPopulator)ctor.newInstance( args );
}
catch( NoSuchMethodException nsme )
{
Constructor ctor = popClass.getConstructor( new Class[ 0 ] );
Constructor<?> ctor = popClass.getConstructor( new Class[ 0 ] );
populator = (JposRegPopulator)ctor.newInstance( new Object[ 0 ] );
}

Expand Down Expand Up @@ -164,34 +163,28 @@ public String getClassName()
* @param entries an enumeration of JposEntry objects
* @throws java.lang.Exception if any error occurs while saving
*/
public void save( Enumeration entries ) throws Exception
public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exception
{
HashMap popEntriesMap = new HashMap();
HashMap<String, List<JposEntry>>popEntriesMap = new HashMap<>();

Iterator popIterator = popMap.values().iterator();
Iterator<JposRegPopulator> popIterator = popMap.values().iterator();
while( popIterator.hasNext() )
popEntriesMap.put( ( (JposRegPopulator)popIterator.next() ).
getUniqueId(),
new ArrayList() );
popEntriesMap.put( ( popIterator.next() ).getUniqueId(), new ArrayList<>() );

while( entries.hasMoreElements() )
{
JposEntry entry = (JposEntry)entries.nextElement();

JposRegPopulator populator = (JposRegPopulator)entry.
getRegPopulator();
JposRegPopulator populator = entry.getRegPopulator();

if( populator == null )
{
Collection defaultEntryList = (Collection)popEntriesMap.
get( getDefaultPopulator().
getUniqueId() );
List<JposEntry> defaultEntryList = popEntriesMap.get( getDefaultPopulator().getUniqueId() );
defaultEntryList.add( entry );
}
else
{
Collection entryList = (Collection)popEntriesMap.
get( populator.getUniqueId() );
List<JposEntry> entryList = popEntriesMap.get( populator.getUniqueId() );

if( entryList == null )
tracer.println( "Trying to save entry with logicalName = " +
Expand All @@ -206,17 +199,17 @@ public void save( Enumeration entries ) throws Exception
popIterator = popMap.values().iterator();
while( popIterator.hasNext() )
{
JposRegPopulator populator = (JposRegPopulator)popIterator.next();
JposRegPopulator populator = popIterator.next();
String popUniqueId = populator.getUniqueId();
Collection entryList = (Collection)popEntriesMap.get( popUniqueId );
List<JposEntry> entryList = popEntriesMap.get( popUniqueId );

try
{
if( popFileMap.get( populator.getUniqueId() ) != null )
populator.save( new Vector( entryList ).elements(),
(String)popFileMap.get( populator.getUniqueId() ) );
populator.save( Collections.enumeration(entryList),
popFileMap.get( populator.getUniqueId() ) );
else
populator.save( new Vector( entryList ).elements() );
populator.save( Collections.enumeration(entryList) );
}
catch( Exception e )
{
Expand All @@ -236,7 +229,7 @@ public void save( Enumeration entries ) throws Exception
* @param fileName the file name to save entries
* @throws java.lang.Exception if any error occurs while saving
*/
public void save( Enumeration entries, String fileName ) throws Exception
public void save( @SuppressWarnings("rawtypes") Enumeration entries, String fileName ) throws Exception
{
getDefaultPopulator().save( entries, fileName );
}
Expand All @@ -254,57 +247,60 @@ public void load()
JposProperties jposProperties = JposServiceLoader.getManager().getProperties();

JposProperties.MultiProperty populatorClassMultiProp =
jposProperties.getMultiProperty( JposProperties.JPOS_CONFIG_POPULATOR_CLASS_MULTIPROP_NAME );
jposProperties.getMultiProperty( JposPropertiesConst.JPOS_CONFIG_POPULATOR_CLASS_MULTIPROP_NAME );

JposProperties.MultiProperty populatorFileMultiProp =
jposProperties.getMultiProperty( JposProperties.JPOS_CONFIG_POPULATOR_FILE_MULTIPROP_NAME );
jposProperties.getMultiProperty( JposPropertiesConst.JPOS_CONFIG_POPULATOR_FILE_MULTIPROP_NAME );

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

Iterator popClasses = populatorClassMultiProp.getSortedPropertyNames();
@SuppressWarnings("unchecked")
Iterator<String> popClasses = populatorClassMultiProp.getSortedPropertyNames();

String defaultPopName = (String)popClasses.next();
String defaultPopName = popClasses.next();
String defaultPopClass = populatorClassMultiProp.getPropertyString( defaultPopName );
int defaultPopClassNumber = populatorClassMultiProp.propertyNumber( defaultPopName );

JposRegPopulator defaultPopulator = createPopulator( defaultPopName, defaultPopClass );

if( populatorFileMultiProp != null && populatorFileMultiProp.getNumberOfProperties() > 0 )
{
String defaultPopFile = (String)populatorFileMultiProp.getPropertyString( defaultPopClassNumber );

if( defaultPopFile != null )
if( defaultPopulator != null ) {

if( populatorFileMultiProp != null && populatorFileMultiProp.getNumberOfProperties() > 0 )
{
defaultPopulator.load( defaultPopFile );
lastLoadException = defaultPopulator.getLastLoadException();
popFileMap.put( defaultPopulator.getUniqueId(), defaultPopFile );
String defaultPopFile = populatorFileMultiProp.getPropertyString( defaultPopClassNumber );

if( defaultPopFile != null )
{
defaultPopulator.load( defaultPopFile );
lastLoadException = defaultPopulator.getLastLoadException();
popFileMap.put( defaultPopulator.getUniqueId(), defaultPopFile );
}
else
{
tracer.println( "Created default populator with name = " + defaultPopName +
" OK but populator file is null" );
defaultPopulator.load();
lastLoadException = defaultPopulator.getLastLoadException();
}
}
else
{
tracer.println( "Created default populator with name = " + defaultPopName +
" OK but populator file is null" );
defaultPopulator.load();
lastLoadException = defaultPopulator.getLastLoadException();
}
}
else
{
defaultPopulator.load();
lastLoadException = defaultPopulator.getLastLoadException();
}

if( defaultPopulator != null )
setDefaultPopulator( defaultPopulator );
}
else
tracer.println( "Did not add default populator by <name, className>: " +
"<" + defaultPopName + ", " + defaultPopClass + ">" );
while( popClasses.hasNext() )
{
String popName = (String)popClasses.next();
String popName = popClasses.next();
String popClass = populatorClassMultiProp.getPropertyString( popName );
int popClassNumber = populatorClassMultiProp.propertyNumber( popName );

Expand All @@ -314,7 +310,7 @@ public void load()
{
if( populatorFileMultiProp != null && populatorFileMultiProp.getNumberOfProperties() > 0 )
{
String popFile = (String)populatorFileMultiProp.getPropertyString( popClassNumber );
String popFile = populatorFileMultiProp.getPropertyString( popClassNumber );
populator.load( popFile );
popFileMap.put( populator.getUniqueId(), popFile );
}
Expand Down Expand Up @@ -349,21 +345,24 @@ public void load()
* number of entries in populator. Could do better by keeping more data structure
* but not worth it if n and m are small (as expected in typical system)
*/
public Enumeration getEntries()
@SuppressWarnings("rawtypes")
public Enumeration getEntries()
{
Vector entryVector = new Vector();
Iterator populators = getPopulators();
List<JposEntry> entryList = new ArrayList<>();
@SuppressWarnings("unchecked")
Iterator<JposRegPopulator> populators = getPopulators();

while( populators.hasNext() )
{
JposRegPopulator pop = (JposRegPopulator)populators.next();
JposRegPopulator pop = populators.next();

Enumeration entries = pop.getEntries();
@SuppressWarnings("unchecked")
Enumeration<JposEntry> entries = pop.getEntries();
while( entries.hasMoreElements() )
entryVector.add( entries.nextElement() );
entryList.add( entries.nextElement() );
}

return entryVector.elements();
return Collections.enumeration(entryList);
}

/**
Expand Down Expand Up @@ -411,6 +410,7 @@ public Enumeration getEntries()
public void remove( JposRegPopulator populator ) { popMap.remove( populator.getUniqueId() ); }

/** @return an iterator over all populators in this composite */
@SuppressWarnings("rawtypes")
public Iterator getPopulators() { return popMap.values().iterator(); }

/**
Expand All @@ -419,7 +419,7 @@ public Enumeration getEntries()
* @see jpos.config.JposRegPopulator#getUniqueId()
*/
public JposRegPopulator getPopulator( String uniqueId )
{ return (JposRegPopulator)popMap.get( uniqueId ); }
{ return popMap.get( uniqueId ); }

/** @return the number of populator in this composite */
public int size() { return popMap.size(); }
Expand All @@ -428,8 +428,8 @@ public JposRegPopulator getPopulator( String uniqueId )
// Instance variables
//

private HashMap popMap = new HashMap();
private HashMap popFileMap = new HashMap();
private HashMap<String, JposRegPopulator> popMap = new HashMap<>();
private HashMap<String, String> popFileMap = new HashMap<>();
private JposRegPopulator defaultPop = null;
private Exception lastLoadException = null;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jpos/config/JposConfigException.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
public class JposConfigException extends JposException
{
private static final long serialVersionUID = 6080819630774250157L;

//-------------------------------------------------------------------------
// Ctor(s)
//
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/jpos/config/JposEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @since 0.1 (Philly 99 meeting)
* @author E. Michael Maximilien (maxim@us.ibm.com)
*/
@SuppressWarnings("rawtypes")
public interface JposEntry extends Serializable, Comparable
{
/**
Expand Down Expand Up @@ -90,6 +91,7 @@ public interface JposEntry extends Serializable, Comparable
* NOTE: any property with the same name gets overlaid
* @param propName the name of this property (should be unique per property)
* @param propValue the properties value Object
* @return the property value object as passed as 2nd argument
* @since 0.1 (Philly 99 meeting)
* @throws java.lang.IllegalArgumentException if the propName or propValue is null
*/
Expand All @@ -98,11 +100,17 @@ public interface JposEntry extends Serializable, Comparable
/**
* Looks for a property with name specified and removes it
* @param propName the name String of the property to remove
* @return the property object that has been removed
* @since 0.1 (Philly 99 meeting)
*/
public Object removeProperty( String propName );

/**
* A {@link JposEntry} specific equal method. <br>
* This considered a design flow today as {@link Object} defines an {@link Object#equals(Object)} which never should be
* redefined. However, this interface is from the early days when Java was only 4 years old and that was unknown.
* For backward compatibility reasons ths will remain.
* @param otherEntry the other {@link JposEntry} object the comparison has to be done against
* @return true if the two JposEntries have the same properties
* @since 0.1 (Philly 99 meeting)
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jpos/config/JposEntryConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public interface JposEntryConst extends RS232Const, Serializable
//

/** The default JposEntry property type */
public static final Class DEFAULT_PROP_TYPE = String.class;
public static final Class<String> DEFAULT_PROP_TYPE = String.class;

/** Array of all the property types allowed for a JposEntry property */
public static final Class[] PROP_TYPES =
public static final Class<?>[] PROP_TYPES =
{
String.class,
Boolean.class,
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jpos/config/JposEntryRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public interface JposEntryRegistry
* @return an enumeration of JposEntry objects
* @since 0.1 (Philly 99 meeting)
*/
public Enumeration getEntries();
@SuppressWarnings("rawtypes")
public Enumeration getEntries();

/**
* @return the JposEntry for the logicalName specified
Expand Down Expand Up @@ -115,6 +116,7 @@ public interface JposEntryRegistry
* Tell the JposEntryRegistry to save the current entries to the file
* specified. Depending on the current JposEntryPopulator the file might
* be an XML or serialized or other file.
* @param file the {@link File} object the registry entries has to to be persisted to
* @since 2.1.0
* @throws java.lang.Exception if any error occurs while saving or if the
* current populator does not support saving in a file
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jpos/config/JposEntryRegistryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*/
public class JposEntryRegistryEvent extends EventObject
{
/**
private static final long serialVersionUID = 8674029321997818382L;

/**
* Creates a new event
* @param source the source of this event
* @param entry the JposEntry associated with the event
Expand Down
Loading