Class Engine
- java.lang.Object
-
- org.apache.harmony.security.fortress.Engine
-
public final class Engine extends Object
This class implements common functionality for Provider supplied classes. The usage pattern is to allocate static Engine instance per service type and synchronize on that instance during calls togetInstanceand retrieval of the selectedProviderand Service Provider Interface (SPI) results. Retrieving the results withgetProviderandgetSpisets the internalEnginevalues to null to prevent memory leaks.For example:
{@code public class Foo { private static final Engine ENGINE = new Engine("Foo"); private final FooSpi spi; private final Provider provider; private final String algorithm; protected Foo(FooSpi spi, Provider provider, String algorithm) { this.spi = spi; this.provider = provider; this.algorithm = algorithm; } public static Foo getInstance(String algorithm) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new Foo((FooSpi) sap.spi, sap.provider, algorithm); } public static Foo getInstance(String algorithm, Provider provider) { Object spi = ENGINE.getInstance(algorithm, provider, null); return new Foo((FooSpi) spi, provider, algorithm); } ... }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEngine.SpiAndProvider
-
Field Summary
Fields Modifier and Type Field Description static SecurityAccessdoorAccess to package visible api in java.security
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Engine.SpiAndProvidergetInstance(String algorithm, Object param)Finds the appropriate service implementation and returns anSpiAndProviderinstance containing a reference to the first matching SPI and itsProviderObjectgetInstance(String algorithm, Provider provider, Object param)Finds the appropriate service implementation and returns and instance of the class that implements corresponding Service Provider Interface.Engine.SpiAndProvidergetInstance(Provider.Service service, String param)Finds the appropriate service implementation and returns anSpiAndProviderinstance containing a reference to SPI and itsProviderArrayList<Provider.Service>getServices()Returns a list of all providers for this type of service ornullif no matches were found.ArrayList<Provider.Service>getServices(String algorithm)Returns a list of all possible matches for a given algorithm.
-
-
-
Field Detail
-
door
public static SecurityAccess door
Access to package visible api in java.security
-
-
Constructor Detail
-
Engine
public Engine(String serviceName)
Creates a Engine object- Parameters:
serviceName-
-
-
Method Detail
-
getInstance
public Engine.SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException
Finds the appropriate service implementation and returns anSpiAndProviderinstance containing a reference to the first matching SPI and itsProvider- Throws:
NoSuchAlgorithmException
-
getInstance
public Engine.SpiAndProvider getInstance(Provider.Service service, String param) throws NoSuchAlgorithmException
Finds the appropriate service implementation and returns anSpiAndProviderinstance containing a reference to SPI and itsProvider- Throws:
NoSuchAlgorithmException
-
getServices
public ArrayList<Provider.Service> getServices()
Returns a list of all providers for this type of service ornullif no matches were found.
-
getServices
public ArrayList<Provider.Service> getServices(String algorithm)
Returns a list of all possible matches for a given algorithm. Returnsnullif no matches were found.
-
getInstance
public Object getInstance(String algorithm, Provider provider, Object param) throws NoSuchAlgorithmException
Finds the appropriate service implementation and returns and instance of the class that implements corresponding Service Provider Interface.- Throws:
NoSuchAlgorithmException
-
-