Merge pull request #1 from alexkogon/dontThrowExceptionWhenNoProperties

Dont throw exception when no properties
This commit is contained in:
Alex Kogon
2015-09-22 11:29:52 +02:00
2 changed files with 19 additions and 10 deletions

View File

@@ -21,6 +21,9 @@
<mkdir dir="${lib}"/>
<echo>basedir: ${basedir}</echo>
<echo>VM: ${java.vm.name}</echo>
<echo>VM Version: ${java.vm.specification.version}</echo>
<echo>VM Vendor: ${java.vm.vendor}</echo>
<echo>VM Build: ${java.vm.version}</echo>
<echo>Username: ${user.name}</echo>
</target>

View File

@@ -59,13 +59,13 @@ public class PropertiesSerializer {
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Unable to load properties from file: "+propertyFilename+". Default values will be used.");
return;
}
Field[] fields = this.getClass().getFields();
for (int i = 0 ; i < fields.length; i++)
{
//fields[i].get(this);
String pName = fields[i].getName();
String pType = "String";
try
@@ -74,20 +74,26 @@ public class PropertiesSerializer {
}
catch (Exception e)
{
//e.printStackTrace();
// e.printStackTrace();
}
final Object myProperty = prop.get(pName);
try
{
if (pType.equalsIgnoreCase("integer"))
fields[i].set(this, Integer.parseInt(prop.get(pName) + ""));
if (pType.equalsIgnoreCase("boolean"))
fields[i].set(this, Boolean.parseBoolean(prop.get(pName) + ""));
else
fields[i].set(this, prop.get(pName));
if(myProperty==null) {
System.out.println("Property "+pName+"["+pType+"] not set; input was null");
} else {
if (pType.equalsIgnoreCase("integer"))
fields[i].set(this, Integer.parseInt(myProperty + ""));
if (pType.equalsIgnoreCase("boolean"))
fields[i].set(this, Boolean.parseBoolean(myProperty + ""));
else
fields[i].set(this, myProperty);
System.out.println("Property "+pName+"["+pType+"] set to: "+myProperty);
}
}
catch (Exception e)
{
//e.printStackTrace();
// e.printStackTrace();
}
}
}