KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SystemProps.java
26  *
27  * Created on October 2, 2001, 2:53 PM
28  */

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

40 public class SystemProps
41 {
42     public static List get()
43     {
44         Properties p = System.getProperties();
45         // these 2 lines woul;d be nice -- but it's case-sensitive...
46
//Map sortedMap = new TreeMap(p);
47
//Set sortedSet = sortedMap.entrySet();
48
Set set = p.entrySet();
49         List list = new ArrayList(set);
50         Collections.sort(list, new Comparator()
51         {
52             public int compare(Object JavaDoc o1, Object JavaDoc o2)
53             {
54                 Map.Entry me1 = (Map.Entry)o1;
55                 Map.Entry me2 = (Map.Entry)o2;
56                 
57                 return ((String JavaDoc)me1.getKey()).compareToIgnoreCase((String JavaDoc)me2.getKey());
58             }
59         });
60         return list;
61     }
62     
63     ///////////////////////////////////////////////////////////////////////////
64

65     public static String JavaDoc toStringStatic()
66     {
67         int longestKey = 0;
68         List list = get();
69         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
70
71         for(Iterator it = list.iterator(); it.hasNext(); )
72         {
73             Map.Entry entry = (Map.Entry)it.next();
74             int len = ((String JavaDoc)entry.getKey()).length();
75
76             if(len > longestKey)
77                 longestKey = len;
78         }
79
80         longestKey += 1;
81
82         for(Iterator it = list.iterator(); it.hasNext(); )
83         {
84             Map.Entry entry = (Map.Entry)it.next();
85             sb.append(StringUtils.padRight((String JavaDoc)entry.getKey(), longestKey));
86             sb.append("= ");
87             sb.append((String JavaDoc)entry.getValue());
88             sb.append("\n");
89         }
90         
91         return sb.toString();
92     }
93     
94     ///////////////////////////////////////////////////////////////////////////
95

96     private SystemProps()
97     {
98     }
99     
100     ///////////////////////////////////////////////////////////////////////////
101

102     public static void main(String JavaDoc[] args)
103     {
104         System.out.println(toStringStatic());
105     }
106 }
107
Popular Tags