Coverage Report - org.mule.util.DebugUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DebugUtils
0%
0/26
0%
0/7
3.333
 
 1  
 /*
 2  
  * $Id: DebugUtils.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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 CPAL v1.0
 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;
 14  
 import java.security.Security;
 15  
 import java.util.HashSet;
 16  
 import java.util.Iterator;
 17  
 import java.util.Set;
 18  
 
 19  
 /**
 20  
  * Useful for enumerating debug information about the current Java environment
 21  
  */
 22  
 // @ThreadSafe
 23  
 public final class DebugUtils
 24  
 {
 25  
 
 26  
     /** Do not instanciate. */
 27  
     private DebugUtils ()
 28  0
     {
 29  
         // no-op
 30  0
     }
 31  
 
 32  
     /**
 33  
      * @return all available services types
 34  
      */
 35  
     public static String[] listSecurityServiceTypes()
 36  
     {
 37  0
         Set result = new HashSet();
 38  
 
 39  
         // All all providers
 40  0
         Provider[] providers = Security.getProviders();
 41  0
         for (int i = 0; i < providers.length; i++)
 42  
         {
 43  
             // Get services provided by each provider
 44  0
             Set keys = providers[i].keySet();
 45  0
             for (Iterator it = keys.iterator(); it.hasNext();)
 46  
             {
 47  0
                 String key = (String) it.next();
 48  0
                 key = key.split(" ")[0];
 49  
 
 50  0
                 if (key.startsWith("Alg.Alias."))
 51  
                 {
 52  
                     // Strip the alias
 53  0
                     key = key.substring(10);
 54  
                 }
 55  0
                 int ix = key.indexOf('.');
 56  0
                 result.add(key.substring(0, ix));
 57  
             }
 58  
         }
 59  0
         return (String[]) result.toArray(new String[result.size()]);
 60  
     }
 61  
 
 62  
     /**
 63  
      * @return the available implementations for a service type
 64  
      */
 65  
     public static String[] listCryptoImplementations(String serviceType)
 66  
     {
 67  0
         Set result = new HashSet();
 68  
 
 69  
         // All all providers
 70  0
         Provider[] providers = Security.getProviders();
 71  0
         for (int i = 0; i < providers.length; i++)
 72  
         {
 73  
             // Get services provided by each provider
 74  0
             Set keys = providers[i].keySet();
 75  0
             for (Iterator it = keys.iterator(); it.hasNext();)
 76  
             {
 77  0
                 String key = (String) it.next();
 78  0
                 key = key.split(" ")[0];
 79  
 
 80  0
                 if (key.startsWith(serviceType + "."))
 81  
                 {
 82  0
                     result.add(key.substring(serviceType.length() + 1));
 83  
                 }
 84  0
                 else if (key.startsWith("Alg.Alias." + serviceType + "."))
 85  
                 {
 86  
                     // This is an alias
 87  0
                     result.add(key.substring(serviceType.length() + 11));
 88  
                 }
 89  
             }
 90  
         }
 91  0
         return (String[]) result.toArray(new String[result.size()]);
 92  
     }
 93  
 }