/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.jmx.snmp.defaults; // java import // import java.io.File; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * This class represents a set of default directories used by Java DMK. * *
This API is a Sun Microsystems internal API and is subject * to change without notice.
* @since 1.5 */ public class DefaultPaths { private static final String INSTALL_PATH_RESOURCE_NAME = "com/sun/jdmk/defaults/install.path"; // private constructor defined to "hide" the default public constructor private DefaultPaths() { } // PUBLIC STATIC METHODS //---------------------- /** * Returns the installation directory for Java DMK. * * The default value of the installation directory is: *<base_dir> + File.separator + SUNWjdmk + File.separator + jdmk5.0
*
* @return Java DMK installation directory.
*/
public static String getInstallDir() {
if (installDir == null)
return useRessourceFile();
else
return installDir;
}
/**
* Returns the installation directory for Java DMK concatenated with dirname.
*
* The default value of the installation directory is:
* <base_dir> + File.separator + SUNWjdmk + File.separator + jdmk5.0
*
* @param dirname The directory to be appended.
*
* @return Java DMK installation directory + File.separator
+ dirname
.
*/
public static String getInstallDir(String dirname) {
if (installDir == null) {
if (dirname == null) {
return getInstallDir();
} else {
return getInstallDir() + File.separator + dirname;
}
} else {
if (dirname == null) {
return installDir;
} else {
return installDir + File.separator + dirname;
}
}
}
/**
* Sets the installation directory for Java DMK.
*
* @param dirname The directory where Java DMK resides.
*/
public static void setInstallDir(String dirname) {
installDir = dirname;
}
/**
* Returns the etc
directory for Java DMK.
*
* The default value of the etc
directory is:
*
DefaultPaths.getInstallDir("etc")
.
* etc
directory.
*/
public static String getEtcDir() {
if (etcDir == null)
return getInstallDir("etc");
else
return etcDir;
}
/**
* Returns the etc
directory for Java DMK concatenated with dirname.
*
* The default value of the etc
directory is:
*
DefaultPaths.getInstallDir("etc")
.
* etc
directory + File.separator
+ dirname
.
*/
public static String getEtcDir(String dirname) {
if (etcDir == null) {
if (dirname == null) {
return getEtcDir();
} else {
return getEtcDir() + File.separator + dirname;
}
} else {
if (dirname == null) {
return etcDir;
} else {
return etcDir + File.separator + dirname;
}
}
}
/**
* Sets the etc
directory for Java DMK.
*
* @param dirname The etc
directory for Java DMK.
*/
public static void setEtcDir(String dirname) {
etcDir = dirname;
}
/**
* Returns the tmp
directory for the product.
*
* The default value of the tmp
directory is:
*
DefaultPaths.getInstallDir("tmp")
.
* tmp
directory.
*/
public static String getTmpDir() {
if (tmpDir == null)
return getInstallDir("tmp");
else
return tmpDir;
}
/**
* Returns the tmp
directory for Java DMK concatenated with dirname.
*
* The default value of the tmp
directory is:
*
DefaultPaths.getInstallDir("tmp")
.
* tmp
directory + File.separator
+ dirname
.
*/
public static String getTmpDir(String dirname) {
if (tmpDir == null) {
if (dirname == null) {
return getTmpDir();
} else {
return getTmpDir() + File.separator + dirname;
}
} else {
if (dirname == null) {
return tmpDir;
} else {
return tmpDir + File.separator + dirname;
}
}
}
/**
* Sets the tmp
directory for the product
*
* @param dirname The tmp
directory for Java DMK.
*/
public static void setTmpDir(String dirname) {
tmpDir = dirname;
}
// PRIVATE STATIC METHODS
//-----------------------
private static String useRessourceFile() {
InputStream in = null;
BufferedReader r = null;
try {
in =
DefaultPaths.class.getClassLoader().getResourceAsStream(INSTALL_PATH_RESOURCE_NAME);
if(in == null) return null;
r = new BufferedReader(new InputStreamReader(in));
installDir = r.readLine();
}catch(Exception e) {
}
finally {
try {
if(in != null) in.close();
if(r != null) r.close();
}catch(Exception e) {}
}
return installDir;
}
// PRIVATE VARIABLES
//------------------
/**
* Directories used by Java DMK.
*/
private static String etcDir;
private static String tmpDir;
private static String installDir;
}