Class TransformService
- java.lang.Object
-
- javax.xml.crypto.dsig.TransformService
-
- All Implemented Interfaces:
- AlgorithmMethod, Transform, XMLStructure
public abstract class TransformService extends java.lang.Object implements Transform
A Service Provider Interface for transform and canonicalization algorithms.Each instance of
TransformServicesupports a specific transform or canonicalization algorithm and XML mechanism type. To create aTransformService, call one of the staticgetInstancemethods, passing in the algorithm URI and XML mechanism type desired, for example:TransformService ts = TransformService.getInstance(Transform.XPATH2, "DOM");TransformServiceimplementations are registered and loaded using theProvidermechanism. EachTransformServiceservice provider implementation should include aMechanismTypeservice attribute that identifies the XML mechanism type that it supports. If the attribute is not specified, "DOM" is assumed. For example, a service provider that supports the XPath Filter 2 Transform and DOM mechanism would be specified in theProvidersubclass as:put("TransformService." + Transform.XPATH2, "org.example.XPath2TransformService"); put("TransformService." + Transform.XPATH2 + " MechanismType", "DOM");TransformServiceimplementations that support the DOM mechanism type must abide by the DOM interoperability requirements defined in the DOM Mechanism Requirements section of the API overview. See the Service Providers section of the API overview for a list of standard mechanism types.Once a
TransformServicehas been created, it can be used to processTransformorCanonicalizationMethodobjects. If theTransformorCanonicalizationMethodexists in XML form (for example, when validating an existingXMLSignature), theinit(XMLStructure, XMLCryptoContext)method must be first called to initialize the transform and provide document context (even if there are no parameters). Alternatively, if theTransformorCanonicalizationMethodis being created from scratch, theinit(TransformParameterSpec)method is called to initialize the transform with parameters and themarshalParamsmethod is called to marshal the parameters to XML and provide the transform with document context. Finally, thetransformmethod is called to perform the transformation.Concurrent Access
The static methods of this class are guaranteed to be thread-safe. Multiple threads may concurrently invoke the static methods defined in this class with no ill effects.
However, this is not true for the non-static methods defined by this class. Unless otherwise documented by a specific provider, threads that need to access a single
TransformServiceinstance concurrently should synchronize amongst themselves and provide the necessary locking. Multiple threads each manipulating a differentTransformServiceinstance need not synchronize.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description private static classTransformService.MechanismMapEntry
-
Field Summary
Fields Modifier and Type Field and Description private java.lang.Stringalgorithmprivate static java.lang.Classclprivate static java.lang.reflect.MethodgetImplMethodprivate static java.lang.Class[]getImplParamsprivate java.lang.Stringmechanismprivate java.security.Providerprovider
-
Constructor Summary
Constructors Modifier Constructor and Description protectedTransformService()Default constructor, for invocation by subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description private static TransformServicefindInstance(java.lang.String algorithm, java.lang.String mechanismType, java.security.Provider provider)java.lang.StringgetAlgorithm()Returns the URI of the algorithm supported by thisTransformService.static TransformServicegetInstance(java.lang.String algorithm, java.lang.String mechanismType)Returns aTransformServicethat supports the specified algorithm URI (ex:Transform.XPATH2) and mechanism type (ex: DOM).static TransformServicegetInstance(java.lang.String algorithm, java.lang.String mechanismType, java.security.Provider provider)Returns aTransformServicethat supports the specified algorithm URI (ex:Transform.XPATH2) and mechanism type (ex: DOM) as supplied by the specified provider.static TransformServicegetInstance(java.lang.String algorithm, java.lang.String mechanismType, java.lang.String provider)Returns aTransformServicethat supports the specified algorithm URI (ex:Transform.XPATH2) and mechanism type (ex: DOM) as supplied by the specified provider.java.lang.StringgetMechanismType()Returns the mechanism type supported by thisTransformService.java.security.ProvidergetProvider()Returns the provider of thisTransformService.abstract voidinit(TransformParameterSpec params)Initializes thisTransformServicewith the specified parameters.abstract voidinit(XMLStructure parent, XMLCryptoContext context)Initializes thisTransformServicewith the specified parameters and document context.abstract voidmarshalParams(XMLStructure parent, XMLCryptoContext context)Marshals the algorithm-specific parameters.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.xml.crypto.dsig.Transform
getParameterSpec, transform, transform
-
Methods inherited from interface javax.xml.crypto.XMLStructure
isFeatureSupported
-
-
-
-
Field Detail
-
algorithm
private java.lang.String algorithm
-
mechanism
private java.lang.String mechanism
-
provider
private java.security.Provider provider
-
cl
private static java.lang.Class cl
-
getImplParams
private static final java.lang.Class[] getImplParams
-
getImplMethod
private static java.lang.reflect.Method getImplMethod
-
-
Constructor Detail
-
TransformService
protected TransformService()
Default constructor, for invocation by subclasses.
-
-
Method Detail
-
getInstance
public static TransformService getInstance(java.lang.String algorithm, java.lang.String mechanismType) throws java.security.NoSuchAlgorithmException
Returns aTransformServicethat supports the specified algorithm URI (ex:Transform.XPATH2) and mechanism type (ex: DOM).This method uses the standard JCA provider lookup mechanism to locate and instantiate a
TransformServiceimplementation of the desired algorithm andMechanismTypeservice attribute. It traverses the list of registered securityProviders, starting with the most preferredProvider. A newTransformServiceobject from the firstProviderthat supports the specified algorithm and mechanism type is returned.Note that the list of registered providers may be retrieved via the
Security.getProviders()method.- Parameters:
algorithm- the URI of the algorithmmechanismType- the type of the XML processing mechanism and representation- Returns:
- a new
TransformService - Throws:
java.lang.NullPointerException- ifalgorithmormechanismTypeisnulljava.security.NoSuchAlgorithmException- if noProvidersupports aTransformServiceimplementation for the specified algorithm and mechanism type- See Also:
Provider
-
getInstance
public static TransformService getInstance(java.lang.String algorithm, java.lang.String mechanismType, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
Returns aTransformServicethat supports the specified algorithm URI (ex:Transform.XPATH2) and mechanism type (ex: DOM) as supplied by the specified provider. Note that the specifiedProviderobject does not have to be registered in the provider list.- Parameters:
algorithm- the URI of the algorithmmechanismType- the type of the XML processing mechanism and representationprovider- theProviderobject- Returns:
- a new
TransformService - Throws:
java.lang.NullPointerException- ifprovider,algorithm, ormechanismTypeisnulljava.security.NoSuchAlgorithmException- if aTransformServiceimplementation for the specified algorithm and mechanism type is not available from the specifiedProviderobject- See Also:
Provider
-
getInstance
public static TransformService getInstance(java.lang.String algorithm, java.lang.String mechanismType, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
Returns aTransformServicethat supports the specified algorithm URI (ex:Transform.XPATH2) and mechanism type (ex: DOM) as supplied by the specified provider. The specified provider must be registered in the security provider list.Note that the list of registered providers may be retrieved via the
Security.getProviders()method.- Parameters:
algorithm- the URI of the algorithmmechanismType- the type of the XML processing mechanism and representationprovider- the string name of the provider- Returns:
- a new
TransformService - Throws:
java.security.NoSuchProviderException- if the specified provider is not registered in the security provider listjava.lang.NullPointerException- ifprovider,mechanismType, oralgorithmisnulljava.security.NoSuchAlgorithmException- if aTransformServiceimplementation for the specified algorithm and mechanism type is not available from the specified provider- See Also:
Provider
-
findInstance
private static TransformService findInstance(java.lang.String algorithm, java.lang.String mechanismType, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
- Throws:
java.security.NoSuchAlgorithmException
-
getMechanismType
public final java.lang.String getMechanismType()
Returns the mechanism type supported by thisTransformService.- Returns:
- the mechanism type
-
getAlgorithm
public final java.lang.String getAlgorithm()
Returns the URI of the algorithm supported by thisTransformService.- Specified by:
getAlgorithmin interfaceAlgorithmMethod- Returns:
- the algorithm URI
-
getProvider
public final java.security.Provider getProvider()
Returns the provider of thisTransformService.- Returns:
- the provider
-
init
public abstract void init(TransformParameterSpec params) throws java.security.InvalidAlgorithmParameterException
Initializes thisTransformServicewith the specified parameters.If the parameters exist in XML form, the
init(XMLStructure, XMLCryptoContext)method should be used to initialize theTransformService.- Parameters:
params- the algorithm parameters (may benullif not required or optional)- Throws:
java.security.InvalidAlgorithmParameterException- if the specified parameters are invalid for this algorithm
-
marshalParams
public abstract void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException
Marshals the algorithm-specific parameters. If there are no parameters to be marshalled, this method returns without throwing an exception.- Parameters:
parent- a mechanism-specific structure containing the parent node that the marshalled parameters should be appended tocontext- theXMLCryptoContextcontaining additional context (may benullif not applicable)- Throws:
java.lang.ClassCastException- if the type ofparentorcontextis not compatible with thisTransformServicejava.lang.NullPointerException- ifparentisnullMarshalException- if the parameters cannot be marshalled
-
init
public abstract void init(XMLStructure parent, XMLCryptoContext context) throws java.security.InvalidAlgorithmParameterException
Initializes thisTransformServicewith the specified parameters and document context.- Parameters:
parent- a mechanism-specific structure containing the parent structurecontext- theXMLCryptoContextcontaining additional context (may benullif not applicable)- Throws:
java.lang.ClassCastException- if the type ofparentorcontextis not compatible with thisTransformServicejava.lang.NullPointerException- ifparentisnulljava.security.InvalidAlgorithmParameterException- if the specified parameters are invalid for this algorithm
-
-