package gov.nih.nci.nbia.textsupport;

import java.io.File;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.CoreContainer;
import gov.nih.nci.nbia.util.NCIAConfig;

public class NBIAEmbeddedSolrServer implements SolrServerInterface{
	   private static SolrServer server;
	   private static String solrHome=NCIAConfig.getSolrHome();
	   static Logger log = Logger.getLogger(NBIAEmbeddedSolrServer.class);
	   // Spring maintains this as a singleton so this only happens once
	   public NBIAEmbeddedSolrServer() {
	         startServer();
	   }
	   private void startServer()
	   {
		   log.warn("SolrHome is "+solrHome);
			server = new EmbeddedSolrServer(CoreContainer.createAndLoad(
					solrHome, new File(solrHome + "solr.xml")), null);
			log.info("Embedded Solr Server started successfully");
	   }
	   private void stopServer()
	   {
		   server.shutdown();
	   }
	   protected void finalize() throws Throwable {
		     try {
		    	 stopServer();        // close open files
		     } finally {
		         super.finalize();
		     }
	   }
	   public SolrServer GetServer()
	   {
		   return server;
	   }
	   public String getSolrHome()
	   {
		   return solrHome;
	   }
}

@@ -238,24 +238,25 @@
 eContainer;%0A
+%0A
 import gov.n
@@ -705,16 +705,25 @@
  %7B%0A%09%09   
+try %7B%0A%09%09%09
 log.warn
@@ -749,16 +749,17 @@
 rHome);%0A
+%09
 %09%09%09serve
@@ -819,16 +819,17 @@
 d(%0A%09%09%09%09%09
+%09
 solrHome
@@ -871,16 +871,17 @@
  null);%0A
+%09
 %09%09%09log.i
@@ -930,16 +930,108 @@
 ully%22);%0A
+%09%09%7D catch (Exception e) %7B%0A%09%09%09log.error(%22Unable to start Solr%22);%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %09   %7D%0A%09 

deal with config not found