private static PropertiesConfigSource configSource( String identifier ) throws Exception
{
boolean hocon = isHoconPath( identifier );
if (!hocon && ! identifier.startsWith("/"))
throw new IllegalArgumentException(String.format("Resource identifier '%s' is neither an absolute resource path nor a HOCON path. (Resource paths should be specified beginning with '/' or 'hocon:/')", identifier));
if ( hocon )
{
try
{
Class.forName( HOCON_CFG_CNAME );
return new HoconPropertiesConfigSource();
}
catch (ClassNotFoundException e)
{
int sfx_index = identifier.lastIndexOf('#');
String resourcePath = sfx_index > 0 ? identifier.substring( HOCON_PFX_LEN, sfx_index ) : identifier.substring( HOCON_PFX_LEN );
if (BasicMultiPropertiesConfig.class.getResource( resourcePath ) == null)
throw new FileNotFoundException( String.format("HOCON lib (typesafe-config) is not available. Also, no resource available at '%s' for HOCON identifier '%s'.", resourcePath, identifier) );
else
throw new Exception(String.format("Could not decode HOCON resource '%s', even though the resource exists, because HOCON lib (typesafe-config) is not available.", identifier), e);
}
}
else if ( "/".equals(identifier) )
return new SystemPropertiesConfigSource();
else
return new BasicPropertiesConfigSource();
}