org.dellroad.stuff.main
Class ContextMainClass

java.lang.Object
  extended by org.dellroad.stuff.main.MainClass
      extended by org.dellroad.stuff.main.ContextMainClass

public abstract class ContextMainClass
extends MainClass

Support superclass for MainClass implementations that wish to execute with an associated Spring application context.


Field Summary
protected  ClassPathXmlApplicationContext context
           
 
Fields inherited from class org.dellroad.stuff.main.MainClass
log
 
Constructor Summary
ContextMainClass()
           
 
Method Summary
protected  void autowire()
          Autowire this instance using its associated application context.
protected  String getContextLocation()
          Get the classpath location of this instance's associated XML application context.
 int run(String[] args)
          Subclass main implementation.
protected abstract  int runInContext(String[] args)
          Execute the main method.
 
Methods inherited from class org.dellroad.stuff.main.MainClass
commandLoop, doMain, errout, handleCommand, parsePropertyFlags, usageError, usageMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected ClassPathXmlApplicationContext context
Constructor Detail

ContextMainClass

public ContextMainClass()
Method Detail

getContextLocation

protected String getContextLocation()
Get the classpath location of this instance's associated XML application context. The returned string will resolved on the classpath relative to this instance's class.

The implementation in ContextMainClass returns getClass().getSimpleName() + ".xml", which will locate an XML file in the same package and with the same name.


autowire

protected void autowire()
Autowire this instance using its associated application context. This may be invoked by runInContext(java.lang.String[]) to autowire this bean using its associated context.

For this to work, the application context must have autowiring enabled, e.g., via <context:annotation-config/>.


run

public final int run(String[] args)
              throws Exception
Description copied from class: MainClass
Subclass main implementation. This method is free to throw exceptions; these will be displayed on standard error and converted into non-zero exit values.

Specified by:
run in class MainClass
Returns:
exit value
Throws:
Exception

runInContext

protected abstract int runInContext(String[] args)
                             throws Exception
Execute the main method. The application context will be open when this method is invoked.

Throws:
Exception