FileDocCategorySizeDatePackage
Services.javaAPI DocAndroid 1.5 API7312Wed May 06 22:41:06 BST 2009org.apache.harmony.security.fortress

Services

public class Services extends Object
This class contains information about all registered providers and preferred implementations for all "serviceName.algName".

Fields Summary
private static final Map
services
private static boolean
needRefresh
public static int
refreshNumber
Refresh number
private static final List
providers
private static final Map
providersNames
Constructors Summary
Methods Summary
public static java.security.ProvidergetProvider(java.lang.String name)
Returns the provider with the specified name

param
name
return

        if (name == null) {
            return null;
        }
        return providersNames.get(name);
    
public static java.security.Provider[]getProviders()
Returns registered providers

return

        return providers.toArray(new Provider[providers.size()]);
    
public static java.util.ListgetProvidersList()
Returns registered providers as List

return

        return new ArrayList<Provider>(providers);
    
public static java.security.Provider$ServicegetService(java.lang.String key)
Returns service description. Call refresh() before.

param
key
return

        return services.get(key);
    
public static voidinitServiceInfo(java.security.Provider p)
Adds information about provider services into HashMap.

param
p

        Provider.Service serv;
        String key;
        String type;
        String alias;
        StringBuffer sb = new StringBuffer(128);

        for (Iterator<Provider.Service> it1 = p.getServices().iterator(); it1.hasNext();) {
            serv = it1.next();
            type = serv.getType();
            sb.delete(0, sb.length());
            key = sb.append(type).append(".").append( //$NON-NLS-1$
                    serv.getAlgorithm().toUpperCase()).toString();
            if (!services.containsKey(key)) {
                services.put(key, serv);
            }
            for (Iterator<String> it2 = Engine.door.getAliases(serv); it2.hasNext();) {
                alias = it2.next();
                sb.delete(0, sb.length());
                key = sb.append(type).append(".").append(alias.toUpperCase()) //$NON-NLS-1$
                        .toString();
                if (!services.containsKey(key)) {
                    services.put(key, serv);
                }
            }
        }
    
public static intinsertProviderAt(java.security.Provider provider, int position)
Inserts a provider at a specified position

param
provider
param
position
return

        int size = providers.size();
        if ((position < 1) || (position > size)) {
            position = size + 1;
        }
        providers.add(position - 1, provider);
        providersNames.put(provider.getName(), provider);
        setNeedRefresh();
        return position;
    
public static booleanisEmpty()
Returns true if services contain any provider information

return

        return services.isEmpty();
    
private static voidloadProviders()


     
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                loadProviders();
                return null;
            }
        });
    
        String providerClassName = null;
        int i = 1;
        ClassLoader cl = ClassLoader.getSystemClassLoader();
        Provider p;

        while ((providerClassName = Security.getProperty("security.provider." //$NON-NLS-1$
                + i++)) != null) {
            try {
                p = (Provider) Class
                        .forName(providerClassName.trim(), true, cl)
                        .newInstance();
                providers.add(p);
                providersNames.put(p.getName(), p);
                initServiceInfo(p);
            } catch (Exception e) { // ignore
            }
        }
        Engine.door.renumProviders();
    
public static voidprintServices()
Prints Services content

        refresh();
        Set<String> s = services.keySet();
        for (Iterator<String> i = s.iterator(); i.hasNext();) {
            String key = i.next();
            System.out.println(key + "=" + services.get(key)); //$NON-NLS-1$
        }
    
public static voidrefresh()
Refresh services info

        if (needRefresh) {
            refreshNumber++;
            updateServiceInfo();
        }
    
public static voidremoveProvider(int providerNumber)
Removes the provider

param
providerNumber

        Provider p = providers.remove(providerNumber - 1);
        providersNames.remove(p.getName());
        setNeedRefresh();
    
public static voidsetNeedRefresh()
Set flag needRefresh

        needRefresh = true;
    
public static voidupdateServiceInfo()
Updates services hashtable for all registered providers

        services.clear();
        for (Iterator<Provider> it = providers.iterator(); it.hasNext();) {
            initServiceInfo(it.next());
        }
        needRefresh = false;