*/
private Map<String,UpdateRequestProcessorChain> loadUpdateProcessorChains() {
final Map<String,UpdateRequestProcessorChain> map = new HashMap<String, UpdateRequestProcessorChain>();
final String parsingErrorText = "Parsing Update Request Processor Chain";
UpdateRequestProcessorChain def = null;
// This is kinda ugly, but at least it keeps the xpath logic in one place
// away from the Processors themselves.
XPath xpath = solrConfig.getXPath();
NodeList nodes = (NodeList)solrConfig.evaluate("updateRequestProcessorChain", XPathConstants.NODESET);
boolean requireName = nodes.getLength() > 1;
if (nodes !=null ) {
for (int i=0; i<nodes.getLength(); i++) {
Node node = nodes.item(i);
String name = DOMUtil.getAttr(node,"name", requireName?parsingErrorText:null);
boolean isDefault = "true".equals( DOMUtil.getAttr(node,"default", null ) );
NodeList links = null;
try {
links = (NodeList)xpath.evaluate("processor", node, XPathConstants.NODESET);
}
catch (XPathExpressionException e) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error reading processors",e,false);
}
if( links == null || links.getLength() < 1 ) {
throw new RuntimeException( "updateRequestProcessorChain require at least one processor");
}
// keep a list of the factories...
final ArrayList<UpdateRequestProcessorFactory> factories = new ArrayList<UpdateRequestProcessorFactory>(links.getLength());
// Load and initialize the plugin chain
AbstractPluginLoader<UpdateRequestProcessorFactory> loader
= new AbstractPluginLoader<UpdateRequestProcessorFactory>( "processor chain", false, false ) {
@Override
protected void init(UpdateRequestProcessorFactory plugin, Node node) throws Exception {
plugin.init( (node==null)?null:DOMUtil.childNodesToNamedList(node) );
}
@Override
protected UpdateRequestProcessorFactory register(String name, UpdateRequestProcessorFactory plugin) throws Exception {
factories.add( plugin );
return null;
}
};
loader.load( solrConfig.getResourceLoader(), links );
UpdateRequestProcessorChain chain = new UpdateRequestProcessorChain(
factories.toArray( new UpdateRequestProcessorFactory[factories.size()] ) );
if( isDefault || nodes.getLength()==1 ) {
def = chain;
}
if( name != null ) {
map.put(name, chain);
}
}
}
if( def == null ) {
// construct the default chain
UpdateRequestProcessorFactory[] factories = new UpdateRequestProcessorFactory[] {
new RunUpdateProcessorFactory(),
new LogUpdateProcessorFactory()
};
def = new UpdateRequestProcessorChain( factories );
}
map.put( null, def );
map.put( "", def );
return map;
}