* to generate meaningful error messages
*/
@Activate
protected void activate(ComponentContext context) throws ConfigurationException {
log.info("Activate {}: ",getClass().getSimpleName());
SolrServerProperties properties = null;
Object value = context.getProperties().get(PROPERTY_SERVER_DIR);
if(value == null || value.toString().isEmpty()){
throw new ConfigurationException(PROPERTY_SERVER_DIR, "The Server directory is a " +
"required configuration and MUST NOT be NULL nor empty!");
} else {
File solrServerDir = new File(value.toString());
if(solrServerDir.isDirectory()){
log.info(" > solrDir = {}",solrServerDir);
properties = new SolrServerProperties(solrServerDir);
} else {
throw new ConfigurationException(PROPERTY_SERVER_DIR, "The parsed Solr Server directpry '"+
value+"' does not exist or is not a directory!");
}
}
value = context.getProperties().get(PROPERTY_SERVER_NAME);
if(value == null || value.toString().isEmpty()){
throw new ConfigurationException(PROPERTY_SERVER_NAME, "The Server Name is a required" +
"Configuration and MUST NOT be NULL nor empty!");
} else {
properties.setServerName(value.toString());
log.info(" > Name = {}",value.toString());
}
value = context.getProperties().get(PROPERTY_SERVER_RANKING);
if(value instanceof Number){
properties.setServerRanking(((Number)value).intValue());
} else if(value != null && !value.toString().isEmpty()){
try {
properties.setServerRanking(Integer.parseInt(value.toString()));
log.info(" > Ranking = {}",properties.getServerRanking());
}catch (NumberFormatException e) {
throw new ConfigurationException(PROPERTY_SERVER_RANKING, "The configured Server Ranking '"+
value+" can not be converted to an Integer!",e);
}
} //else not present or empty string -> do not set a ranking!
value = properties.get(PROPERTY_SERVER_PUBLISH_REST);
if(value == null || value instanceof Boolean) {
properties.setPublishREST((Boolean)value);
} else {
properties.setPublishREST(Boolean.parseBoolean(value.toString()));
}
log.info(" > publisRest = {}",properties.isPublishREST());
try {
server = new SolrServerAdapter(context.getBundleContext(), properties);
} catch (ParserConfigurationException e) {
throw new IllegalStateException("Unable to initialise the XML parser " +
"for parsing the SolrServer Configuration for Server '"+
properties.getServerName()+"' (dir="+
properties.getServerDir()+")!",e);
} catch (IOException e) {
throw new ConfigurationException(PROPERTY_SERVER_DIR, "Unable to initialise " +
"a SolrServer based on the Directory '"+properties.getServerDir() +
"'!",e);
} catch (SAXException e) {
throw new ConfigurationException(PROPERTY_SERVER_DIR, "Unable to initialise " +
"a SolrServer based on the Directory '"+properties.getServerDir() +
"'!",e);
}
log.info(" ... SolrServer successfully initialised!");
}