/** * 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 URL locateConfig(final String path) { try { return new URL( path ); } catch (MalformedURLException e) { return findAsResource( 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 InputStream getConfigStream(final String path) throws HibernateException { final URL url = ConfigHelper.locateConfig( path ); if ( url == null ) { String msg = LOG.unableToLocateConfigFile( path ); LOG.error( msg ); throw new HibernateException( msg ); } try { return url.openStream(); } catch (IOException e) { throw new HibernateException( "Unable to open config file: " + path, e ); } }
protected InputStream resolveInLocalNamespace(String path) { try { return ConfigHelper.getUserResourceAsStream( path ); } catch ( Throwable t ) { return null; } } }
File file = File.createTempFile( "TempInvalidMapping", ".hbm.xml" ); file.deleteOnExit(); copy( ConfigHelper.getConfigStream( resourceName ), file ); cfg.addInputStream( ConfigHelper.getResourceAsStream( resourceName ) ); fail(); cfg.addURL( ConfigHelper.findAsResource( resourceName ) ); fail();
/** 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 Reader getConfigStreamReader(final String path) throws HibernateException { return new InputStreamReader( getConfigStream(path) ); }
/** * Get the configuration file as an <tt>InputStream</tt>. Might be overridden * by subclasses to allow the configuration to be located by some arbitrary * mechanism. * <p/> * By default here we use classpath resource resolution * * @param resource The resource to locate * * @return The stream * * @throws HibernateException Generally indicates we cannot find the named resource */ protected InputStream getConfigurationInputStream(String resource) throws HibernateException { LOG.configurationResource( resource ); return ConfigHelper.getResourceAsStream( resource ); }
/** 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 Reader getConfigStreamReader(final String path) throws HibernateException { return new InputStreamReader( getConfigStream(path) ); }
/** * Get the configuration file as an <tt>InputStream</tt>. Might be overridden * by subclasses to allow the configuration to be located by some arbitrary * mechanism. * <p/> * By default here we use classpath resource resolution * * @param resource The resource to locate * * @return The stream * * @throws HibernateException Generally indicates we cannot find the named resource */ protected InputStream getConfigurationInputStream(String resource) throws HibernateException { LOG.configurationResource( resource ); return ConfigHelper.getResourceAsStream( resource ); }
@Test @TestForIssue(jiraKey = "HHH-9247") public void parseNamedAttributeNode() { final Configuration cfg = new Configuration(); cfg.addURL( ConfigHelper.findAsResource( "org/hibernate/test/annotations/entityGraph/orm.xml" ) ); cfg.buildMappings(); }
/** 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 InputStream getConfigStream(final String path) throws HibernateException { final URL url = ConfigHelper.locateConfig(path); if (url == null) { String msg = LOG.unableToLocateConfigFile(path); LOG.error(msg); throw new HibernateException(msg); } try { return url.openStream(); } catch(IOException e) { throw new HibernateException("Unable to open config file: " + path, e); } }
protected InputStream resolveInLocalNamespace(String path) { try { return ConfigHelper.getUserResourceAsStream( path ); } catch ( Throwable t ) { return null; } } }
/** 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 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); } }
try { final String resourceName = currentFile.trim(); InputStream stream = ConfigHelper.getResourceAsStream( resourceName ); importFileReaders.add( new NamedReader( resourceName, stream ) );
@Test @TestForIssue(jiraKey = "HHH-8462") public void testBasicOrmXmlConverterApplication() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) .addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/orm.xml" ) ) .getMetadataBuilder() .build(); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); Property nameProp = tester.getProperty( "name" ); SimpleValue nameValue = (SimpleValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { fail( "AttributeConverter not applied" ); } AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type ); assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); assertEquals( Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType() ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
/** 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 InputStream getConfigStream(final String path) throws HibernateException { final URL url = ConfigHelper.locateConfig(path); if (url == null) { String msg = LOG.unableToLocateConfigFile(path); LOG.error(msg); throw new HibernateException(msg); } try { return url.openStream(); } catch(IOException e) { throw new HibernateException("Unable to open config file: " + path, e); } }
protected InputStream resolveInLocalNamespace(String path) { try { return ConfigHelper.getUserResourceAsStream( path ); } catch ( Throwable t ) { return null; } } }
/** 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 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); } }
try { final String resourceName = currentFile.trim(); InputStream stream = ConfigHelper.getResourceAsStream( resourceName ); importFileReaders.add( new NamedReader( resourceName, stream ) );
/** 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 URL locateConfig(final String path) { try { return new URL(path); } catch(MalformedURLException e) { return findAsResource(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 InputStream getConfigStream(final String path) throws HibernateException { final URL url = ConfigHelper.locateConfig( path ); if ( url == null ) { String msg = LOG.unableToLocateConfigFile( path ); LOG.error( msg ); throw new HibernateException( msg ); } try { return url.openStream(); } catch (IOException e) { throw new HibernateException( "Unable to open config file: " + path, e ); } }