org.apache.env
Class Which

java.lang.Object
  |
  +--org.apache.env.Which

public class Which
extends java.lang.Object

General environment checking and version finding service; main external entrypoints and command line interface.

Which is the command line interface to the org.apache.env package. Simply put, it provides a simplistic check of a user's actual environment for debugging and product support purposes by detecting the specific versions of commonly installed classes in the environment.

Which and related service classes provide a framework for looking for version information and passing it around in hashtables. Users can plug in their own implementations of WhichProject classes to get custom version info about any product.

One important usage note: you must call Which (or subclasses) in the environment that you wish to check. I.e. if you have a problem with a command line tool, then call Which from the same command line environment. If you have a problem with a servlet, you must call Which.blah() from your servlet as it's installed in an actual container.

Usage - command line:
java org.apache.env.Which [project;WhichProject] [-options]

Usage - from program:
int status = org.apache.env.Which.which(hash, projects, options);

Usage - from XSLT stylesheet in Xalan-J:
(add which.jar to your classpath and run the following stylesheet)

 <?xml version="1.0"?>
 <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:xalan="http://xml.apache.org/xalan"
     exclude-result-prefixes="xalan">
     <xsl:output indent="yes"/>
     <xsl:template match="/">
       <xsl:copy-of select="xalan:checkEnvironment()"/>
     </xsl:template>
 </xsl:stylesheet>
 

Original credit to org.apache.xalan.xslt.EnvironmentCheck

Version:
$Id: Which.html,v 1.4 2003/12/30 03:55:19 crossley Exp $
Author:
shane_curcuru@us.ibm.com

Field Summary
static java.lang.String DEFAULT_PROJECTS
          Default set of projects to use if none provided.
protected  java.lang.StringBuffer optionsBuf
          optionsBuf.
protected  java.io.PrintWriter outWriter
          outWriter.
protected  java.lang.StringBuffer projectsBuf
          projectsBuf.
static java.lang.String SEPARATOR
          Generic ';' separator for various items.
 
Constructor Summary
Which()
           
 
Method Summary
 void doMain(java.lang.String[] args)
          Instance worker method to handle main().
static void getGeneralInfo(java.util.Hashtable hash, java.lang.String options)
          Grab a couple of generally useful items, like classpath, java version, version of this file, etc..
static int getProjectsInfo(java.util.Hashtable hash, java.lang.String projects, java.lang.String options)
          Get information from various project's WhichProject impls.
static java.lang.String getVersion()
          Get simple version info about org.apache.env.Which and related classes.
static void main(java.lang.String[] args)
          Command line runnability.
protected  boolean parseArgs(java.lang.String[] args)
          Parse commandline args, return false if help asked for.
protected  void reportHashtable(java.util.Hashtable hash, java.lang.String name, java.io.PrintWriter out)
          Print information from a hashtable into the PrintWriter.
 void reportProjectsInfo(java.util.Hashtable hash, java.lang.String options, int status, java.io.PrintWriter out)
          Print information from which() into the PrintWriter.
protected  java.lang.String usage()
          Return our usage statement.
static int which(java.util.Hashtable hash, java.lang.String projects, java.lang.String options)
          Which - get all info.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
Generic ';' separator for various items.

See Also:
Constant Field Values

DEFAULT_PROJECTS

public static final java.lang.String DEFAULT_PROJECTS
Default set of projects to use if none provided.

See Also:
Constant Field Values

optionsBuf

protected java.lang.StringBuffer optionsBuf
optionsBuf.


projectsBuf

protected java.lang.StringBuffer projectsBuf
projectsBuf.


outWriter

protected java.io.PrintWriter outWriter
outWriter.

Constructor Detail

Which

public Which()
Method Detail

main

public static void main(java.lang.String[] args)
Command line runnability.

Parameters:
args - command line args

doMain

public void doMain(java.lang.String[] args)
Instance worker method to handle main().

Parameters:
args - command line args

which

public static int which(java.util.Hashtable hash,
                        java.lang.String projects,
                        java.lang.String options)
Which - get all info. Worker method called from doMain or suitable for calling from other programs.

Parameters:
hash - to put information in
projects - to get information about
options - to apply like strict or verbose
Returns:
status information from WhichConstant

getGeneralInfo

public static void getGeneralInfo(java.util.Hashtable hash,
                                  java.lang.String options)
Grab a couple of generally useful items, like classpath, java version, version of this file, etc..

Parameters:
hash - to put information in

getProjectsInfo

public static int getProjectsInfo(java.util.Hashtable hash,
                                  java.lang.String projects,
                                  java.lang.String options)
Get information from various project's WhichProject impls.

Each project's info is put into a subhash. Note: if projects is null, we use DEFAULT_PROJECTS.

Parameters:
hash - to put information in
projects - to get information about
options - to apply like strict or verbose
Returns:
status information from WhichConstant

reportProjectsInfo

public void reportProjectsInfo(java.util.Hashtable hash,
                               java.lang.String options,
                               int status,
                               java.io.PrintWriter out)
Print information from which() into the PrintWriter.

Simplistic implementation to report to a writer.

Parameters:
hash - to get info from (may have subhashtables)
options - to apply like strict or verbose
status - from finding version info
out - PrintWriter to send Properties.list()-like output to

reportHashtable

protected void reportHashtable(java.util.Hashtable hash,
                               java.lang.String name,
                               java.io.PrintWriter out)
Print information from a hashtable into the PrintWriter.

Provides a pre-order traversal where the parent hash has it's output dumped before recursing to any child sub hashes. Sorta looks like Properties.list() output.

Parameters:
hash - to get info from (may have subhashtables)
name - to print as header for this hash
out - PrintWriter to send Properties.list()-like output to

usage

protected java.lang.String usage()
Return our usage statement.

Returns:
String of our usage

parseArgs

protected boolean parseArgs(java.lang.String[] args)
Parse commandline args, return false if help asked for.

Parameters:
args - array of commandline args
Returns:
true if OK, false if error/usage/help needed

getVersion

public static java.lang.String getVersion()
Get simple version info about org.apache.env.Which and related classes.

Returns:
String of our file version


Copyright © 2001 Apache Software Foundation. All Rights Reserved.