KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > DebugUtils


1 /*
2  * $Id: DebugUtils.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.util;
12
13 import java.security.Provider JavaDoc;
14 import java.security.Security JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Set JavaDoc;
18
19 /**
20  * Useful for enumerating debug information about the current Java environment
21  */

22 // @ThreadSafe
23
public class DebugUtils
24 {
25
26     /**
27      * @return all available services types
28      */

29     public static String JavaDoc[] listSecurityServiceTypes()
30     {
31         Set JavaDoc result = new HashSet JavaDoc();
32
33         // All all providers
34
Provider JavaDoc[] providers = Security.getProviders();
35         for (int i = 0; i < providers.length; i++)
36         {
37             // Get services provided by each provider
38
Set JavaDoc keys = providers[i].keySet();
39             for (Iterator JavaDoc it = keys.iterator(); it.hasNext();)
40             {
41                 String JavaDoc key = (String JavaDoc)it.next();
42                 key = key.split(" ")[0];
43
44                 if (key.startsWith("Alg.Alias."))
45                 {
46                     // Strip the alias
47
key = key.substring(10);
48                 }
49                 int ix = key.indexOf('.');
50                 result.add(key.substring(0, ix));
51             }
52         }
53         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
54     }
55
56     /**
57      * @return the available implementations for a service type
58      */

59     public static String JavaDoc[] listCryptoImplementations(String JavaDoc serviceType)
60     {
61         Set JavaDoc result = new HashSet JavaDoc();
62
63         // All all providers
64
Provider JavaDoc[] providers = Security.getProviders();
65         for (int i = 0; i < providers.length; i++)
66         {
67             // Get services provided by each provider
68
Set JavaDoc keys = providers[i].keySet();
69             for (Iterator JavaDoc it = keys.iterator(); it.hasNext();)
70             {
71                 String JavaDoc key = (String JavaDoc)it.next();
72                 key = key.split(" ")[0];
73
74                 if (key.startsWith(serviceType + "."))
75                 {
76                     result.add(key.substring(serviceType.length() + 1));
77                 }
78                 else if (key.startsWith("Alg.Alias." + serviceType + "."))
79                 {
80                     // This is an alias
81
result.add(key.substring(serviceType.length() + 11));
82                 }
83             }
84         }
85         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
86     }
87 }
88
Popular Tags