org.hibernate.search.jsr352.jberet.impl.HibernateSearchJobXmlResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-jsr352-jberet
Show all versions of hibernate-search-jsr352-jberet
Hibernate Search JSR-352 integration - for JBeret
/*
* 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.jsr352.jberet.impl;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.hibernate.search.exception.SearchException;
import org.hibernate.search.jsr352.massindexing.MassIndexingJob;
import org.jberet.spi.JobXmlResolver;
import org.jberet.tools.AbstractJobXmlResolver;
public final class HibernateSearchJobXmlResolver extends AbstractJobXmlResolver implements JobXmlResolver {
private static final String XML_SUFFIX = ".xml";
private static final Map JOB_XML_NAMES_TO_JOB_NAMES = Collections.unmodifiableMap(
Arrays.asList( MassIndexingJob.NAME ).stream()
.collect( Collectors.toMap( s -> s.concat( XML_SUFFIX ), Function.identity() ) )
);
@Override
public Collection getJobXmlNames(ClassLoader classLoader) {
return JOB_XML_NAMES_TO_JOB_NAMES.keySet();
}
@Override
public String resolveJobName(String jobXml, ClassLoader classLoader) {
return JOB_XML_NAMES_TO_JOB_NAMES.get( jobXml );
}
@Override
public InputStream resolveJobXml(final String jobXml, final ClassLoader classLoader) throws IOException {
if ( JOB_XML_NAMES_TO_JOB_NAMES.containsKey( jobXml ) ) {
final String path = DEFAULT_PATH + jobXml;
return classLoader.getResourceAsStream( path );
}
else {
throw new SearchException( "Not a Hibernate Search JSR-352 job: " + jobXml );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy