Standardize calling mechanism for classes with main() routines
--------------------------------------------------------------
Key: DERBY-295
URL: http://issues.apache.org/jira/browse/DERBY-295
Project: Derby
Type: Improvement
Components: Tools
Versions: 10.1.0.0
Reporter: David Van Couvering
Priority: Minor
We need a standard, common agreed upon design pattern and mechanism for how
applications can embed and invoke classes that have a main() routine in them,
like ij, dblook, etc.
See
http://mail-archives.apache.org/mod_mbox/db-derby-dev/200504.mbox/[EMAIL
PROTECTED]
(or http://tinyurl.com/b4qjc)
for the mail thread that discusses this.
The conclusion was the following:
- There should be a *non-static* public method that can be used to execute a
class
with a main() routine
- Properties are set prior to calling this public method using the standard
JavaBeans get/set pattern
- We should have a new interface called Executable or something similar that
defines this contract, and our tools should be modified to implement this
interface
- The main() routine should call this method after processing arguments.
The Executable interface would look something like:
public interface Executable
{
public void execute() throws Exception;
}
So then you would have:
public class MyMain implements Executable
{
public int length;
public int duration;
public static void main(String[] args)
{
try
{
MyMain me = new myMain();
me.processArgs(args);
me.execute();
}
catch ( Exception e )
{
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
public void processArgs(String[] args)
{
// handwaving around argument processing
setLength(getLength(args));
setDuration(getDuration(args));
}
public void setLength(int length)
{
this.length = length;
}
public void setDuration(int duration)
{
this.duration = duration;
}
public void execute() throws Exception
{
// this is where the real work happens...
}
}
An example embedded use:
MyTool tool = new MyTool();
tool.setLength(2);
tool.setDuration(12);
tool.execute();
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira