0N/A/*
2362N/A * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.jmx.snmp.defaults;
0N/A
0N/A
0N/A// java import
0N/A//
0N/Aimport java.io.File;
0N/Aimport java.io.BufferedReader;
0N/Aimport java.io.InputStream;
0N/Aimport java.io.InputStreamReader;
0N/Aimport java.util.StringTokenizer;
0N/A
0N/A/**
0N/A * This class represents a set of default directories used by Java DMK.
0N/A *
0N/A * <p><b>This API is a Sun Microsystems internal API and is subject
0N/A * to change without notice.</b></p>
0N/A * @since 1.5
0N/A */
0N/Apublic class DefaultPaths {
0N/A private static final String INSTALL_PATH_RESOURCE_NAME = "com/sun/jdmk/defaults/install.path";
0N/A // private constructor defined to "hide" the default public constructor
0N/A private DefaultPaths() {
0N/A
0N/A }
0N/A
0N/A // PUBLIC STATIC METHODS
0N/A //----------------------
0N/A
0N/A /**
0N/A * Returns the installation directory for Java DMK.
0N/A *
0N/A * The default value of the installation directory is:
0N/A * <CODE>&lt;base_dir&gt; + File.separator + SUNWjdmk + File.separator + jdmk5.0 </CODE>
0N/A *
0N/A * @return Java DMK installation directory.
0N/A */
0N/A public static String getInstallDir() {
0N/A if (installDir == null)
0N/A return useRessourceFile();
0N/A else
0N/A return installDir;
0N/A }
0N/A
0N/A /**
0N/A * Returns the installation directory for Java DMK concatenated with dirname.
0N/A *
0N/A * The default value of the installation directory is:
0N/A * <CODE>&lt;base_dir&gt; + File.separator + SUNWjdmk + File.separator + jdmk5.0 </CODE>
0N/A *
0N/A * @param dirname The directory to be appended.
0N/A *
0N/A * @return Java DMK installation directory + <CODE>File.separator</CODE> + <CODE>dirname</CODE>.
0N/A */
0N/A public static String getInstallDir(String dirname) {
0N/A if (installDir == null) {
0N/A if (dirname == null) {
0N/A return getInstallDir();
0N/A } else {
0N/A return getInstallDir() + File.separator + dirname;
0N/A }
0N/A } else {
0N/A if (dirname == null) {
0N/A return installDir;
0N/A } else {
0N/A return installDir + File.separator + dirname;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the installation directory for Java DMK.
0N/A *
0N/A * @param dirname The directory where Java DMK resides.
0N/A */
0N/A public static void setInstallDir(String dirname) {
0N/A installDir = dirname;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <CODE>etc</CODE> directory for Java DMK.
0N/A * <P>
0N/A * The default value of the <CODE>etc</CODE> directory is:
0N/A * <UL>
0N/A * <LI><CODE>DefaultPaths.getInstallDir("etc")</CODE>.
0N/A * </UL>
0N/A *
0N/A * @return Java DMK <CODE>etc</CODE> directory.
0N/A */
0N/A public static String getEtcDir() {
0N/A if (etcDir == null)
0N/A return getInstallDir("etc");
0N/A else
0N/A return etcDir;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <CODE>etc</CODE> directory for Java DMK concatenated with dirname.
0N/A * <P>
0N/A * The default value of the <CODE>etc</CODE> directory is:
0N/A * <UL>
0N/A * <LI><CODE>DefaultPaths.getInstallDir("etc")</CODE>.
0N/A * </UL>
0N/A *
0N/A * @param dirname The directory to be appended.
0N/A *
0N/A * @return Java DMK <CODE>etc</CODE> directory + <CODE>File.separator</CODE> + <CODE>dirname</CODE>.
0N/A */
0N/A public static String getEtcDir(String dirname) {
0N/A if (etcDir == null) {
0N/A if (dirname == null) {
0N/A return getEtcDir();
0N/A } else {
0N/A return getEtcDir() + File.separator + dirname;
0N/A }
0N/A } else {
0N/A if (dirname == null) {
0N/A return etcDir;
0N/A } else {
0N/A return etcDir + File.separator + dirname;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the <CODE>etc</CODE> directory for Java DMK.
0N/A *
0N/A * @param dirname The <CODE>etc</CODE> directory for Java DMK.
0N/A */
0N/A public static void setEtcDir(String dirname) {
0N/A etcDir = dirname;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <CODE>tmp</CODE> directory for the product.
0N/A * <P>
0N/A * The default value of the <CODE>tmp</CODE> directory is:
0N/A * <UL>
0N/A * <LI><CODE>DefaultPaths.getInstallDir("tmp")</CODE>.
0N/A * </UL>
0N/A *
0N/A * @return Java DMK <CODE>tmp</CODE> directory.
0N/A */
0N/A public static String getTmpDir() {
0N/A if (tmpDir == null)
0N/A return getInstallDir("tmp");
0N/A else
0N/A return tmpDir;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <CODE>tmp</CODE> directory for Java DMK concatenated with dirname.
0N/A * <P>
0N/A * The default value of the <CODE>tmp</CODE> directory is:
0N/A * <UL>
0N/A * <LI><CODE>DefaultPaths.getInstallDir("tmp")</CODE>.
0N/A * </UL>
0N/A *
0N/A * @param dirname The directory to be appended.
0N/A *
0N/A * @return Java DMK <CODE>tmp</CODE> directory + <CODE>File.separator</CODE> + <CODE>dirname</CODE>.
0N/A */
0N/A public static String getTmpDir(String dirname) {
0N/A if (tmpDir == null) {
0N/A if (dirname == null) {
0N/A return getTmpDir();
0N/A } else {
0N/A return getTmpDir() + File.separator + dirname;
0N/A }
0N/A } else {
0N/A if (dirname == null) {
0N/A return tmpDir;
0N/A } else {
0N/A return tmpDir + File.separator + dirname;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the <CODE>tmp</CODE> directory for the product
0N/A *
0N/A * @param dirname The <CODE>tmp</CODE> directory for Java DMK.
0N/A */
0N/A public static void setTmpDir(String dirname) {
0N/A tmpDir = dirname;
0N/A }
0N/A
0N/A
0N/A // PRIVATE STATIC METHODS
0N/A //-----------------------
0N/A
0N/A private static String useRessourceFile() {
0N/A InputStream in = null;
0N/A BufferedReader r = null;
0N/A try {
0N/A in =
0N/A DefaultPaths.class.getClassLoader().getResourceAsStream(INSTALL_PATH_RESOURCE_NAME);
0N/A if(in == null) return null;
0N/A r = new BufferedReader(new InputStreamReader(in));
0N/A installDir = r.readLine();
0N/A }catch(Exception e) {
0N/A }
0N/A finally {
0N/A try {
0N/A if(in != null) in.close();
0N/A if(r != null) r.close();
0N/A }catch(Exception e) {}
0N/A }
0N/A return installDir;
0N/A }
0N/A
0N/A // PRIVATE VARIABLES
0N/A //------------------
0N/A
0N/A /**
0N/A * Directories used by Java DMK.
0N/A */
0N/A private static String etcDir;
0N/A private static String tmpDir;
0N/A private static String installDir;
0N/A}