All Packages  Class Hierarchy  This Package  Previous  Next  Index


Class Acme.Application

java.lang.Object
   |
   +----Acme.Application

public abstract class Application
extends Object
Superclass for embeddable applications.

Make all your applications a subclass of this, and you can more easily embed them in larger applications or applets. What it does is define an enhanced main routine that gives you three standard I/O streams to use instead of System.in, System.out, and System.err.

When run from the command line there's no difference between the enhanced main and the regular one - you get the System streams. The point of this class is that you can also run your applications from applets, from other applications, in pipelines, and in contexts yet to be invented, and then you get passed other streams appropriate to those contexts.

There are a few simple steps to converting your application to use this class.

  1. Make it a subclass of this class:
     public class YourApp extends Acme.Application
     
  2. Change the declaration of your existing main() routine to look like this:
     public int newMain( String[] args )
     
    Note that the enhanced newMain() is *not* static. It must be an instance method so that it can be called at runtime - Java has no way to call a static method of a runtime-loaded class.
  3. Add an old-style main() that calls a compatibility routine:
     public static void main( String[] args )
         {
         (new YourApp()).compat( args );
         }
     
    This lets you continue to run your application from the command line.
  4. Change your application to use the I/O streams in, out, and err, instead of directly using the ones from System. These are now variables in your class, inherited from Acme.Application, and are initialized with streams appropriate to the context in which you are running.
  5. Don't call System.exit(). Instead, return your exit status from the newMain() routine.
  6. Change all your static methods and variables to be non-static. As noted in step 3, peculiarities of Java mean the enhanced main must be non-static. Since this is required, you might as well take advantage of it and make the rest of your application non-static too. The advantage is you'll be able to run multiple copies of it at the same time in the same Java VM; perhaps in a pipeline.

    But be sure and leave the old-style main() static.

And that's about it.

Fetch the software.
Fetch the entire Acme package.

For an example of a non-command-line context that can call these enhanced Applications,

See Also:
ApplicationApplet

Variable Index

 o err
 o in
 o out

Constructor Index

 o Application()

Method Index

 o compat(String[])
Compatibility gateway between old-style static main() and new-style non-static.
 o compat(String[], InputStream, PrintStream, PrintStream)
Compatibility gateway for contexts other than old-style main().
 o newMain(String[])
Definition for enhanced main.

Variables

 o in
 protected InputStream in
 o out
 protected PrintStream out
 o err
 protected PrintStream err

Constructors

 o Application
 public Application()

Methods

 o compat
 public void compat(String args[])
Compatibility gateway between old-style static main() and new-style non-static. Does not return.

 o compat
 public int compat(String args[],
                   InputStream stdin,
                   PrintStream stdout,
                   PrintStream stderr)
Compatibility gateway for contexts other than old-style main().

 o newMain
 public abstract int newMain(String args[])
Definition for enhanced main. Subclasses implement this instead of the old static version of main(). This has to be an instance method instead of a static method because there's some bug with inherited static main()s.

Returns:
exit status, 0 for ok

All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs