: Class Code

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.mortbay.Base
Class Code

    java.lang.Object
      |
      +--com.mortbay.Base.Code

public class Code
extends java.lang.Object

Coding Standards support. Support for defensive programming Coding defensively as follows:

     {
        ...
        Code.assert(booleanExpression(),"Assert that expression evaluates true");
        ...
        Code.assertEquals(objectA,objectB,"Assert equality");
        Code.assertEquals(1,2,"Assert equality");
        ...
        Code.debug("Debug message");
        ...
        Code.debug("Debug message",exception,object);
        ...
        Code.warning("warning message");
        ...
        Code.warning("warning message",exception);
        ...
        Code.notImplemented();
        Code.fail("fatal error");
        ...
     }

The debug output can be controlled with java properties:

- DEBUG - If set, debug output is enabled
- DEBUG_PATTERNS - If set to a comma separated list of strings, Then debug output is only produced from those classes whose fully qualified class name contains one of the strings as a substring.
- DEBUG_OPTIONS - A string of option character. 'W' - suppress warnings unless debug is on, 'S' suppress stack frame dumps
- DEBUG_VERBOSE - Set to an integer verbosity level for use in controlling debug verbosity (see verbose(int))

  #### Usage

       java [-DDEBUG [-DDEBUG_PATTERNS="MyClass,my.package"] \\
                     [-DDEBUG_OPTIONS=[S][W]] \\
                     [-DDEBUG_VERBOSE=n] ] \\
            my.package.main

  Version:
    $Id: Code.java,v 2.9 2000/06/02 23:41:04 gregw Exp $
  Author:
    Greg Wilkins
  See Also:
    `ISS.Base.Log`

  Constructor Summary
  `protected` | `Code()` Construct shared instance that decodes the options setup environments properties.

  Method Summary
  `static void` | `assert(boolean b)` Check assertion that a boolean is true.
  `static void` | `assert(boolean b, java.lang.String m)` Check assertion that a boolean is true.
  `static void` | `assertContains(java.lang.String string, java.lang.String sub, java.lang.String m)` Check assertion that a string is a substring of another.
  `static void` | `assertEquals(char o1, char o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` | `assertEquals(double o1, double o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` | `assertEquals(long o1, long o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` | `assertEquals(java.lang.Object o1, java.lang.Object o2, java.lang.String m)` Check assertion that o1==o2.
  `static boolean` | `debug()` Get debug status for the current stack frame
  `static void` | `debug(java.lang.Object o)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, long l1)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, long l1, java.lang.Object o2, long l2)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, long l1)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6, java.lang.Object o7)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6, java.lang.Object o7, java.lang.Object o8)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.String m)` Programming debugging output sent to the Log.
  `static void` | `debug(java.lang.String m, java.lang.Throwable ex)` As debug(String) Do not rely on side-effects
  `static void` | `debug(java.lang.Throwable ex)` As debug(String) Don Notnot rely on side-effects
  `static void` | `fail(java.lang.String m)` Programmer initiated fatal CodeException.
  `static void` | `fail(java.lang.String m, java.lang.Throwable ex)` Programmer initiated fatal error.
  `static void` | `fail(java.lang.Throwable ex)` Programmer initiated fatal error.
  `static boolean` | `getDebug()` Get the debug status
  `static java.lang.String` | `getDebugPatterns()` Get the debug patterns
  `static java.lang.String` | `getDebugTriggers()` Get the debug triggers
  `static boolean` | `getSuppressStack()` Get the stack suppression status
  `static boolean` | `getSuppressWarnings()` Get the warnings suppression status
  `static int` | `getVerbose()` Get the verbosity level
  `static void` | `ignore(java.lang.Throwable ex)` Ignore an exception
  `static void` | `initParamsFromApplet(java.applet.Applet appl)` Initialize default behaviour from applet parameters Look for applet parameters of the same name as the system properties used to config Code.
  `static void` | `notImplemented()` Standard fatal error for a method not yet implemented
  `static void` | `setDebug(boolean debug)` Set if debugging is on or off
  `static void` | `setDebugPatterns(java.lang.String patterns)` Set debug patterns
  `static void` | `setDebugTriggers(java.lang.String triggers)` Set debug triggers
  `static void` | `setSuppressStack(boolean stack)` Suppress stack trace
  `static void` | `setSuppressWarnings(boolean warnings)` Set warning suppression
  `static void` | `setVerbose(int verbose)` Set verbosity level
  `static void` | `triggerOff(java.lang.String trigger)`
  `static void` | `triggerOn(java.lang.String trigger)`
  `static boolean` | `verbose()` Get verbosity level
  `static boolean` | `verbose(int v)` Get verbosity level
  `static void` | `warning(java.lang.String m)` Programmer initiated warning, intended to be viewed by technical not operational staff.
  `static void` | `warning(java.lang.String m, java.lang.Throwable ex)` Programmer initiated warning, intended to be viewed by technical not operational staff.
  `static void` | `warning(java.lang.Throwable ex)` Programmer initiated warning, intended to be viewed by technical not operational staff.

  Methods inherited from class java.lang.Object
  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  Constructor Detail

  ### Code

      protected Code()

    Construct shared instance that decodes the options setup environments properties.

  Method Detail

  ### initParamsFromApplet

      public static void initParamsFromApplet(java.applet.Applet appl)

    Initialize default behaviour from applet parameters Look for applet parameters of the same name as the system properties used to config Code.

  ### setDebug

      public static void setDebug(boolean debug)

    Set if debugging is on or off
    Parameters:
      `debug` -

  ### getDebug

      public static boolean getDebug()

    Get the debug status
    Returns:
      the debug status

  ### setSuppressStack

      public static void setSuppressStack(boolean stack)

    Suppress stack trace
    Parameters:
      `stack` - if true stacks are not produced

  ### getSuppressStack

      public static boolean getSuppressStack()

    Get the stack suppression status
    Returns:
      the stack suppression status

  ### setSuppressWarnings

      public static void setSuppressWarnings(boolean warnings)

    Set warning suppression
    Parameters:
      `warnings` - Warnings suppress if this is true and debug is false

  ### getSuppressWarnings

      public static boolean getSuppressWarnings()

    Get the warnings suppression status
    Returns:
      the warnings suppression status

  ### setVerbose

      public static void setVerbose(int verbose)

    Set verbosity level
    Parameters:
      `verbose` -

  ### getVerbose

      public static int getVerbose()

    Get the verbosity level
    Returns:
      the verbosity level

  ### setDebugPatterns

      public static void setDebugPatterns(java.lang.String patterns)

    Set debug patterns
    Parameters:
      `patterns` - coma separated string of patterns

  ### getDebugPatterns

      public static java.lang.String getDebugPatterns()

    Get the debug patterns
    Returns:
      Coma separated list of debug patterns

  ### setDebugTriggers

      public static void setDebugTriggers(java.lang.String triggers)

    Set debug triggers
    Parameters:
      `triggers` - coma separated string of triggers

  ### getDebugTriggers

      public static java.lang.String getDebugTriggers()

    Get the debug triggers
    Returns:
      Coma separated list of debug triggers

  ### triggerOn

      public static void triggerOn(java.lang.String trigger)

  ### triggerOff

      public static void triggerOff(java.lang.String trigger)

  ### assert

      public static void assert(boolean b)

    Check assertion that a boolean is true. Logs and throws CodeException if the assertion fails.
    Parameters:
      `b` - The boolean to assert is true
    Throws:
      CodeException - Thrown if assertion fails

  ### assert

      public static void assert(boolean b,
                                java.lang.String m)

    Check assertion that a boolean is true. Logs and throws CodeException if the assertion fails.
    Parameters:
      `b` - The boolean to assert is true
      `m` - Message to log if assertion fails
    Throws:
      CodeException - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(java.lang.Object o1,
                                      java.lang.Object o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.
    Parameters:
      `o1` - The first object to check
      `o2` - The first object to check
      `m` - Message to log if assertion fails
    Throws:
      CodeException - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(long o1,
                                      long o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.
    Parameters:
      `o1` - The first long to check
      `o2` - The first long to check
      `m` - Message to log if assertion fails
    Throws:
      CodeException - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(double o1,
                                      double o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.
    Parameters:
      `o1` - The first double to check
      `o2` - The first double to check
      `m` - Message to log if assertion fails
    Throws:
      CodeException - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(char o1,
                                      char o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.
    Parameters:
      `o1` - The first char to check
      `o2` - The first char to check
      `m` - Message to log if assertion fails
    Throws:
      CodeException - Thrown if assertion fails

  ### assertContains

      public static void assertContains(java.lang.String string,
                                        java.lang.String sub,
                                        java.lang.String m)

    Check assertion that a string is a substring of another. Logs and throws CodeException if the assertion fails.
    Parameters:
      `string` - The string
      `sub` - The sub string
      `m` - Message to log if assertion fails
    Throws:
      CodeException - Thrown if assertion fails

  ### warning

      public static void warning(java.lang.String m)

    Programmer initiated warning, intended to be viewed by technical not operational staff.
    Parameters:
      `m` - The message body of the warning

  ### warning

      public static void warning(java.lang.String m,
                                 java.lang.Throwable ex)

    Programmer initiated warning, intended to be viewed by technical not operational staff.
    Parameters:
      `m` - The message body of the warning
      `ex` - A Throwable object

  ### warning

      public static void warning(java.lang.Throwable ex)

    Programmer initiated warning, intended to be viewed by technical not operational staff.
    Parameters:
      `ex` - A Throwable object

  ### fail

      public static void fail(java.lang.String m)

    Programmer initiated fatal CodeException.
    Parameters:
      `m` - The message body to log with the fatal error
    Throws:
      CodeException - thrown to cause fatal error

  ### fail

      public static void fail(java.lang.String m,
                              java.lang.Throwable ex)

    Programmer initiated fatal error.
    Parameters:
      `m` - The message body to log with the fatal error
      `ex` - The Throwable to print the full stack trace of
    Throws:
      CodeException - thrown to cause fatal error

  ### fail

      public static void fail(java.lang.Throwable ex)

    Programmer initiated fatal error.
    Parameters:
      `ex` - The Throwable to print the full stack trace of
    Throws:
      CodeException - thrown to cause fatal error

  ### notImplemented

      public static void notImplemented()

    Standard fatal error for a method not yet implemented

  ### verbose

      public static boolean verbose()

    Get verbosity level
    Returns:
      true if any level of verbosity is set.

  ### verbose

      public static boolean verbose(int v)

    Get verbosity level
    Parameters:
      `v` - verbosity level to check against
    Returns:
      true if current level of verbosity greater than or equal to v

  ### debug

      public static boolean debug()

    Get debug status for the current stack frame

  ### debug

      public static void debug(java.lang.String m)

    Programming debugging output sent to the Log. For debug output to be generated, the property DEBUG must be passed to the java VM. If the property DEBUG_PATTERN is set, it is used as a regular expression on the method, file and thread names to filter debug generation. Do not rely on side-effects
    Parameters:
      `m` - The debug message to log.

  ### debug

      public static void debug(java.lang.String m,
                               java.lang.Throwable ex)

    As debug(String) Do not rely on side-effects
    Parameters:
      `m` - The debug message to log.
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Throwable ex)

    As debug(String) Don Notnot rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               long l1)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               long l1)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               long l1,
                               java.lang.Object o2,
                               long l2)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5,
                               java.lang.Object o6)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5,
                               java.lang.Object o6,
                               java.lang.Object o7)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5,
                               java.lang.Object o6,
                               java.lang.Object o7,
                               java.lang.Object o8)

    As debug(String) Do not rely on side-effects
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### ignore

      public static void ignore(java.lang.Throwable ex)

    Ignore an exception
    Parameters:
      `ex` - The Throwable to print the full stack trace of

  Overview | Package | Class | Tree | Deprecated | Index | Help
  PREV CLASS NEXT CLASS | FRAMES NO FRAMES
  SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD