try {
// pass the config resource loader to avoid building an empty one for no reason:
// in the current case though, the stream is valid so we wont load the resource by name
final Config schemaConf = new Config(loader, "datatypeConfig", is, "/datatypeConfig/");
final Document document = schemaConf.getDocument();
final XPath xpath = schemaConf.getXPath();
final Node nd = (Node) xpath.evaluate("/datatypeConfig/@name", document, XPathConstants.NODE);
if (nd == null) {
log.warn("datatypeConfig has no name!");
}
else {
name = nd.getNodeValue();
log.info("datatypeConfig name=" + name);
}
version = schemaConf.get("/datatypeConfig/@version");
final AbstractPluginLoader<Datatype> datatypeLoader =
new AbstractPluginLoader<Datatype>("[datatypeConfig] datatype",
Datatype.class, true, true) {
@Override
protected Datatype create(final SolrResourceLoader loader,
final String name, final String className,
final Node node)
throws Exception {
final Datatype dt = loader.newInstance(className, Datatype.class);
dt.setDatatypeName(name);
// An analyzer with type="index"
String expression = "./analyzer[@type='index']";
Node anode = (Node) xpath.evaluate(expression, node, XPathConstants.NODE);
final Analyzer analyzer = AnalyzerConfigReader.readAnalyzer(anode,
loader, luceneMatchVersion);
if (analyzer != null) dt.setAnalyzer(analyzer);
expression = "./analyzer[@type='query']";
anode = (Node) xpath.evaluate(expression, node, XPathConstants.NODE);
final Analyzer queryAnalyzer = AnalyzerConfigReader.readAnalyzer(anode,
loader, luceneMatchVersion);
if (queryAnalyzer != null) dt.setQueryAnalyzer(queryAnalyzer);
return dt;
}
@Override
protected void init(final Datatype plugin, final Node node)
throws Exception {
final Map<String,String> params = DOMUtil.toMapExcept(node.getAttributes(), "name", "class");
plugin.setArgs(params);
}
@Override
protected Datatype register(final String name, final Datatype plugin)
throws Exception {
log.trace("datatype defined: " + plugin);
return datatypes.put(name, plugin);
}
};
final String expression = "/datatypeConfig/datatype";
final NodeList nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
datatypeLoader.load(loader, nodes);
}
catch (final SolrException e) {
throw e;
}