/** 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. * * @param path The path representing the config location. * @return An appropriate URL or null. */ public static final URL locateConfig(final String path) { try { return new URL(path); } catch(MalformedURLException e) { return findAsResource(path); } }
/** Open an Reader to the URL represented by the incoming path. First makes a call * to {@link #locateConfig(java.lang.String)} in order to find an appropriate URL. * {@link java.net.URL#openStream()} is then called to obtain a stream, which is then * wrapped in a Reader. * * @param path The path representing the config location. * @return An input stream to the requested config resource. * @throws HibernateException Unable to open reader to that resource. */ public static final Reader getConfigStreamReader(final String path) throws HibernateException { return new InputStreamReader( getConfigStream(path) ); }
private URL loadResource(String configurationResourceName) { URL url = ConfigHelper.locateConfig( configurationResourceName ); if (log.isDebugEnabled()) { log.debug("Creating EhCacheProvider from a specified resource: " + configurationResourceName + " Resolved to URL: " + url); } return url; }
JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader(jaxpFile), false ); PropertyConfigurator.configure( ConfigHelper.getConfigProperties(propFile) );
InputStream stream = ConfigHelper.getResourceAsStream( importFile ); importFileReader = new InputStreamReader( stream );
JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader(jaxpFile), false ); PropertyConfigurator.configure( ConfigHelper.getConfigProperties(propFile) );
/** Open an Reader to the URL represented by the incoming path. First makes a call * to {@link #locateConfig(java.lang.String)} in order to find an appropriate URL. * {@link java.net.URL#openStream()} is then called to obtain a stream, which is then * wrapped in a Reader. * * @param path The path representing the config location. * @return An input stream to the requested config resource. * @throws HibernateException Unable to open reader to that resource. */ public static final Reader getConfigStreamReader(final String path) throws HibernateException { return new InputStreamReader( getConfigStream(path) ); }
/** Open an InputStream to the URL represented by the incoming path. First makes a call * to {@link #locateConfig(java.lang.String)} in order to find an appropriate URL. * {@link java.net.URL#openStream()} is then called to obtain the stream. * * @param path The path representing the config location. * @return An input stream to the requested config resource. * @throws HibernateException Unable to open stream to that resource. */ public static final InputStream getConfigStream(final String path) throws HibernateException { final URL url = ConfigHelper.locateConfig(path); if (url == null) { String msg = "Unable to locate config file: " + path; log.fatal(msg); throw new HibernateException(msg); } try { return url.openStream(); } catch(IOException e) { throw new HibernateException("Unable to open config file: " + path, e); } }
/** 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. * * @param path The path representing the config location. * @return An appropriate URL or null. */ public static final URL locateConfig(final String path) { try { return new URL(path); } catch(MalformedURLException e) { return findAsResource(path); } }
/** Loads a properties instance based on the data at the incoming config location. * * @param path The path representing the config location. * @return The loaded properties instance. * @throws HibernateException Unable to load properties from that resource. */ public static final Properties getConfigProperties(String path) throws HibernateException { try { Properties properties = new Properties(); properties.load( getConfigStream(path) ); return properties; } catch(IOException e) { throw new HibernateException("Unable to load properties from specified config file: " + path, e); } }
/** Open an InputStream to the URL represented by the incoming path. First makes a call * to {@link #locateConfig(java.lang.String)} in order to find an appropriate URL. * {@link java.net.URL#openStream()} is then called to obtain the stream. * * @param path The path representing the config location. * @return An input stream to the requested config resource. * @throws HibernateException Unable to open stream to that resource. */ public static final InputStream getConfigStream(final String path) throws HibernateException { final URL url = ConfigHelper.locateConfig(path); if (url == null) { String msg = "Unable to locate config file: " + path; log.fatal(msg); throw new HibernateException(msg); } try { return url.openStream(); } catch(IOException e) { throw new HibernateException("Unable to open config file: " + path, e); } }
/** Loads a properties instance based on the data at the incoming config location. * * @param path The path representing the config location. * @return The loaded properties instance. * @throws HibernateException Unable to load properties from that resource. */ public static final Properties getConfigProperties(String path) throws HibernateException { try { Properties properties = new Properties(); properties.load( getConfigStream(path) ); return properties; } catch(IOException e) { throw new HibernateException("Unable to load properties from specified config file: " + path, e); } }