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

The following examples show how to use org.apache.lucene.analysis.util.ResourceLoaderAware. 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 File: CustomContainerPlugins.java    From lucene-solr with 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 File: PackagePluginHolder.java    From lucene-solr with 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 File: SynonymGraphFilterFactory.java    From lucene-solr with 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 File: SynonymGraphFilterFactory.java    From lucene-solr with 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 File: SynonymFilterFactory.java    From lucene-solr with 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 File: SynonymFilterFactory.java    From lucene-solr with 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 File: ConditionalTokenFilterFactory.java    From lucene-solr with 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 File: CustomAnalyzer.java    From lucene-solr with 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;
}