com.izforge.izpack.util
Class TargetFactory

java.lang.Object
  extended bycom.izforge.izpack.util.TargetFactory

public class TargetFactory
extends java.lang.Object

The TargetFactory serves as a central mechanism to instantiate OS specific class flavors, provide OS specific file extension types, default install directories and similar functionality. In addition it provides services that are related to OS versions and flavors. For a tutorial on using some of the features in this class see the TargetFactory Tutorial.

Version:
0.0.1 / 1/3/2002
Author:
Elmar Grom

Field Summary
private  int architecture
          identifies the hardware architecture we are running on
(package private) static java.lang.String[] CLASS_ARCHITECTURE_PREFIX
          The list of processor architecture specific prefixes.
(package private) static java.lang.String[] CLASS_FLAVOR_PREFIX
          The os favor specific class prefixes for classes the implement different versions for various os favors.
(package private) static java.lang.String[] CLASS_PREFIX
          The os specific class prefixes for classes that implement different versions for the various operating systems.
static int GENERIC
          Used to report a non specific operating system.
(package private) static java.lang.String[] INSTALL_PATH_FRAGMENT
          The list of default install path fragments.
(package private) static java.lang.String[][] INSTALL_PATH_RESOURCE_KEY
          This is a list of keys to use when looking for resources that define the default install path to use.
(package private) static java.lang.String[] LIBRARY_EXTENSION
          The extensions used for native libraries on various operating systems.
private static TargetFactory me
          The reference to the single instance of TargetFactory.
static int NT
          Used to identify the Windows-NT class of operating systems in terms of an OS flavor.
private  int os
          identifies the operating system we are running on
private  int osFlavor
          identifies the operating system favor
static int OTHER
          Nonspecific processor architecture, other than X86.
static int STANDARD
          This is the basic flavor for every operating system.
static int UNIX
          Identifies generic UNIX operating systems
private  java.lang.String version
          represents the version number of the target system
private static java.lang.String VERSION_DELIMITER
          The delimiter characters used to tokenize version numbers
static int WINDOWS
          Identifies Microsoft Windows.
static int X
          Used to identify the OS X flavor of the Mac OS
static int X86
          Identifies Intel X86 based processor types.
 
Constructor Summary
private TargetFactory()
          Constructor
 
Method Summary
 int getArchitecture()
          Returns an index number that identified the processor architecture of the target system.
static java.lang.String getCurrentOSPrefix()
          Gets a prefix alias for the current platform.
 java.lang.String getDefaultInstallPath(java.lang.String appName)
          Returns the system dependent default install path.
static TargetFactory getInstance()
          Returns an instance of TargetFactory to use.
 java.lang.String getNativeLibraryExtension()
          Returns the file extension customarily used on the target OS for dynamically loadable libraries.
 int getOS()
          Returns the index number for the target operating system that was detected.
 int getOSFlavor()
          Returns the index number for the operating system flavor that was detected on the target system.
 java.lang.Object makeObject(java.lang.String name)
          This method returns an OS and OS flavor specific instance of the requested class.
 boolean versionIsHigher(java.lang.String version)
          Returns true if the version in the parameter string is higher than the version of the target os.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WINDOWS

public static final int WINDOWS
Identifies Microsoft Windows.

See Also:
Constant Field Values

UNIX

public static final int UNIX
Identifies generic UNIX operating systems

See Also:
Constant Field Values

GENERIC

public static final int GENERIC
Used to report a non specific operating system.

See Also:
Constant Field Values

STANDARD

public static final int STANDARD
This is the basic flavor for every operating system.

See Also:
Constant Field Values

NT

public static final int NT
Used to identify the Windows-NT class of operating systems in terms of an OS flavor. It is reported for Windows-NT, 2000 and XP.

See Also:
Constant Field Values

X

public static final int X
Used to identify the OS X flavor of the Mac OS

See Also:
Constant Field Values

X86

public static final int X86
Identifies Intel X86 based processor types.

See Also:
Constant Field Values

OTHER

public static final int OTHER
Nonspecific processor architecture, other than X86.

See Also:
Constant Field Values

LIBRARY_EXTENSION

static final java.lang.String[] LIBRARY_EXTENSION
The extensions used for native libraries on various operating systems. The string positions correspond to the basic operating system indexes. The following values are legal to use :


CLASS_PREFIX

static final java.lang.String[] CLASS_PREFIX
The os specific class prefixes for classes that implement different versions for the various operating systems. The string positions correspond to the basic operating system indexes. The following values are legal to use :


CLASS_FLAVOR_PREFIX

static final java.lang.String[] CLASS_FLAVOR_PREFIX
The os favor specific class prefixes for classes the implement different versions for various os favors. The string positions correspond to the flavor indexes. The following values are legal to use :


CLASS_ARCHITECTURE_PREFIX

static final java.lang.String[] CLASS_ARCHITECTURE_PREFIX
The list of processor architecture specific prefixes. The string positions correspond to the architecture indexes. The following values are leegal to use :


INSTALL_PATH_FRAGMENT

static final java.lang.String[] INSTALL_PATH_FRAGMENT
The list of default install path fragments. Depending on the operating system, a path fragment might represent either a part of the default install path or the entire path to use. For MS-Windows it is always only a part of the full install path. The string positions correspond to the basic operating system indexes. The following values are leegal to use :


INSTALL_PATH_RESOURCE_KEY

static final java.lang.String[][] INSTALL_PATH_RESOURCE_KEY
This is a list of keys to use when looking for resources that define the default install path to use. The list is organized as two dimensional array of Strings. To access the array, denote the first dimension with the operating system index and the second dimension with the flavor index. For example to access the key for Windows-NT use INSTALL_PATH_RESOURCE_KEY[WINDOWS][NT] The array uses a sparse population, that is, not all array locations actually contain a key. Only locations for which a real operating system/flavor combination exists are populated. For example, there is no such thing as INSTALL_PATH_RESOURCE_KEY[UNIX][X]


VERSION_DELIMITER

private static final java.lang.String VERSION_DELIMITER
The delimiter characters used to tokenize version numbers

See Also:
Constant Field Values

me

private static TargetFactory me
The reference to the single instance of TargetFactory. Used in static methods in place of this.


os

private int os
identifies the operating system we are running on


osFlavor

private int osFlavor
identifies the operating system favor


architecture

private int architecture
identifies the hardware architecture we are running on


version

private java.lang.String version
represents the version number of the target system

Constructor Detail

TargetFactory

private TargetFactory()
Constructor

Method Detail

getInstance

public static TargetFactory getInstance()
Returns an instance of TargetFactory to use.

Returns:
an instance of TargetFactory.

makeObject

public java.lang.Object makeObject(java.lang.String name)
                            throws java.lang.Exception
This method returns an OS and OS flavor specific instance of the requested class.

Class Naming Rules
Class versions must be named with the OS and OS flavor as prefix. The prefixes are simply concatenated, with the OS prefix first and the flavor prefix second. Use the following OS specific prefixes:

Operating System Prefix
Microsoft Windows Win_
Mac OS Mac_
UNIX UNIX_

For the different OS flavors, use these prefixes:

OS Flavor Prefix
NT NT_
Mac OS X X_


Naming Example:

For the class MyClass, the specific version for Windows NT must be in the same package as MyClass and the name must be Win_NT_MyClass. A version that should be instantiated for any non-NT flavor would be called Win_MyClass. This would also be the version instantiated on Windows NT if the version Win_NT_MyClass does not exist.

The Loading Process

The process is completed after the first successful attempt to load a class.
  1. load a version that is OS and OS-Flavor specific
  2. load a version that is OS specific
  3. load the base version (without OS or OS-Flavor prefix)

See the TargetFactory Tutorial for more information.

Parameters:
name - the fully qualified name of the class to load without the extension.
Returns:
An instance of the requested class. Note that specific initialization that can not be accomplished in the default constructor still needs to be performed before the object can be used.
Throws:
java.lang.Exception - if all attempts to instantiate class fail

versionIsHigher

public boolean versionIsHigher(java.lang.String version)
                        throws java.lang.Exception
Returns true if the version in the parameter string is higher than the version of the target os.

Parameters:
version - the version number to compare to
Returns:
false if the version of the target system is higher, otherwise true
Throws:
java.lang.Exception

getOS

public int getOS()
Returns the index number for the target operating system that was detected.

Returns:
an index number for the OS
See Also:
WINDOWS, UNIX, GENERIC

getOSFlavor

public int getOSFlavor()
Returns the index number for the operating system flavor that was detected on the target system.

Returns:
an index for the OS flavor
See Also:
STANDARD, NT, X

getArchitecture

public int getArchitecture()
Returns an index number that identified the processor architecture of the target system.

Returns:
an index for the processor architecture
See Also:
X86, OTHER

getNativeLibraryExtension

public java.lang.String getNativeLibraryExtension()
Returns the file extension customarily used on the target OS for dynamically loadable libraries.

Returns:
a String containing the customary library extension for the target OS. Note that the string might be empty if there no such specific extension for the target OS.

getDefaultInstallPath

public java.lang.String getDefaultInstallPath(java.lang.String appName)
Returns the system dependent default install path. This is typically used to suggest an istall path to the end user, when performing an installation. The default install path is assembled form the OS specific path fragment specified in INSTALL_PATH_FRAGMENT, possibly a drive letter and the application name. The user the option to define resources that define default paths which differ from the path fragments defined here. The following resource names will be recognized by this method:

Parameters:
appName - the name of the application to install. If no specific resource has been set, then this name will be appended to the OS specific default path fragment.
Returns:
the default install path for the target system

getCurrentOSPrefix

public static java.lang.String getCurrentOSPrefix()
Gets a prefix alias for the current platform. "Win_" on Windows Systems "Win_NT_" on WinNT4, 2000, XP Mac on Mac Mac_X on macosx and Unix_

Returns:
a prefix alias for the current platform