Java Code Examples for org.apache.lucene.analysis.util.ResourceLoaderAware

The following examples show how to use org.apache.lucene.analysis.util.ResourceLoaderAware. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File: CustomContainerPlugins.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public void init() throws Exception {
  if (this.holders != null) return;
  Constructor constructor = klas.getConstructors()[0];
  if (constructor.getParameterTypes().length == 0) {
    instance = constructor.newInstance();
  } else if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == CoreContainer.class) {
    instance = constructor.newInstance(coreContainer);
  } else {
    throw new RuntimeException("Must have a no-arg constructor or CoreContainer constructor ");
  }
  if (instance instanceof ResourceLoaderAware) {
    try {
      ((ResourceLoaderAware) instance).inform(pkgVersion.getLoader());
    } catch (IOException e) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
    }
  }
  this.holders = new ArrayList<>();
  for (Api api : AnnotatedApi.getApis(instance)) {
    holders.add(new ApiHolder((AnnotatedApi) api));
  }
}
 
Example 2
Source Project: lucene-solr   Source File: PackagePluginHolder.java    License: Apache License 2.0 6 votes vote down vote up
private void handleAwareCallbacks(SolrResourceLoader loader, Object instance) {
  if (instance instanceof SolrCoreAware) {
    SolrCoreAware coreAware = (SolrCoreAware) instance;
    if (!core.getResourceLoader().addToCoreAware(coreAware)) {
      coreAware.inform(core);
    }
  }
  if (instance instanceof ResourceLoaderAware) {
    SolrResourceLoader.assertAwareCompatibility(ResourceLoaderAware.class, instance);
    try {
      ((ResourceLoaderAware) instance).inform(loader);
    } catch (IOException e) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
    }
  }
  if (instance instanceof SolrInfoBean) {
    core.getResourceLoader().addToInfoBeans(instance);
  }
}
 
Example 3
Source Project: lucene-solr   Source File: SynonymGraphFilterFactory.java    License: Apache License 2.0 5 votes vote down vote up
private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname) throws IOException {
  Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
  try {
    TokenizerFactory tokFactory = clazz.getConstructor(Map.class).newInstance(tokArgs);
    if (tokFactory instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) tokFactory).inform(loader);
    }
    return tokFactory;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 4
Source Project: lucene-solr   Source File: SynonymGraphFilterFactory.java    License: Apache License 2.0 5 votes vote down vote up
private Analyzer loadAnalyzer(ResourceLoader loader, String cname) throws IOException {
  Class<? extends Analyzer> clazz = loader.findClass(cname, Analyzer.class);
  try {
    Analyzer analyzer = clazz.getConstructor().newInstance();
    if (analyzer instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) analyzer).inform(loader);
    }
    return analyzer;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 5
Source Project: lucene-solr   Source File: SynonymFilterFactory.java    License: Apache License 2.0 5 votes vote down vote up
private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname) throws IOException {
  Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
  try {
    TokenizerFactory tokFactory = clazz.getConstructor(Map.class).newInstance(tokArgs);
    if (tokFactory instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) tokFactory).inform(loader);
    }
    return tokFactory;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 6
Source Project: lucene-solr   Source File: SynonymFilterFactory.java    License: Apache License 2.0 5 votes vote down vote up
private Analyzer loadAnalyzer(ResourceLoader loader, String cname) throws IOException {
  Class<? extends Analyzer> clazz = loader.findClass(cname, Analyzer.class);
  try {
    Analyzer analyzer = clazz.getConstructor().newInstance();
    if (analyzer instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) analyzer).inform(loader);
    }
    return analyzer;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 7
Source Project: lucene-solr   Source File: ConditionalTokenFilterFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void inform(ResourceLoader loader) throws IOException {
  if (innerFilters == null)
    return;
  for (TokenFilterFactory factory : innerFilters) {
    if (factory instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware)factory).inform(loader);
    }
  }
  doInform(loader);
}
 
Example 8
Source Project: lucene-solr   Source File: CustomAnalyzer.java    License: Apache License 2.0 4 votes vote down vote up
<T> T applyResourceLoader(T factory) throws IOException {
  if (factory instanceof ResourceLoaderAware) {
    ((ResourceLoaderAware) factory).inform(loader);
  }
  return factory;
}