Top Description Fields Constructors Methods
org.hibernate.util

public final Class ConfigHelper

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .InputStreamReader, .Reader, java.net.MalformedURLException, .URL, java.util.Properties, org.slf4j.Logger, .LoggerFactory, org.hibernate.HibernateException, org.hibernate.cfg.Environment

A simple class to centralize logic needed to locate config files on the system.
Author
Steve

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static final URL

Returns:

An appropriate URL or null.
findAsResource
(final String
The path representing the config location.
path
)

Try to locate a local URL representing the incoming path.

public static final Properties

Returns:

The loaded properties instance.
getConfigProperties
(String
The path representing the config location.
path
)

Loads a properties instance based on the data at the incoming config location.

public static final InputStream

Returns:

An input stream to the requested config resource.
getConfigStream
(final String
The path representing the config location.
path
)

Open an InputStream to the URL represented by the incoming path.

public static final Reader

Returns:

An input stream to the requested config resource.
getConfigStreamReader
(final String
The path representing the config location.
path
)

Open an Reader to the URL represented by the incoming path.

public static InputStream
public static InputStream
public static final URL

Returns:

An appropriate URL or null.
locateConfig
(final String
The path representing the config location.
path
)

Try to locate a local URL representing the incoming path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logback to summary
private static final Logger log

Constructor Detail

ConfigHelperback to summary
private ConfigHelper()

Method Detail

findAsResourceback to summary
public static final URL findAsResource(final String path)

Try to locate a local URL representing the incoming path. This method only attempts to locate this URL as a java system resource.

Parameters
path:String

The path representing the config location.

Returns:URL

An appropriate URL or null.

getConfigPropertiesback to summary
public static final Properties getConfigProperties(String path) throws HibernateException

Loads a properties instance based on the data at the incoming config location.

Parameters
path:String

The path representing the config location.

Returns:Properties

The loaded properties instance.

Exceptions
HibernateException:
Unable to load properties from that resource.
getConfigStreamback to summary
public static final InputStream getConfigStream(final String path) throws HibernateException

Open an InputStream to the URL represented by the incoming path. First makes a call to locateConfig(java.lang.String) in order to find an appropriate URL. java.net.URL#openStream() is then called to obtain the stream.

Parameters
path:String

The path representing the config location.

Returns:InputStream

An input stream to the requested config resource.

Exceptions
HibernateException:
Unable to open stream to that resource.
getConfigStreamReaderback to summary
public static final Reader getConfigStreamReader(final String path) throws HibernateException

Open an Reader to the URL represented by the incoming path. First makes a call to locateConfig(java.lang.String) in order to find an appropriate URL. java.net.URL#openStream() is then called to obtain a stream, which is then wrapped in a Reader.

Parameters
path:String

The path representing the config location.

Returns:Reader

An input stream to the requested config resource.

Exceptions
HibernateException:
Unable to open reader to that resource.
getResourceAsStreamback to summary
public static InputStream getResourceAsStream(String resource)
getUserResourceAsStreamback to summary
public static InputStream getUserResourceAsStream(String resource)
locateConfigback to summary
public static final URL locateConfig(final String path)

Try to locate a local URL representing the incoming path. The first attempt assumes that the incoming path is an actual URL string (file://, etc). If this does not work, then the next attempts try to locate this UURL as a java system resource.

Parameters
path:String

The path representing the config location.

Returns:URL

An appropriate URL or null.