KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > diagnostics > Classpath


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Classpath.java
26  *
27  * Created on September 28, 2001, 11:34 PM
28  */

29
30 package com.sun.enterprise.util.diagnostics;
31 import com.sun.enterprise.util.diagnostics.Reporter;
32 import java.util.*;
33
34 /**
35  *
36  * @author bnevins
37  * @version
38  */

39
40 public class Classpath
41 {
42     public static List getClasspathAsList()
43     {
44         String JavaDoc cp = getClasspathAsString();
45         String JavaDoc ps = System.getProperty("path.separator");
46         StringTokenizer st = new StringTokenizer(cp, ps);
47         List list = new ArrayList();
48         
49         while (st.hasMoreTokens())
50         {
51             list.add(st.nextToken());
52         }
53         
54         return list;
55     }
56     
57     public static List getClasspathAsBatchCommands()
58     {
59         List from = getClasspathAsList();
60         List to = new ArrayList();
61         
62         boolean first = true;
63         
64         for(Iterator iter = from.iterator(); iter.hasNext(); )
65         {
66             if(first)
67             {
68                 to.add("set CLASSPATH=" + iter.next());
69                 first = false;
70             }
71             else
72                 to.add("set CLASSPATH=%CLASSPATH%;" + iter.next());
73         }
74         
75         return to;
76     }
77
78     public static String JavaDoc getClasspathAsString()
79     {
80         return System.getProperty("java.class.path");
81     }
82
83     public static List getClasspathAsSortedList()
84     {
85         List list = getClasspathAsList();
86         Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
87         return list;
88     }
89         
90     
91     public static void main(String JavaDoc[] args)
92     {
93         pr("****** CLASSPATH as String *******");
94         pr(getClasspathAsString());
95         pr("****** CLASSPATH as List *******");
96         pr(getClasspathAsList());
97         pr("****** CLASSPATH as Sorted List *******");
98         pr(getClasspathAsSortedList());
99         pr("****** CLASSPATH as Batch Commands *******");
100         pr(getClasspathAsBatchCommands());
101     }
102     
103     private static void pr(String JavaDoc s)
104     {
105         System.out.println(s);
106     }
107     
108     private static void pr(List c)
109     {
110         for(Iterator iter = c.iterator(); iter.hasNext(); )
111         {
112             pr((String JavaDoc)iter.next());
113         }
114     }
115     
116 }
117
Popular Tags