From 7b708bb4130b1556faf884da8b05cf6e5e5cbd64 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Mon, 24 Aug 2009 08:36:26 +0000 Subject: [PATCH] SOLR-1198 moved PluginInfo out of solrconfig git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@807120 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/solr/core/PluginInfo.java | 77 +++++++++++++++++++ .../org/apache/solr/core/RequestHandlers.java | 6 +- src/java/org/apache/solr/core/SolrConfig.java | 55 ------------- src/java/org/apache/solr/core/SolrCore.java | 24 +++--- .../highlight/DefaultSolrHighlighter.java | 5 +- 5 files changed, 95 insertions(+), 72 deletions(-) create mode 100644 src/java/org/apache/solr/core/PluginInfo.java diff --git a/src/java/org/apache/solr/core/PluginInfo.java b/src/java/org/apache/solr/core/PluginInfo.java new file mode 100644 index 00000000000..ed96139adc8 --- /dev/null +++ b/src/java/org/apache/solr/core/PluginInfo.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.core; + +import org.apache.solr.common.util.NamedList; +import org.apache.solr.common.util.DOMUtil; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; + +import java.util.*; + +/** + * An Object which represents a Plugin of any type + * @version $Id$ + */ +public class PluginInfo { + public final String startup, name, className, type; + public final boolean isDefault; + public final NamedList initArgs; + public final Map attributes; + + public PluginInfo(String type, String startup, String name, String className, + boolean isdefault, NamedList initArgs, Map otherAttrs) { + this.type = type; + this.startup = startup; + this.name = name; + this.className = className; + this.isDefault = isdefault; + this.initArgs = initArgs; + attributes = otherAttrs == null ? Collections.emptyMap() : otherAttrs; + } + + + public PluginInfo(Node node, String err, boolean requireName) { + type = node.getNodeName(); + name = DOMUtil.getAttr(node, "name", requireName ? err : null); + className = DOMUtil.getAttr(node, "class", err); + isDefault = Boolean.parseBoolean(DOMUtil.getAttr(node, "default", null)); + startup = DOMUtil.getAttr(node, "startup", null); + initArgs = DOMUtil.childNodesToNamedList(node); + Map m = new HashMap(); + NamedNodeMap nnm = node.getAttributes(); + for (int i = 0; i < nnm.getLength(); i++) { + String name = nnm.item(i).getNodeName(); + m.put(name, nnm.item(i).getNodeValue()); + } + attributes = Collections.unmodifiableMap(m); + + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("{"); + if (name != null) sb.append("name = " + name + ","); + if (className != null) sb.append("class = " + className + ","); + if (isDefault) sb.append("default = " + isDefault + ","); + if (startup != null) sb.append("startup = " + startup + ","); + if (initArgs.size() > 0) sb.append("args = " + initArgs); + sb.append("}"); + return sb.toString(); + } + +} diff --git a/src/java/org/apache/solr/core/RequestHandlers.java b/src/java/org/apache/solr/core/RequestHandlers.java index a7c68a59179..0e53e16e2de 100644 --- a/src/java/org/apache/solr/core/RequestHandlers.java +++ b/src/java/org/apache/solr/core/RequestHandlers.java @@ -135,8 +135,8 @@ final class RequestHandlers { */ void initHandlersFromConfig(SolrConfig config ){ - Map handlers = new HashMap(); - for (SolrConfig.PluginInfo info : config.getReqHandlerInfo()) { + Map handlers = new HashMap(); + for (PluginInfo info : config.getReqHandlerInfo()) { try { SolrRequestHandler requestHandler; if( info.startup != null ) { @@ -166,7 +166,7 @@ final class RequestHandlers { SolrException.logOnce(log,null,e); } } - for (Map.Entry entry : handlers.entrySet()) { + for (Map.Entry entry : handlers.entrySet()) { entry.getValue().init(entry.getKey().initArgs); } diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.java index 1f881d3ba88..beedf4797dc 100644 --- a/src/java/org/apache/solr/core/SolrConfig.java +++ b/src/java/org/apache/solr/core/SolrConfig.java @@ -460,61 +460,6 @@ public class SolrConfig extends Config { } } - public static class PluginInfo { - public final String startup, name, className; - public final boolean isDefault; - public final NamedList initArgs; - public final Map otherAttributes; - - public PluginInfo(String startup, String name, String className, - boolean isdefault, NamedList initArgs, Map otherAttrs) { - this.startup = startup; - this.name = name; - this.className = className; - this.isDefault = isdefault; - this.initArgs = initArgs; - otherAttributes = otherAttrs == null ? Collections.emptyMap(): otherAttrs; - } - - - public PluginInfo(Node node, String err, boolean requireName) { - name = DOMUtil.getAttr(node, "name", requireName ? err : null); - className = DOMUtil.getAttr(node, "class", err ); - isDefault = Boolean.parseBoolean(DOMUtil.getAttr(node, "default", null)); - startup = DOMUtil.getAttr(node, "startup",null); - initArgs = DOMUtil.childNodesToNamedList(node); - Map m = new HashMap(); - NamedNodeMap nnm = node.getAttributes(); - for (int i = 0; i < nnm.getLength(); i++) { - String name= nnm.item(i).getNodeName(); - if(knownAttrs.contains(name)) continue; - m.put(name, nnm.item(i).getNodeValue()); - } - otherAttributes = m.isEmpty() ? - Collections.emptyMap(): - Collections.unmodifiableMap(m); - - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("{"); - if(name != null) sb.append("name = "+name +","); - if(className != null) sb.append("class = "+className +","); - if(isDefault) sb.append("default = "+isDefault +","); - if(startup != null) sb.append("startup = "+startup +","); - if(initArgs.size() >0) sb.append("args = "+initArgs); - sb.append("}"); - return sb.toString(); - } - private static final Set knownAttrs = new HashSet(); - static { - knownAttrs.add("name"); - knownAttrs.add("class"); - knownAttrs.add("startup"); - knownAttrs.add("default"); - } - } public List getReqHandlerInfo() { return reqHandlerInfo; } diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index 24a3e17c8db..49fa6765a37 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -248,7 +248,7 @@ public final class SolrCore implements SolrInfoMBean { } private void initDeletionPolicy() { - SolrConfig.PluginInfo info = solrConfig.getDeletionPolicyInfo(); + PluginInfo info = solrConfig.getDeletionPolicyInfo(); IndexDeletionPolicy delPolicy = null; if(info != null){ delPolicy = createInstance(info.className,IndexDeletionPolicy.class,"Deletion Policy for SOLR"); @@ -261,9 +261,9 @@ public final class SolrCore implements SolrInfoMBean { solrDelPolicy = new IndexDeletionPolicyWrapper(delPolicy); } - private List parseListener(List path) { + private List parseListener(List path) { List lst = new ArrayList(); - for (SolrConfig.PluginInfo info : path) { + for (PluginInfo info : path) { SolrEventListener listener = createEventListener(info.className); listener.init(info.initArgs); lst.add(listener); @@ -328,7 +328,7 @@ public final class SolrCore implements SolrInfoMBean { private void initDirectoryFactory() { DirectoryFactory dirFactory; - SolrConfig.PluginInfo info = solrConfig.getDirectoryfactoryInfo(); + PluginInfo info = solrConfig.getDirectoryfactoryInfo(); if (info != null) { dirFactory = (DirectoryFactory) getResourceLoader().newInstance(info.className); dirFactory.init(info.initArgs); @@ -341,7 +341,7 @@ public final class SolrCore implements SolrInfoMBean { private void initIndexReaderFactory() { IndexReaderFactory indexReaderFactory; - SolrConfig.PluginInfo info = solrConfig.getIndexReaderFactoryInfo(); + PluginInfo info = solrConfig.getIndexReaderFactoryInfo(); if (info != null) { indexReaderFactory = (IndexReaderFactory) resourceLoader.newInstance(info.className); indexReaderFactory.init(info.initArgs); @@ -590,19 +590,19 @@ public final class SolrCore implements SolrInfoMBean { private Map loadUpdateProcessorChains() { final Map map = new HashMap(); UpdateRequestProcessorChain def = null; - Map> infos = solrConfig.getUpdateProcessorChainInfo(); + Map> infos = solrConfig.getUpdateProcessorChainInfo(); if (!infos.isEmpty()) { boolean defaultProcessed = false; - List defProcessorChainInfo = infos.get(null);// this is the default one - for (Map.Entry> e : solrConfig.getUpdateProcessorChainInfo().entrySet()) { - List processorsInfo = e.getValue(); + List defProcessorChainInfo = infos.get(null);// this is the default one + for (Map.Entry> e : solrConfig.getUpdateProcessorChainInfo().entrySet()) { + List processorsInfo = e.getValue(); if (processorsInfo == defProcessorChainInfo && defaultProcessed) { map.put(e.getKey(), def); continue; } UpdateRequestProcessorFactory[] chain = new UpdateRequestProcessorFactory[processorsInfo.size()]; for (int i = 0; i < processorsInfo.size(); i++) { - SolrConfig.PluginInfo info = processorsInfo.get(i); + PluginInfo info = processorsInfo.get(i); chain[i] = createInstance(info.className, UpdateRequestProcessorFactory.class, null); chain[i].init(info.initArgs); } @@ -1465,9 +1465,9 @@ public final class SolrCore implements SolrInfoMBean { } } - public T initPlugins(List pluginInfos , Map registry, Class type){ + public T initPlugins(List pluginInfos , Map registry, Class type){ T def = null; - for (SolrConfig.PluginInfo info : pluginInfos) { + for (PluginInfo info : pluginInfos) { T o = createInstance(info.className,type, type.getSimpleName()); if (o instanceof NamedListInitializedPlugin) { ((NamedListInitializedPlugin) o).init(info.initArgs); diff --git a/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java index de60c2c97f1..5e2cfa88317 100644 --- a/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java +++ b/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java @@ -42,6 +42,7 @@ import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.core.SolrConfig; +import org.apache.solr.core.PluginInfo; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.SchemaField; @@ -63,7 +64,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter // Load the fragmenters ResourceLoader loader= config.getResourceLoader(); SolrFragmenter frag = null; - for (SolrConfig.PluginInfo info : config.getHighlightingFragmenterInfo()) { + for (PluginInfo info : config.getHighlightingFragmenterInfo()) { SolrFragmenter fragmenter = (SolrFragmenter) loader.newInstance(info.className); fragmenter.init(info.initArgs); if(info.isDefault) frag = fragmenter; @@ -77,7 +78,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter fragmenters.put( null, frag ); // Load the formatters SolrFormatter fmt = null; - for (SolrConfig.PluginInfo info : config.getHighlightingFormatterInfo()) { + for (PluginInfo info : config.getHighlightingFormatterInfo()) { SolrFormatter formatter = (SolrFormatter) loader.newInstance(info.className); formatter.init(info.initArgs); formatters.put(info.name, formatter);