mirror of https://github.com/apache/lucene.git
LUCENE-4260: factor subPackages out of the resourceloader interface
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1366360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
53dc0191b5
commit
467faeaae0
|
@ -36,9 +36,8 @@ public class ResourceAsStreamResourceLoader implements ResourceLoader {
|
|||
return clazz.getResourceAsStream(resource);
|
||||
}
|
||||
|
||||
// TODO: do this subpackages thing... wtf is that?
|
||||
@Override
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages) {
|
||||
public <T> T newInstance(String cname, Class<T> expectedType) {
|
||||
try {
|
||||
Class<? extends T> clazz = Class.forName(cname).asSubclass(expectedType);
|
||||
return clazz.newInstance();
|
||||
|
|
|
@ -33,5 +33,6 @@ public interface ResourceLoader {
|
|||
/**
|
||||
* Creates a class of the name and expected type
|
||||
*/
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String ... subpackages);
|
||||
// TODO: fix exception handling
|
||||
public <T> T newInstance(String cname, Class<T> expectedType);
|
||||
}
|
|
@ -67,26 +67,6 @@ public class TestSnowballPorterFilterFactory extends BaseTokenStreamTestCase {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
class LinesMockSolrResourceLoader implements ResourceLoader {
|
||||
List<String> lines;
|
||||
|
||||
LinesMockSolrResourceLoader(List<String> lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
public List<String> getLines(String resource) throws IOException {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public InputStream openResource(String resource) throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the protected words mechanism of SnowballPorterFilterFactory
|
||||
|
|
|
@ -29,8 +29,7 @@ public class StringMockResourceLoader implements ResourceLoader {
|
|||
this.text = text;
|
||||
}
|
||||
|
||||
// TODO: do this subpackages thing... wtf is that?
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages) {
|
||||
public <T> T newInstance(String cname, Class<T> expectedType) {
|
||||
try {
|
||||
Class<? extends T> clazz = Class.forName(cname).asSubclass(expectedType);
|
||||
return clazz.newInstance();
|
||||
|
|
|
@ -33,8 +33,7 @@ class StringMockResourceLoader implements ResourceLoader {
|
|||
this.text = text;
|
||||
}
|
||||
|
||||
// TODO: do this subpackages thing... wtf is that?
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages) {
|
||||
public <T> T newInstance(String cname, Class<T> expectedType) {
|
||||
try {
|
||||
Class<? extends T> clazz = Class.forName(cname).asSubclass(expectedType);
|
||||
return clazz.newInstance();
|
||||
|
|
|
@ -448,6 +448,12 @@ public class SolrResourceLoader implements ResourceLoader
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final String empty[] = new String[0];
|
||||
|
||||
public <T> T newInstance(String name, Class<T> expectedType) {
|
||||
return newInstance(name, expectedType, empty);
|
||||
}
|
||||
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String ... subpackages) {
|
||||
Class<? extends T> clazz = findClass(cname, expectedType, subpackages);
|
||||
|
|
|
@ -73,7 +73,7 @@ public final class FieldTypePluginLoader
|
|||
|
||||
|
||||
@Override
|
||||
protected FieldType create( ResourceLoader loader,
|
||||
protected FieldType create( SolrResourceLoader loader,
|
||||
String name,
|
||||
String className,
|
||||
Node node ) throws Exception {
|
||||
|
|
|
@ -698,7 +698,7 @@ public final class IndexSchema {
|
|||
return newArr;
|
||||
}
|
||||
|
||||
static SimilarityFactory readSimilarity(ResourceLoader loader, Node node) {
|
||||
static SimilarityFactory readSimilarity(SolrResourceLoader loader, Node node) {
|
||||
if (node==null) {
|
||||
return null;
|
||||
} else {
|
||||
|
|
|
@ -22,11 +22,11 @@ import java.util.List;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.lucene.analysis.util.ResourceLoader;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
import org.apache.solr.util.DOMUtil;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
@ -81,7 +81,7 @@ public abstract class AbstractPluginLoader<T>
|
|||
* @param node - the XML node defining this plugin
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T create( ResourceLoader loader, String name, String className, Node node ) throws Exception
|
||||
protected T create( SolrResourceLoader loader, String name, String className, Node node ) throws Exception
|
||||
{
|
||||
return loader.newInstance(className, pluginClassType, getDefaultPackages());
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public abstract class AbstractPluginLoader<T>
|
|||
* If a default element is defined, it will be returned from this function.
|
||||
*
|
||||
*/
|
||||
public T load( ResourceLoader loader, NodeList nodes )
|
||||
public T load( SolrResourceLoader loader, NodeList nodes )
|
||||
{
|
||||
List<PluginInitInfo> info = new ArrayList<PluginInitInfo>();
|
||||
T defaultPlugin = null;
|
||||
|
@ -204,7 +204,7 @@ public abstract class AbstractPluginLoader<T>
|
|||
* The created class for the plugin will be returned from this function.
|
||||
*
|
||||
*/
|
||||
public T loadSingle(ResourceLoader loader, Node node) {
|
||||
public T loadSingle(SolrResourceLoader loader, Node node) {
|
||||
List<PluginInitInfo> info = new ArrayList<PluginInitInfo>();
|
||||
T plugin = null;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class StringMockSolrResourceLoader implements ResourceLoader {
|
|||
this.text = text;
|
||||
}
|
||||
|
||||
public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages) {
|
||||
public <T> T newInstance(String cname, Class<T> expectedType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue