
com.draagon.util.Configuration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utilities Show documentation
Show all versions of utilities Show documentation
Draagon Utilities used by other Draagon projects
The newest version!
/*
* Copyright Draagon Software, LLC. All Rights Reserved.
*
* This software is the proprietary information of Draagon Software, LLC.
* Use is subject to license terms.
*/
package com.draagon.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Enumeration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
public class Configuration extends Properties implements InitializingBean
{
private static final long serialVersionUID = 4319443307567558525L;
private static Log log = LogFactory.getLog(Configuration.class);
private Properties overrides = null;
private boolean ignoreResourceNotFound = false;
private Resource resource = null;
public Configuration()
{
}
public Configuration( Properties p )
{
super();
setProperties( p );
}
public void afterPropertiesSet() throws IOException {
if ( resource != null ) {
// If it doesn't exist and we can ignore this error, then return
if ( !resource.exists() && isIgnoreResourceNotFound() ) {
return;
}
// Get the input stream for this
InputStream is = null;
try {
is = resource.getInputStream();
Properties p = new Properties();
p.load( is );
// Set the properties that were just loaded
setProperties( p );
}
catch( IOException e ) {
if ( e instanceof FileNotFoundException && isIgnoreResourceNotFound() ) {
// Do nothing as we can ignore this error
} else {
throw e;
}
}
finally {
if ( is != null ) is.close();
}
}
}
/** Directly sets Properties onto the Configuration object */
public void setProperties( Properties p ) {
for( Enumeration
© 2015 - 2025 Weber Informatics LLC | Privacy Policy