All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.analyzer.impl.LuceneAnalyzerReference Maven / Gradle / Ivy

There is a newer version: 5.11.12.Final
Show newest version
/*
 * 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.analyzer.impl;

import java.lang.invoke.MethodHandles;

import org.apache.lucene.analysis.Analyzer;
import org.hibernate.search.analyzer.spi.AnalyzerReference;
import org.hibernate.search.util.logging.impl.Log;
import org.hibernate.search.util.logging.impl.LoggerFactory;

/**
 * A reference to an {@link Analyzer}.
 *
 * @author Davide D'Alto
 */
public abstract class LuceneAnalyzerReference implements AnalyzerReference {

	private final Log log = LoggerFactory.make( MethodHandles.lookup() );

	public abstract Analyzer getAnalyzer();

	@Override
	public  boolean is(Class analyzerType) {
		return analyzerType.isAssignableFrom( getClass() );
	}

	@Override
	public  T unwrap(Class analyzerType) {
		try {
			return analyzerType.cast( this );
		}
		catch (ClassCastException e) {
			if ( !LuceneAnalyzerReference.class.isAssignableFrom( analyzerType ) ) {
				// Not even the same technology, probably a user error
				throw log.invalidConversionFromLuceneAnalyzer( this, e );
			}
			else {
				// The other type uses the same technology... probably a bug?
				throw e;
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy