* This algorithm seems to be safe for incremental search factories.
*/
private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
ConfigContext context = new ConfigContext( cfg );
DirectoryProviderFactory factory = new DirectoryProviderFactory();
initProgrammaticAnalyzers( context, reflectionManager );
initProgrammaticallyDefinedFilterDef( reflectionManager );
final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
final Map<Class<?>, DocumentBuilderIndexedEntity<?>> documentBuildersIndexedEntities = factoryState.getDocumentBuildersIndexedEntities();
final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
final Map<XClass, Class> classMappings = initializeClassMappings( cfg, reflectionManager );
for ( Map.Entry<XClass, Class> mapping : classMappings.entrySet() ) {
XClass mappedXClass = mapping.getKey();
Class mappedClass = mapping.getValue();
if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
if ( mappedXClass.isAbstract() ) {
log.warn( "Abstract classes can never insert index documents. Remove @Indexed." );
continue;
}
DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders(
mappedXClass, cfg, buildContext, reflectionManager
);
//FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
//XClass unfortunately is not (yet) genericized: TODO?
final DocumentBuilderIndexedEntity<?> documentBuilder =
new DocumentBuilderIndexedEntity(
mappedXClass,
context,
providers,
reflectionManager,
optimizationBlackListedTypes
);
indexingHierarchy.addIndexedClass( mappedClass );
documentBuildersIndexedEntities.put( mappedClass, documentBuilder );
}
else {
//FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
//XClass unfortunately is not (yet) genericized: TODO?
final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
mappedXClass, context, reflectionManager, optimizationBlackListedTypes
);
//TODO enhance that, I don't like to expose EntityState
if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
documentBuildersContainedEntities.put( mappedClass, documentBuilder );
}
}
bindFilterDefs( mappedXClass );
//TODO should analyzer def for classes at their same level???
}
disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
factoryState.setAnalyzers( context.initLazyAnalyzers() );
factory.startDirectoryProviders();
}