org.hibernate.search.util.impl.HibernateSearchResourceLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Core of the Object/Lucene mapper, query engine and index management
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.search.util.impl;
import java.io.IOException;
import java.io.InputStream;
import org.apache.lucene.analysis.util.ResourceLoader;
import org.hibernate.search.engine.service.classloading.spi.ClassLoaderService;
import org.hibernate.search.engine.service.spi.ServiceManager;
import org.hibernate.search.util.logging.impl.Log;
import org.hibernate.search.util.logging.impl.LoggerFactory;
import java.lang.invoke.MethodHandles;
/**
* Hibernate Search specific implementation of Lucene's {@code ResourceLoader} interface.
*
* @author Emmanuel Bernard
* @author Sanne Grinovero (C) 2011 Red Hat Inc.
* @author Hardy Ferentschik
*/
public class HibernateSearchResourceLoader implements ResourceLoader {
private static final Log log = LoggerFactory.make( MethodHandles.lookup() );
private final ServiceManager serviceManager;
public HibernateSearchResourceLoader(ServiceManager serviceManager) {
this.serviceManager = serviceManager;
}
@Override
public InputStream openResource(String resource) throws IOException {
ClassLoaderService classLoaderService = serviceManager.getClassLoaderService();
InputStream inputStream = classLoaderService.locateResourceStream( resource );
if ( inputStream == null ) {
throw log.unableToLoadResource( resource );
}
else {
return inputStream;
}
}
@Override
public Class extends T> findClass(String className, Class expectedType) {
return ClassLoaderHelper.classForName(
expectedType,
className,
describeComponent( className ),
serviceManager
);
}
@Override
public T newInstance(String className, Class expectedType) {
return ClassLoaderHelper.instanceFromName(
expectedType,
className,
describeComponent( className ),
serviceManager
);
}
private static String describeComponent(final String className) {
return "Lucene Analyzer component " + className;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy