Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

refactored and added javadocs

Noble Paul2652eabbbdad
diff --git a/src/java/org/apache/solr/core/PluginInfo.java b/src/java/org/apache/solr/core/PluginInfo.java
index b6a2c251d9c..87e18978377 100644
--- a/src/java/org/apache/solr/core/PluginInfo.java
+++ b/src/java/org/apache/solr/core/PluginInfo.java
@@ -92,6 +92,10 @@ public class PluginInfo {
return Boolean.parseBoolean(attributes.get("default"));
}
+ /**Filter children by type
+ * @param type The type name. must not be null
+ * @return The mathcing children
+ */
public List<PluginInfo> getChildren(String type){
if(children.isEmpty()) return children;
List<PluginInfo> result = new ArrayList<PluginInfo>();
diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java
index 5ab35edda2d..fbb8cc58892 100644
--- a/src/java/org/apache/solr/core/SolrCore.java
+++ b/src/java/org/apache/solr/core/SolrCore.java
@@ -400,7 +400,7 @@ public final class SolrCore implements SolrInfoMBean {
/** Creates an instance by trying a constructor that accepts a SolrCore before
* trying the default (no arg) constructor.
*@param className the instance class to create
- *@cast the class or interface that the instance should extend or implement
+ *@param cast the class or interface that the instance should extend or implement
*@param msg a message helping compose the exception error if any occurs.
*@return the desired instance
*@throws SolrException if the object could not be instantiated
@@ -430,6 +430,7 @@ public final class SolrCore implements SolrInfoMBean {
}
public <T extends Object> T createInitInstance(PluginInfo info,Class<T> cast, String msg, String defClassName){
+ if(info == null) return null;
T o = createInstance(info.className == null ? defClassName : info.className,cast, msg);
if (o instanceof PluginInfoInitialized) {
((PluginInfoInitialized) o).init(info);
@@ -1478,6 +1479,12 @@ public final class SolrCore implements SolrInfoMBean {
}
}
+ /**
+ * @param registry The map to which the instance should be added to. The key is the name attribute
+ * @param type the class or interface that the instance should extend or implement.
+ * @param defClassName If PluginInfo does not have a classname, use this as the classname
+ * @return The default instance . The one with (default=true)
+ */
public <T> T initPlugins(Map<String ,T> registry, Class<T> type, String defClassName){
return initPlugins(solrConfig.getPluginInfos(type.getName()), registry, type, defClassName);
}
@@ -1486,11 +1493,6 @@ public final class SolrCore implements SolrInfoMBean {
T def = null;
for (PluginInfo info : pluginInfos) {
T o = createInitInstance(info,type, type.getSimpleName(), defClassName);
- if (o instanceof PluginInfoInitialized) {
- ((PluginInfoInitialized) o).init(info);
- }else if (o instanceof NamedListInitializedPlugin) {
- ((NamedListInitializedPlugin) o).init(info.initArgs);
- }
registry.put(info.name, o);
if(info.isDefault()){
def = o;
@@ -1499,6 +1501,23 @@ public final class SolrCore implements SolrInfoMBean {
return def;
}
+ /**For a given List of PluginInfo return the instances as a List
+ * @param defClassName The default classname if PluginInfo#className == null
+ * @return The instances initialized
+ */
+ public <T> List<T> initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName) {
+ if(pluginInfos.isEmpty()) return Collections.emptyList();
+ List<T> result = new ArrayList<T>();
+ for (PluginInfo info : pluginInfos) result.add(createInitInstance(info,type, type.getSimpleName(), defClassName));
+ return result;
+ }
+
+ /**
+ *
+ * @param registry The map to which the instance should be added to. The key is the name attribute
+ * @param type The type of the Plugin. These should be standard ones registerd by type.getName() in SolrConfig
+ * @return The default if any
+ */
public <T> T initPlugins(Map<String, T> registry, Class<T> type) {
return initPlugins(registry, type, null);
}
diff --git a/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
index 887281c75cd..594876f6ff8 100644
--- a/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
+++ b/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
@@ -72,25 +72,19 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
formatters.clear();
fragmenters.clear();
- List<PluginInfo> fragmenterInfo = new ArrayList<PluginInfo>();
- List<PluginInfo> formatterrInfo = new ArrayList<PluginInfo>();
- // Load the fragmenters
- for (PluginInfo child : info.children) {
- if("fragmenter".equals(child.type)) fragmenterInfo.add(child);
- if("formatter".equals(child.type)) formatterrInfo.add(child);
- }
- SolrFragmenter frag = solrCore.initPlugins(fragmenterInfo, fragmenters,SolrFragmenter.class,null);
+ SolrFragmenter frag = solrCore.initPlugins(info.getChildren("fragmenter") , fragmenters,SolrFragmenter.class,null);
if (frag == null) frag = new GapFragmenter();
fragmenters.put("", frag);
fragmenters.put(null, frag);
// Load the formatters
- SolrFormatter fmt = solrCore.initPlugins(formatterrInfo, formatters,SolrFormatter.class,null);
+ SolrFormatter fmt = solrCore.initPlugins(info.getChildren("formatter"), formatters,SolrFormatter.class,null);
if (fmt == null) fmt = new HtmlFormatter();
formatters.put("", fmt);
formatters.put(null, fmt);
initialized = true;
}
+ //just for back-compat with the deprecated method
private boolean initialized = false;
@Deprecated
public void initalize( SolrConfig config) {
diff --git a/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java b/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java
index 53bf0dbfa84..0c7a9f14246 100644
--- a/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java
+++ b/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java
@@ -23,7 +23,7 @@ import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrCore;
-import java.util.ArrayList;
+import java.util.List;
/**
* Manages a chain of UpdateRequestProcessorFactories.
@@ -54,13 +54,7 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized
}
public void init(PluginInfo info) {
- ArrayList<UpdateRequestProcessorFactory> list = new ArrayList<UpdateRequestProcessorFactory>();
- for (PluginInfo child : info.children) {
- if("processor".equals(child.type)){
- UpdateRequestProcessorFactory factory = solrCore.createInitInstance(child, UpdateRequestProcessorFactory.class, null,null);
- list.add(factory);
- }
- }
+ List<UpdateRequestProcessorFactory> list = solrCore.initPlugins(info.getChildren("processor"),UpdateRequestProcessorFactory.class,null);
if(list.isEmpty()){
throw new RuntimeException( "updateRequestProcessorChain require at least one processor");
}