JHPropertiesTyped - Why should I use this?

There are many reason to use this, and many reasons not to.

This library do not solve any giving property problem. But let me try to explain the thought behind it.

The typical scenario I have encountered is
Are you tired of do this boiler plate code for each of you properties.
Properties properties = ClassLoader.getResource("app.properties");

int myint = 0;
try {
	myint = Integer.parseInt(properties.getProperty("myint"));
	if ((myint<22) && (myint>658)) {
		//should I use default value?
		//should I throw exception ?
		//throw new IllegalArgumentException("myint property is outside valid range [23-657]");
} catch (NumberFormatException e) {
	//1. Should we use default.
	//2. Should we just log the error.
	//3. Should we close application because of invalid property.
} catch (IllegalArgumentException e) {
	//1. Should we use default.
	//2. Should we just log the error.	
	//3. Should we close application because of invalid property.
Instead you can do this :
public interface MyPropertiesDef {
	public static final Property<Integer> MYINT = new Property<Integer>("myint",new IntegerPropertyType(23,657));
	//All your property definitions here......

//Make this once
public class MyProperties extends PropertyStaticCollection implements MyPropertiesDef {

	private static MyProperties instance=null;
	public MyProperties() {
		super(new ResourceFilePropertyIO("app.properties"),new LoggingPropertyValidationHandler(true));
	public MyProperties getInstance() {
		if (instance==null) {
			instance = new MyProperties();
		return instance;
  • Every application has its own property source code
  • Applications has different ways of loading properties.
  • Always a lot of code to ensure that each property was "valid"
  • Difficult to get an overview of what properties is "defined", what is used, what is legacy but not used any more, but we don't delete in fear of breaking the code
  • The question of what to do if a property wasn't valid was often not address, it was hoped they were not.
  • On deployment it was not uncommon that a property was forgotten to be inserted, and was first discovered later because of dummy default values.
Recognize any of this ??

What this library and its way of thought will provide is the following
  • A centralize place to define the properties your application needs.
  • Complete overview of your properties, can use code inspection to see what is used or not.
  • You get the property values as the type you intended.
  • You can define a property with a strong type and give it restrictions, to ensure its value is with in valid bounds.
  • A property definition is a one line job.
  • You can load properties from many and multiple resources.
  • You can add a validation handler, which takes proper action if any property isn't valid.
  • You can make an uniform way to alter properties, through the GUI of your choice. The web demo is just one possibility.
  • Complete java doc and tutorial documentation, with more to come as I find more use full information to write.
  • Easy to convert legacy property definitions into this framework.

The typical feedback I have received so far, and answers to them
  • Q:Why don't you detect changes in the properties data, an automatically reloads them?
  • A:There is no need for this. You can always reload the properties, and change detection will give an overhead which in most cases is not needed. Either your properties is local or in an container loaded static.

  • Q:What about hierarchical data structure?
  • A:There is very few project I have seen this in, and I think in 99% there is no need to define this. It adds complexity which is not needed, simplicity is the key.

  • Q:What about dynamically defining new properties?
  • A:Why? In an application you want well defined properties, this little framework do not solve every property problem, but most of them. Again, simplicity is the key.

What types is currently supported?
Resulting class Count PropertyType(s)
T 6 DerivedFromSinglePropertyType DerivedFromTypePropertyType DerivedPropertyType AbstractKeyPropertyType FileDerivedPropertyType URLDerivedPropertyType  
T extends java.lang.Enum<T> 1 EnumPropertyType  
dk.heick.properties.types.custom.ByteSizeVO 1 ByteSizePropertyType  
dk.heick.properties.types.custom.HourIntervalsVO 1 HourIntervalsPropertyType  
dk.heick.properties.types.custom.IPRange 1 IPRangePropertyType  
dk.heick.properties.types.custom.LatLng 1 LatLngPropertyType  
dk.heick.properties.types.custom.PasswordTypeVO 1 PasswordPropertyType  
dk.heick.properties.types.custom.Point2D 1 Point2DPropertyType  
dk.heick.properties.types.custom.Point3D 1 Point3DPropertyType  
dk.heick.properties.types.custom.RangeVO<T> 1 RangePropertyType  
dk.heick.properties.types.custom.SequenceVO 1 SequencePropertyType  
dk.heick.properties.types.custom.SignedFile 2 CertificateSignedFilePropertyType KeySignedFilePropertyType  
dk.heick.properties.types.custom.TimeSpan 1 TimeSpanPropertyType  
dk.heick.properties.types.custom.VersionVO 1 VersionPropertyType  
dk.heick.properties.types.custom.enums.Environment 1 EnvironmentPropertyType  
dk.heick.properties.types.custom.enums.Month 1 MonthPropertyType  
dk.heick.properties.types.custom.enums.Weekday 1 WeekdayPropertyType  
dk.heick.properties.types.custom.filefilters.AbstractStringFilenameFilter 1 FilenameFilterPropertyType  
java.awt.Color 1 ColorPropertyType  
java.awt.Font 1 FontPropertyType  
java.awt.image.BufferedImage 2 ImageFromFilePropertyType ImageFromURLPropertyType  
java.io.File 3 DirectoryPropertyType FilePropertyType FileStructurePropertyType  
java.lang.Boolean 1 BooleanPropertyType  
java.lang.Class<? extends org.hibernate.dialect.Dialect> 1 HibernateDialectPropertyType [Extension]  
java.lang.Class<?> 1 ClassnamePropertyType  
java.lang.Double 1 DoublePropertyType  
java.lang.Integer 1 IntegerPropertyType  
java.lang.Long 1 LongPropertyType  
java.lang.String 7 ConnectionUrlPropertyType EmailPropertyType IP4AddressPropertyType RegularExpressionPropertyType StringPropertyType TextFromFilePropertyType QuartzCronExpressionPropertyType [Extension]
java.lang.byte[] 1 BytesFromFilePropertyType  
java.math.BigDecimal 1 BigDecimalPropertyType  
java.math.BigInteger 1 BigIntegerPropertyType  
java.net.InetAddress 1 InetAddressPropertyType  
java.net.Proxy 1 ProxyPropertyType  
java.net.URI 1 URIPropertyType  
java.net.URL 1 URLPropertyType  
java.nio.charset.Charset 1 CharsetPropertyType  
java.security.KeyStore 1 KeyStoreFilePropertyType  
java.security.PrivateKey 1 PrivateKeyFilePropertyType  
java.security.PublicKey 1 PublicKeyFilePropertyType  
java.security.cert.Certificate 1 CertificateKeyStoredPropertyType  
java.text.DecimalFormat 1 DecimalFormatPropertyType  
java.text.SimpleDateFormat 1 DateFormatPropertyType  
java.util.Collection<? extends java.security.cert.Certificate> 1 CertificatesFilePropertyType  
java.util.Date 1 DateTimePropertyType  
java.util.List<T> 2 ListPropertyType TypeListFromTextFilePropertyType  
java.util.List<dk.heick.properties.types.custom.KeyValueVO<K, V>> 1 ListKeyValuePropertyType  
java.util.Locale 2 CountryPropertyType LocalePropertyType  
java.util.Properties 1 StringPropertiesPropertyType  
java.util.TimeZone 1 TimeZonePropertyType  
java.util.concurrent.TimeUnit 1 TimeUnitPropertyType  
javax.activation.MimeType 1 MimeTypePropertyType  
javax.naming.ldap.LdapName 1 LdapNamePropertyType  

What do I wish for?
That some (hopeful many) developers will find this useful.

That I will get feedback on:
  • Gratitude :-)
  • Bug reports
  • Code support.
  • Java doc misconceptions, and english and/or modifications.
  • Custom PropertyType implementation which others will find useful.
  • PropertyIO implementation which others will find useful.
  • Implementation of property management code.
  • Suggestions
  • Etc...
Please send this to "frederik.heick@gmail.com"