package org.datacite.mds.tools;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public abstract class AbstractTool {
    
    private static final String APPLICATION_CONTEXT = "META-INF/spring/applicationContext.xml";
    
    private static final ApplicationContext context = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT);
    
    @SuppressWarnings("unchecked")
    public static final void initAndRun(String[] args) {
        try {
            String callingClassName = Thread.currentThread().getStackTrace()[2].getClassName();
            Class<AbstractTool> callingClass = (Class<AbstractTool>) Class.forName(callingClassName);
            AbstractTool tool = context.getBean(callingClass);
            tool.run(args);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    
    public abstract void run(String[] args);
}

@@ -304,124 +304,8 @@
    %0A
-    private static final ApplicationContext context = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT);%0A    %0A
     
@@ -406,16 +406,114 @@
   try %7B%0A
+            ApplicationContext context = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT);%0A
         

fix for failed tests