KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > defaults > DefaultPaths


1 /*
2  * @(#)file DefaultPaths.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 1.13
5  * @(#)lastedit 03/12/19
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  */

10
11 package com.sun.jmx.snmp.defaults;
12
13
14 // java import
15
//
16
import java.io.File JavaDoc;
17 import java.io.BufferedReader JavaDoc;
18 import java.io.InputStream JavaDoc;
19 import java.io.InputStreamReader JavaDoc;
20 import java.util.StringTokenizer JavaDoc;
21
22 /**
23  * This class represents a set of default directories used by Java DMK.
24  *
25  * <p><b>This API is a Sun Microsystems internal API and is subject
26  * to change without notice.</b></p>
27  * @since 1.5
28  */

29 public class DefaultPaths {
30     private static final String JavaDoc INSTALL_PATH_RESOURCE_NAME = "com/sun/jdmk/defaults/install.path";
31     // private constructor defined to "hide" the default public constructor
32
private DefaultPaths() {
33     
34     }
35     
36     // PUBLIC STATIC METHODS
37
//----------------------
38

39     /**
40      * Returns the installation directory for Java DMK.
41      *
42      * The default value of the installation directory is:
43      * <CODE>&lt;base_dir&gt; + File.separator + SUNWjdmk + File.separator + jdmk5.0 </CODE>
44      *
45      * @return Java DMK installation directory.
46      */

47     public static String JavaDoc getInstallDir() {
48         if (installDir == null)
49             return useRessourceFile();
50         else
51             return installDir;
52     }
53
54     /**
55      * Returns the installation directory for Java DMK concatenated with dirname.
56      *
57      * The default value of the installation directory is:
58      * <CODE>&lt;base_dir&gt; + File.separator + SUNWjdmk + File.separator + jdmk5.0 </CODE>
59      *
60      * @param dirname The directory to be appended.
61      *
62      * @return Java DMK installation directory + <CODE>File.separator</CODE> + <CODE>dirname</CODE>.
63      */

64     public static String JavaDoc getInstallDir(String JavaDoc dirname) {
65         if (installDir == null) {
66             if (dirname == null) {
67                 return getInstallDir();
68             } else {
69                 return getInstallDir() + File.separator + dirname;
70             }
71         } else {
72             if (dirname == null) {
73                 return installDir;
74             } else {
75                 return installDir + File.separator + dirname;
76             }
77         }
78     }
79
80     /**
81      * Sets the installation directory for Java DMK.
82      *
83      * @param dirname The directory where Java DMK resides.
84      */

85     public static void setInstallDir(String JavaDoc dirname) {
86         installDir = dirname;
87     }
88
89     /**
90      * Returns the <CODE>etc</CODE> directory for Java DMK.
91      * <P>
92      * The default value of the <CODE>etc</CODE> directory is:
93      * <UL>
94      * <LI><CODE>DefaultPaths.getInstallDir("etc")</CODE>.
95      * </UL>
96      *
97      * @return Java DMK <CODE>etc</CODE> directory.
98      */

99     public static String JavaDoc getEtcDir() {
100         if (etcDir == null)
101             return getInstallDir("etc");
102         else
103             return etcDir;
104     }
105
106     /**
107      * Returns the <CODE>etc</CODE> directory for Java DMK concatenated with dirname.
108      * <P>
109      * The default value of the <CODE>etc</CODE> directory is:
110      * <UL>
111      * <LI><CODE>DefaultPaths.getInstallDir("etc")</CODE>.
112      * </UL>
113      *
114      * @param dirname The directory to be appended.
115      *
116      * @return Java DMK <CODE>etc</CODE> directory + <CODE>File.separator</CODE> + <CODE>dirname</CODE>.
117      */

118     public static String JavaDoc getEtcDir(String JavaDoc dirname) {
119         if (etcDir == null) {
120             if (dirname == null) {
121                 return getEtcDir();
122             } else {
123                 return getEtcDir() + File.separator + dirname;
124             }
125         } else {
126             if (dirname == null) {
127                 return etcDir;
128             } else {
129                 return etcDir + File.separator + dirname;
130             }
131         }
132     }
133
134     /**
135      * Sets the <CODE>etc</CODE> directory for Java DMK.
136      *
137      * @param dirname The <CODE>etc</CODE> directory for Java DMK.
138      */

139     public static void setEtcDir(String JavaDoc dirname) {
140         etcDir = dirname;
141     }
142
143     /**
144      * Returns the <CODE>tmp</CODE> directory for the product.
145      * <P>
146      * The default value of the <CODE>tmp</CODE> directory is:
147      * <UL>
148      * <LI><CODE>DefaultPaths.getInstallDir("tmp")</CODE>.
149      * </UL>
150      *
151      * @return Java DMK <CODE>tmp</CODE> directory.
152      */

153     public static String JavaDoc getTmpDir() {
154      if (tmpDir == null)
155             return getInstallDir("tmp");
156         else
157             return tmpDir;
158     }
159
160     /**
161      * Returns the <CODE>tmp</CODE> directory for Java DMK concatenated with dirname.
162      * <P>
163      * The default value of the <CODE>tmp</CODE> directory is:
164      * <UL>
165      * <LI><CODE>DefaultPaths.getInstallDir("tmp")</CODE>.
166      * </UL>
167      *
168      * @param dirname The directory to be appended.
169      *
170      * @return Java DMK <CODE>tmp</CODE> directory + <CODE>File.separator</CODE> + <CODE>dirname</CODE>.
171      */

172     public static String JavaDoc getTmpDir(String JavaDoc dirname) {
173         if (tmpDir == null) {
174             if (dirname == null) {
175                 return getTmpDir();
176             } else {
177                 return getTmpDir() + File.separator + dirname;
178             }
179         } else {
180             if (dirname == null) {
181                 return tmpDir;
182             } else {
183                 return tmpDir + File.separator + dirname;
184             }
185         }
186     }
187
188     /**
189      * Sets the <CODE>tmp</CODE> directory for the product
190      *
191      * @param dirname The <CODE>tmp</CODE> directory for Java DMK.
192      */

193     public static void setTmpDir(String JavaDoc dirname) {
194         tmpDir = dirname;
195     }
196
197
198     // PRIVATE STATIC METHODS
199
//-----------------------
200

201     private static String JavaDoc useRessourceFile() {
202     InputStream JavaDoc in = null;
203     BufferedReader JavaDoc r = null;
204     try {
205         in =
206         DefaultPaths.class.getClassLoader().getResourceAsStream(INSTALL_PATH_RESOURCE_NAME);
207         if(in == null) return null;
208         r = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(in));
209         installDir = r.readLine();
210     }catch(Exception JavaDoc e) {
211     }
212     finally {
213         try {
214         if(in != null) in.close();
215         if(r != null) r.close();
216         }catch(Exception JavaDoc e) {}
217     }
218     return installDir;
219     }
220
221     // PRIVATE VARIABLES
222
//------------------
223

224     /**
225      * Directories used by Java DMK.
226      */

227     private static String JavaDoc etcDir;
228     private static String JavaDoc tmpDir;
229     private static String JavaDoc installDir;
230 }
231
Popular Tags