You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by no...@apache.org on 2009/09/22 06:38:11 UTC
svn commit: r817501 - in /lucene/solr/trunk/src/java/org/apache/solr:
core/PluginInfo.java core/SolrCore.java highlight/DefaultSolrHighlighter.java
update/processor/UpdateRequestProcessorChain.java
Author: noble
Date: Tue Sep 22 04:38:10 2009
New Revision: 817501
URL: http://svn.apache.org/viewvc?rev=817501&view=rev
Log:
refactored and added javadocs
Modified:
lucene/solr/trunk/src/java/org/apache/solr/core/PluginInfo.java
lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
lucene/solr/trunk/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/PluginInfo.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/PluginInfo.java?rev=817501&r1=817500&r2=817501&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/PluginInfo.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/PluginInfo.java Tue Sep 22 04:38:10 2009
@@ -92,6 +92,10 @@
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>();
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?rev=817501&r1=817500&r2=817501&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Tue Sep 22 04:38:10 2009
@@ -400,7 +400,7 @@
/** 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 <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 @@
}
}
+ /**
+ * @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 @@
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 @@
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);
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java?rev=817501&r1=817500&r2=817501&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java Tue Sep 22 04:38:10 2009
@@ -72,25 +72,19 @@
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) {
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java?rev=817501&r1=817500&r2=817501&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java Tue Sep 22 04:38:10 2009
@@ -23,7 +23,7 @@
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 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");
}