KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > crypto > dsig > XMLSignatureFactory


1 /*
2  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3  */

4 /*
5  * $Id: XMLSignatureFactory.java,v 1.14 2005/09/15 14:29:01 mullan Exp $
6  */

7 package javax.xml.crypto.dsig;
8
9 import javax.xml.crypto.Data;
10 import javax.xml.crypto.MarshalException;
11 import javax.xml.crypto.NoSuchMechanismException;
12 import javax.xml.crypto.URIDereferencer;
13 import javax.xml.crypto.XMLStructure;
14 import javax.xml.crypto.dom.DOMStructure;
15 import javax.xml.crypto.dsig.keyinfo.KeyInfo;
16 import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
17 import javax.xml.crypto.dsig.spec.*;
18 import javax.xml.crypto.dsig.dom.DOMValidateContext;
19 import javax.xml.crypto.dsig.dom.DOMSignContext;
20
21 import java.security.InvalidAlgorithmParameterException JavaDoc;
22 import java.security.NoSuchAlgorithmException JavaDoc;
23 import java.security.NoSuchProviderException JavaDoc;
24 import java.security.Provider JavaDoc;
25 import java.security.Security JavaDoc;
26 import java.util.List JavaDoc;
27
28 import sun.security.jca.*;
29 import sun.security.jca.GetInstance.Instance;
30
31 /**
32  * A factory for creating {@link XMLSignature} objects from scratch or
33  * for unmarshalling an <code>XMLSignature</code> object from a corresponding
34  * XML representation.
35  *
36  * <h2>XMLSignatureFactory Type</h2>
37  *
38  * <p>Each instance of <code>XMLSignatureFactory</code> supports a specific
39  * XML mechanism type. To create an <code>XMLSignatureFactory</code>, call one
40  * of the static {@link #getInstance getInstance} methods, passing in the XML
41  * mechanism type desired, for example:
42  *
43  * <blockquote><code>
44  * XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
45  * </code></blockquote>
46  *
47  * <p>The objects that this factory produces will be based
48  * on DOM and abide by the DOM interoperability requirements as defined in the
49  * <a HREF="../../../../../technotes/guides/security/xmldsig/overview.html#DOM Mechanism Requirements">
50  * DOM Mechanism Requirements</a> section of the API overview. See the
51  * <a HREF="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
52  * Service Providers</a> section of the API overview for a list of standard
53  * mechanism types.
54  *
55  * <p><code>XMLSignatureFactory</code> implementations are registered and loaded
56  * using the {@link java.security.Provider} mechanism.
57  * For example, a service provider that supports the
58  * DOM mechanism would be specified in the <code>Provider</code> subclass as:
59  * <pre>
60  * put("XMLSignatureFactory.DOM", "org.example.DOMXMLSignatureFactory");
61  * </pre>
62  *
63  * <p>An implementation MUST minimally support the default mechanism type: DOM.
64  *
65  * <p>Note that a caller must use the same <code>XMLSignatureFactory</code>
66  * instance to create the <code>XMLStructure</code>s of a particular
67  * <code>XMLSignature</code> that is to be generated. The behavior is
68  * undefined if <code>XMLStructure</code>s from different providers or
69  * different mechanism types are used together.
70  *
71  * <p>Also, the <code>XMLStructure</code>s that are created by this factory
72  * may contain state specific to the <code>XMLSignature</code> and are not
73  * intended to be reusable.
74  *
75  * <h2>Creating XMLSignatures from scratch</h2>
76  *
77  * <p>Once the <code>XMLSignatureFactory</code> has been created, objects
78  * can be instantiated by calling the appropriate method. For example, a
79  * {@link Reference} instance may be created by invoking one of the
80  * {@link #newReference newReference} methods.
81  *
82  * <h2>Unmarshalling XMLSignatures from XML</h2>
83  *
84  * <p>Alternatively, an <code>XMLSignature</code> may be created from an
85  * existing XML representation by invoking the {@link #unmarshalXMLSignature
86  * unmarshalXMLSignature} method and passing it a mechanism-specific
87  * {@link XMLValidateContext} instance containing the XML content:
88  *
89  * <pre>
90  * DOMValidateContext context = new DOMValidateContext(key, signatureElement);
91  * XMLSignature signature = factory.unmarshalXMLSignature(context);
92  * </pre>
93  *
94  * Each <code>XMLSignatureFactory</code> must support the required
95  * <code>XMLValidateContext</code> types for that factory type, but may support
96  * others. A DOM <code>XMLSignatureFactory</code> must support {@link
97  * DOMValidateContext} objects.
98  *
99  * <h2>Signing and marshalling XMLSignatures to XML</h2>
100  *
101  * Each <code>XMLSignature</code> created by the factory can also be
102  * marshalled to an XML representation and signed, by invoking the
103  * {@link XMLSignature#sign sign} method of the
104  * {@link XMLSignature} object and passing it a mechanism-specific
105  * {@link XMLSignContext} object containing the signing key and
106  * marshalling parameters (see {@link DOMSignContext}).
107  * For example:
108  *
109  * <pre>
110  * DOMSignContext context = new DOMSignContext(privateKey, document);
111  * signature.sign(context);
112  * </pre>
113  *
114  * <b>Concurrent Access</b>
115  * <p>The static methods of this class are guaranteed to be thread-safe.
116  * Multiple threads may concurrently invoke the static methods defined in this
117  * class with no ill effects.
118  *
119  * <p>However, this is not true for the non-static methods defined by this
120  * class. Unless otherwise documented by a specific provider, threads that
121  * need to access a single <code>XMLSignatureFactory</code> instance
122  * concurrently should synchronize amongst themselves and provide the
123  * necessary locking. Multiple threads each manipulating a different
124  * <code>XMLSignatureFactory</code> instance need not synchronize.
125  *
126  * @author Sean Mullan
127  * @author JSR 105 Expert Group
128  * @since 1.6
129  */

130 public abstract class XMLSignatureFactory {
131
132     private String JavaDoc mechanismType;
133     private Provider JavaDoc provider;
134
135     /**
136      * Default constructor, for invocation by subclasses.
137      */

138     protected XMLSignatureFactory() {}
139
140     /**
141      * Returns an <code>XMLSignatureFactory</code> that supports the
142      * specified XML processing mechanism and representation type (ex: "DOM").
143      *
144      * <p>This method uses the standard JCA provider lookup mechanism to
145      * locate and instantiate an <code>XMLSignatureFactory</code>
146      * implementation of the desired mechanism type. It traverses the list of
147      * registered security <code>Provider</code>s, starting with the most
148      * preferred <code>Provider</code>. A new <code>XMLSignatureFactory</code>
149      * object from the first <code>Provider</code> that supports the specified
150      * mechanism is returned.
151      *
152      * <p>Note that the list of registered providers may be retrieved via
153      * the {@link Security#getProviders() Security.getProviders()} method.
154      *
155      * @param mechanismType the type of the XML processing mechanism and
156      * representation. See the <a
157      * HREF="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
158      * Service Providers</a> section of the API overview for a list of
159      * standard mechanism types.
160      * @return a new <code>XMLSignatureFactory</code>
161      * @throws NullPointerException if <code>mechanismType</code> is
162      * <code>null</code>
163      * @throws NoSuchMechanismException if no <code>Provider</code> supports an
164      * <code>XMLSignatureFactory</code> implementation for the specified
165      * mechanism
166      * @see Provider
167      */

168     public static XMLSignatureFactory getInstance(String JavaDoc mechanismType) {
169     if (mechanismType == null) {
170         throw new NullPointerException JavaDoc("mechanismType cannot be null");
171     }
172     Instance instance;
173     try {
174         instance = GetInstance.getInstance
175             ("XMLSignatureFactory", null, mechanismType);
176     } catch (NoSuchAlgorithmException JavaDoc nsae) {
177         throw new NoSuchMechanismException(nsae);
178     }
179     XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
180     factory.mechanismType = mechanismType;
181     factory.provider = instance.provider;
182     return factory;
183     }
184
185     /**
186      * Returns an <code>XMLSignatureFactory</code> that supports the
187      * requested XML processing mechanism and representation type (ex: "DOM"),
188      * as supplied by the specified provider. Note that the specified
189      * <code>Provider</code> object does not have to be registered in the
190      * provider list.
191      *
192      * @param mechanismType the type of the XML processing mechanism and
193      * representation. See the <a
194      * HREF="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
195      * Service Providers</a> section of the API overview for a list of
196      * standard mechanism types.
197      * @param provider the <code>Provider</code> object
198      * @return a new <code>XMLSignatureFactory</code>
199      * @throws NullPointerException if <code>provider</code> or
200      * <code>mechanismType</code> is <code>null</code>
201      * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
202      * implementation for the specified mechanism is not available
203      * from the specified <code>Provider</code> object
204      * @see Provider
205      */

206     public static XMLSignatureFactory getInstance(String JavaDoc mechanismType,
207     Provider JavaDoc provider) {
208     if (mechanismType == null) {
209         throw new NullPointerException JavaDoc("mechanismType cannot be null");
210     } else if (provider == null) {
211         throw new NullPointerException JavaDoc("provider cannot be null");
212     }
213
214     Instance instance;
215     try {
216         instance = GetInstance.getInstance
217             ("XMLSignatureFactory", null, mechanismType, provider);
218     } catch (NoSuchAlgorithmException JavaDoc nsae) {
219         throw new NoSuchMechanismException(nsae);
220     }
221     XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
222     factory.mechanismType = mechanismType;
223     factory.provider = instance.provider;
224     return factory;
225     }
226
227     /**
228      * Returns an <code>XMLSignatureFactory</code> that supports the
229      * requested XML processing mechanism and representation type (ex: "DOM"),
230      * as supplied by the specified provider. The specified provider must be
231      * registered in the security provider list.
232      *
233      * <p>Note that the list of registered providers may be retrieved via
234      * the {@link Security#getProviders() Security.getProviders()} method.
235      *
236      * @param mechanismType the type of the XML processing mechanism and
237      * representation. See the <a
238      * HREF="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
239      * Service Providers</a> section of the API overview for a list of
240      * standard mechanism types.
241      * @param provider the string name of the provider
242      * @return a new <code>XMLSignatureFactory</code>
243      * @throws NoSuchProviderException if the specified provider is not
244      * registered in the security provider list
245      * @throws NullPointerException if <code>provider</code> or
246      * <code>mechanismType</code> is <code>null</code>
247      * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
248      * implementation for the specified mechanism is not
249      * available from the specified provider
250      * @see Provider
251      */

252     public static XMLSignatureFactory getInstance(String JavaDoc mechanismType,
253     String JavaDoc provider) throws NoSuchProviderException JavaDoc {
254     if (mechanismType == null) {
255         throw new NullPointerException JavaDoc("mechanismType cannot be null");
256     } else if (provider == null) {
257         throw new NullPointerException JavaDoc("provider cannot be null");
258     } else if (provider.length() == 0) {
259         throw new NoSuchProviderException JavaDoc();
260     }
261
262     Instance instance;
263     try {
264         instance = GetInstance.getInstance
265             ("XMLSignatureFactory", null, mechanismType, provider);
266     } catch (NoSuchAlgorithmException JavaDoc nsae) {
267         throw new NoSuchMechanismException(nsae);
268     }
269     XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
270     factory.mechanismType = mechanismType;
271     factory.provider = instance.provider;
272     return factory;
273     }
274
275     /**
276      * Returns an <code>XMLSignatureFactory</code> that supports the
277      * default XML processing mechanism and representation type ("DOM").
278      *
279      * <p>This method uses the standard JCA provider lookup mechanism to
280      * locate and instantiate an <code>XMLSignatureFactory</code>
281      * implementation of the default mechanism type. It traverses the list of
282      * registered security <code>Provider</code>s, starting with the most
283      * preferred <code>Provider</code>. A new <code>XMLSignatureFactory</code>
284      * object from the first <code>Provider</code> that supports the DOM
285      * mechanism is returned.
286      *
287      * <p>Note that the list of registered providers may be retrieved via
288      * the {@link Security#getProviders() Security.getProviders()} method.
289      *
290      * @return a new <code>XMLSignatureFactory</code>
291      * @throws NoSuchMechanismException if no <code>Provider</code> supports an
292      * <code>XMLSignatureFactory</code> implementation for the DOM
293      * mechanism
294      * @see Provider
295      */

296     public static XMLSignatureFactory getInstance() {
297     return getInstance("DOM");
298     }
299
300     /**
301      * Returns the type of the XML processing mechanism and representation
302      * supported by this <code>XMLSignatureFactory</code> (ex: "DOM").
303      *
304      * @return the XML processing mechanism type supported by this
305      * <code>XMLSignatureFactory</code>
306      */

307     public final String JavaDoc getMechanismType() {
308         return mechanismType;
309     }
310
311     /**
312      * Returns the provider of this <code>XMLSignatureFactory</code>.
313      *
314      * @return the provider of this <code>XMLSignatureFactory</code>
315      */

316     public final Provider JavaDoc getProvider() {
317     return provider;
318     }
319
320     /**
321      * Creates an <code>XMLSignature</code> and initializes it with the contents
322      * of the specified <code>SignedInfo</code> and <code>KeyInfo</code>
323      * objects.
324      *
325      * @param si the signed info
326      * @param ki the key info (may be <code>null</code>)
327      * @return an <code>XMLSignature</code>
328      * @throws NullPointerException if <code>si</code> is <code>null</code>
329      */

330     public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki);
331
332     /**
333      * Creates an <code>XMLSignature</code> and initializes it with the
334      * specified parameters.
335      *
336      * @param si the signed info
337      * @param ki the key info (may be <code>null</code>)
338      * @param objects a list of {@link XMLObject}s (may be empty or
339      * <code>null</code>)
340      * @param id the Id (may be <code>null</code>)
341      * @param signatureValueId the SignatureValue Id (may be <code>null</code>)
342      * @return an <code>XMLSignature</code>
343      * @throws NullPointerException if <code>si</code> is <code>null</code>
344      * @throws ClassCastException if any of the <code>objects</code> are not of
345      * type <code>XMLObject</code>
346      */

347     public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki,
348     List JavaDoc objects, String JavaDoc id, String JavaDoc signatureValueId);
349
350     /**
351      * Creates a <code>Reference</code> with the specified URI and digest
352      * method.
353      *
354      * @param uri the reference URI (may be <code>null</code>)
355      * @param dm the digest method
356      * @return a <code>Reference</code>
357      * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
358      * compliant
359      * @throws NullPointerException if <code>dm</code> is <code>null</code>
360      */

361     public abstract Reference newReference(String JavaDoc uri, DigestMethod dm);
362
363     /**
364      * Creates a <code>Reference</code> with the specified parameters.
365      *
366      * @param uri the reference URI (may be <code>null</code>)
367      * @param dm the digest method
368      * @param transforms a list of {@link Transform}s. The list is defensively
369      * copied to protect against subsequent modification. May be
370      * <code>null</code> or empty.
371      * @param type the reference type, as a URI (may be <code>null</code>)
372      * @param id the reference ID (may be <code>null</code>)
373      * @return a <code>Reference</code>
374      * @throws ClassCastException if any of the <code>transforms</code> are
375      * not of type <code>Transform</code>
376      * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
377      * compliant
378      * @throws NullPointerException if <code>dm</code> is <code>null</code>
379      */

380     public abstract Reference newReference(String JavaDoc uri, DigestMethod dm,
381     List JavaDoc transforms, String JavaDoc type, String JavaDoc id);
382
383     /**
384      * Creates a <code>Reference</code> with the specified parameters and
385      * pre-calculated digest value.
386      *
387      * <p>This method is useful when the digest value of a
388      * <code>Reference</code> has been previously computed. See for example,
389      * the
390      * <a HREF="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=dss">
391      * OASIS-DSS (Digital Signature Services)</a> specification.
392      *
393      * @param uri the reference URI (may be <code>null</code>)
394      * @param dm the digest method
395      * @param transforms a list of {@link Transform}s. The list is defensively
396      * copied to protect against subsequent modification. May be
397      * <code>null</code> or empty.
398      * @param type the reference type, as a URI (may be <code>null</code>)
399      * @param id the reference ID (may be <code>null</code>)
400      * @param digestValue the digest value. The array is cloned to protect
401      * against subsequent modification.
402      * @return a <code>Reference</code>
403      * @throws ClassCastException if any of the <code>transforms</code> are
404      * not of type <code>Transform</code>
405      * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
406      * compliant
407      * @throws NullPointerException if <code>dm</code> or
408      * <code>digestValue</code> is <code>null</code>
409      */

410     public abstract Reference newReference(String JavaDoc uri, DigestMethod dm,
411     List JavaDoc transforms, String JavaDoc type, String JavaDoc id, byte[] digestValue);
412
413     /**
414      * Creates a <code>Reference</code> with the specified parameters.
415      *
416      * <p>This method is useful when a list of transforms have already been
417      * applied to the <code>Reference</code>. See for example,
418      * the
419      * <a HREF="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=dss">
420      * OASIS-DSS (Digital Signature Services)</a> specification.
421      *
422      * <p>When an <code>XMLSignature</code> containing this reference is
423      * generated, the specified <code>transforms</code> (if non-null) are
424      * applied to the specified <code>result</code>. The
425      * <code>Transforms</code> element of the resulting <code>Reference</code>
426      * element is set to the concatenation of the
427      * <code>appliedTransforms</code> and <code>transforms</code>.
428      *
429      * @param uri the reference URI (may be <code>null</code>)
430      * @param dm the digest method
431      * @param appliedTransforms a list of {@link Transform}s that have
432      * already been applied. The list is defensively
433      * copied to protect against subsequent modification. The list must
434      * contain at least one entry.
435      * @param result the result of processing the sequence of
436      * <code>appliedTransforms</code>
437      * @param transforms a list of {@link Transform}s that are to be applied
438      * when generating the signature. The list is defensively copied to
439      * protect against subsequent modification. May be <code>null</code>
440      * or empty.
441      * @param type the reference type, as a URI (may be <code>null</code>)
442      * @param id the reference ID (may be <code>null</code>)
443      * @return a <code>Reference</code>
444      * @throws ClassCastException if any of the transforms (in either list)
445      * are not of type <code>Transform</code>
446      * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
447      * compliant or <code>appliedTransforms</code> is empty
448      * @throws NullPointerException if <code>dm</code>,
449      * <code>appliedTransforms</code> or <code>result</code> is
450      * <code>null</code>
451      */

452     public abstract Reference newReference(String JavaDoc uri, DigestMethod dm,
453     List JavaDoc appliedTransforms, Data result, List JavaDoc transforms, String JavaDoc type,
454     String JavaDoc id);
455
456     /**
457      * Creates a <code>SignedInfo</code> with the specified canonicalization
458      * and signature methods, and list of one or more references.
459      *
460      * @param cm the canonicalization method
461      * @param sm the signature method
462      * @param references a list of one or more {@link Reference}s. The list is
463      * defensively copied to protect against subsequent modification.
464      * @return a <code>SignedInfo</code>
465      * @throws ClassCastException if any of the references are not of
466      * type <code>Reference</code>
467      * @throws IllegalArgumentException if <code>references</code> is empty
468      * @throws NullPointerException if any of the parameters
469      * are <code>null</code>
470      */

471     public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm,
472     SignatureMethod sm, List JavaDoc references);
473
474     /**
475      * Creates a <code>SignedInfo</code> with the specified parameters.
476      *
477      * @param cm the canonicalization method
478      * @param sm the signature method
479      * @param references a list of one or more {@link Reference}s. The list is
480      * defensively copied to protect against subsequent modification.
481      * @param id the id (may be <code>null</code>)
482      * @return a <code>SignedInfo</code>
483      * @throws ClassCastException if any of the references are not of
484      * type <code>Reference</code>
485      * @throws IllegalArgumentException if <code>references</code> is empty
486      * @throws NullPointerException if <code>cm</code>, <code>sm</code>, or
487      * <code>references</code> are <code>null</code>
488      */

489     public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm,
490     SignatureMethod sm, List JavaDoc references, String JavaDoc id);
491
492     // Object factory methods
493
/**
494      * Creates an <code>XMLObject</code> from the specified parameters.
495      *
496      * @param content a list of {@link XMLStructure}s. The list
497      * is defensively copied to protect against subsequent modification.
498      * May be <code>null</code> or empty.
499      * @param id the Id (may be <code>null</code>)
500      * @param mimeType the mime type (may be <code>null</code>)
501      * @param encoding the encoding (may be <code>null</code>)
502      * @return an <code>XMLObject</code>
503      * @throws ClassCastException if <code>content</code> contains any
504      * entries that are not of type {@link XMLStructure}
505      */

506     public abstract XMLObject newXMLObject(List JavaDoc content, String JavaDoc id,
507     String JavaDoc mimeType, String JavaDoc encoding);
508
509     /**
510      * Creates a <code>Manifest</code> containing the specified
511      * list of {@link Reference}s.
512      *
513      * @param references a list of one or more <code>Reference</code>s. The list
514      * is defensively copied to protect against subsequent modification.
515      * @return a <code>Manifest</code>
516      * @throws NullPointerException if <code>references</code> is
517      * <code>null</code>
518      * @throws IllegalArgumentException if <code>references</code> is empty
519      * @throws ClassCastException if <code>references</code> contains any
520      * entries that are not of type {@link Reference}
521      */

522     public abstract Manifest newManifest(List JavaDoc references);
523
524     /**
525      * Creates a <code>Manifest</code> containing the specified
526      * list of {@link Reference}s and optional id.
527      *
528      * @param references a list of one or more <code>Reference</code>s. The list
529      * is defensively copied to protect against subsequent modification.
530      * @param id the id (may be <code>null</code>)
531      * @return a <code>Manifest</code>
532      * @throws NullPointerException if <code>references</code> is
533      * <code>null</code>
534      * @throws IllegalArgumentException if <code>references</code> is empty
535      * @throws ClassCastException if <code>references</code> contains any
536      * entries that are not of type {@link Reference}
537      */

538     public abstract Manifest newManifest(List JavaDoc references, String JavaDoc id);
539
540     /**
541      * Creates a <code>SignatureProperty</code> containing the specified
542      * list of {@link XMLStructure}s, target URI and optional id.
543      *
544      * @param content a list of one or more <code>XMLStructure</code>s. The list
545      * is defensively copied to protect against subsequent modification.
546      * @param target the target URI of the Signature that this property applies
547      * to
548      * @param id the id (may be <code>null</code>)
549      * @return a <code>SignatureProperty</code>
550      * @throws NullPointerException if <code>content</code> or
551      * <code>target</code> is <code>null</code>
552      * @throws IllegalArgumentException if <code>content</code> is empty
553      * @throws ClassCastException if <code>content</code> contains any
554      * entries that are not of type {@link XMLStructure}
555      */

556     public abstract SignatureProperty newSignatureProperty
557     (List JavaDoc content, String JavaDoc target, String JavaDoc id);
558
559     /**
560      * Creates a <code>SignatureProperties</code> containing the specified
561      * list of {@link SignatureProperty}s and optional id.
562      *
563      * @param properties a list of one or more <code>SignatureProperty</code>s.
564      * The list is defensively copied to protect against subsequent
565      * modification.
566      * @param id the id (may be <code>null</code>)
567      * @return a <code>SignatureProperties</code>
568      * @throws NullPointerException if <code>properties</code>
569      * is <code>null</code>
570      * @throws IllegalArgumentException if <code>properties</code> is empty
571      * @throws ClassCastException if <code>properties</code> contains any
572      * entries that are not of type {@link SignatureProperty}
573      */

574     public abstract SignatureProperties newSignatureProperties
575     (List JavaDoc properties, String JavaDoc id);
576
577     // Algorithm factory methods
578
/**
579      * Creates a <code>DigestMethod</code> for the specified algorithm URI
580      * and parameters.
581      *
582      * @param algorithm the URI identifying the digest algorithm
583      * @param params algorithm-specific digest parameters (may be
584      * <code>null</code>)
585      * @return the <code>DigestMethod</code>
586      * @throws InvalidAlgorithmParameterException if the specified parameters
587      * are inappropriate for the requested algorithm
588      * @throws NoSuchAlgorithmException if an implementation of the
589      * specified algorithm cannot be found
590      * @throws NullPointerException if <code>algorithm</code> is
591      * <code>null</code>
592      */

593     public abstract DigestMethod newDigestMethod(String JavaDoc algorithm,
594     DigestMethodParameterSpec params) throws NoSuchAlgorithmException JavaDoc,
595     InvalidAlgorithmParameterException JavaDoc;
596
597     /**
598      * Creates a <code>SignatureMethod</code> for the specified algorithm URI
599      * and parameters.
600      *
601      * @param algorithm the URI identifying the signature algorithm
602      * @param params algorithm-specific signature parameters (may be
603      * <code>null</code>)
604      * @return the <code>SignatureMethod</code>
605      * @throws InvalidAlgorithmParameterException if the specified parameters
606      * are inappropriate for the requested algorithm
607      * @throws NoSuchAlgorithmException if an implementation of the
608      * specified algorithm cannot be found
609      * @throws NullPointerException if <code>algorithm</code> is
610      * <code>null</code>
611      */

612     public abstract SignatureMethod newSignatureMethod(String JavaDoc algorithm,
613     SignatureMethodParameterSpec params) throws NoSuchAlgorithmException JavaDoc,
614     InvalidAlgorithmParameterException JavaDoc;
615
616     /**
617      * Creates a <code>Transform</code> for the specified algorithm URI
618      * and parameters.
619      *
620      * @param algorithm the URI identifying the transform algorithm
621      * @param params algorithm-specific transform parameters (may be
622      * <code>null</code>)
623      * @return the <code>Transform</code>
624      * @throws InvalidAlgorithmParameterException if the specified parameters
625      * are inappropriate for the requested algorithm
626      * @throws NoSuchAlgorithmException if an implementation of the
627      * specified algorithm cannot be found
628      * @throws NullPointerException if <code>algorithm</code> is
629      * <code>null</code>
630      */

631     public abstract Transform newTransform(String JavaDoc algorithm,
632     TransformParameterSpec params) throws NoSuchAlgorithmException JavaDoc,
633     InvalidAlgorithmParameterException JavaDoc;
634
635     /**
636      * Creates a <code>Transform</code> for the specified algorithm URI
637      * and parameters. The parameters are specified as a mechanism-specific
638      * <code>XMLStructure</code> (ex: {@link DOMStructure}). This method is
639      * useful when the parameters are in XML form or there is no standard
640      * class for specifying the parameters.
641      *
642      * @param algorithm the URI identifying the transform algorithm
643      * @param params a mechanism-specific XML structure from which to
644      * unmarshal the parameters from (may be <code>null</code> if
645      * not required or optional)
646      * @return the <code>Transform</code>
647      * @throws ClassCastException if the type of <code>params</code> is
648      * inappropriate for this <code>XMLSignatureFactory</code>
649      * @throws InvalidAlgorithmParameterException if the specified parameters
650      * are inappropriate for the requested algorithm
651      * @throws NoSuchAlgorithmException if an implementation of the
652      * specified algorithm cannot be found
653      * @throws NullPointerException if <code>algorithm</code> is
654      * <code>null</code>
655      */

656     public abstract Transform newTransform(String JavaDoc algorithm,
657     XMLStructure params) throws NoSuchAlgorithmException JavaDoc,
658     InvalidAlgorithmParameterException JavaDoc;
659
660     /**
661      * Creates a <code>CanonicalizationMethod</code> for the specified
662      * algorithm URI and parameters.
663      *
664      * @param algorithm the URI identifying the canonicalization algorithm
665      * @param params algorithm-specific canonicalization parameters (may be
666      * <code>null</code>)
667      * @return the <code>CanonicalizationMethod</code>
668      * @throws InvalidAlgorithmParameterException if the specified parameters
669      * are inappropriate for the requested algorithm
670      * @throws NoSuchAlgorithmException if an implementation of the
671      * specified algorithm cannot be found
672      * @throws NullPointerException if <code>algorithm</code> is
673      * <code>null</code>
674      */

675     public abstract CanonicalizationMethod newCanonicalizationMethod(
676     String JavaDoc algorithm, C14NMethodParameterSpec params)
677     throws NoSuchAlgorithmException JavaDoc, InvalidAlgorithmParameterException JavaDoc;
678
679     /**
680      * Creates a <code>CanonicalizationMethod</code> for the specified
681      * algorithm URI and parameters. The parameters are specified as a
682      * mechanism-specific <code>XMLStructure</code> (ex: {@link DOMStructure}).
683      * This method is useful when the parameters are in XML form or there is
684      * no standard class for specifying the parameters.
685      *
686      * @param algorithm the URI identifying the canonicalization algorithm
687      * @param params a mechanism-specific XML structure from which to
688      * unmarshal the parameters from (may be <code>null</code> if
689      * not required or optional)
690      * @return the <code>CanonicalizationMethod</code>
691      * @throws ClassCastException if the type of <code>params</code> is
692      * inappropriate for this <code>XMLSignatureFactory</code>
693      * @throws InvalidAlgorithmParameterException if the specified parameters
694      * are inappropriate for the requested algorithm
695      * @throws NoSuchAlgorithmException if an implementation of the
696      * specified algorithm cannot be found
697      * @throws NullPointerException if <code>algorithm</code> is
698      * <code>null</code>
699      */

700     public abstract CanonicalizationMethod newCanonicalizationMethod(
701     String JavaDoc algorithm, XMLStructure params)
702     throws NoSuchAlgorithmException JavaDoc, InvalidAlgorithmParameterException JavaDoc;
703
704     /**
705      * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
706      * objects. The returned <code>KeyInfoFactory</code> has the same
707      * mechanism type and provider as this <code>XMLSignatureFactory</code>.
708      *
709      * @return a <code>KeyInfoFactory</code>
710      * @throws NoSuchMechanismException if a <code>KeyFactory</code>
711      * implementation with the same mechanism type and provider
712      * is not available
713      */

714     public final KeyInfoFactory getKeyInfoFactory() {
715     return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
716     }
717
718     /**
719      * Unmarshals a new <code>XMLSignature</code> instance from a
720      * mechanism-specific <code>XMLValidateContext</code> instance.
721      *
722      * @param context a mechanism-specific context from which to unmarshal the
723      * signature from
724      * @return the <code>XMLSignature</code>
725      * @throws NullPointerException if <code>context</code> is
726      * <code>null</code>
727      * @throws ClassCastException if the type of <code>context</code> is
728      * inappropriate for this factory
729      * @throws MarshalException if an unrecoverable exception occurs
730      * during unmarshalling
731      */

732     public abstract XMLSignature unmarshalXMLSignature
733     (XMLValidateContext context) throws MarshalException;
734
735     /**
736      * Unmarshals a new <code>XMLSignature</code> instance from a
737      * mechanism-specific <code>XMLStructure</code> instance.
738      * This method is useful if you only want to unmarshal (and not
739      * validate) an <code>XMLSignature</code>.
740      *
741      * @param xmlStructure a mechanism-specific XML structure from which to
742      * unmarshal the signature from
743      * @return the <code>XMLSignature</code>
744      * @throws NullPointerException if <code>xmlStructure</code> is
745      * <code>null</code>
746      * @throws ClassCastException if the type of <code>xmlStructure</code> is
747      * inappropriate for this factory
748      * @throws MarshalException if an unrecoverable exception occurs
749      * during unmarshalling
750      */

751     public abstract XMLSignature unmarshalXMLSignature
752     (XMLStructure xmlStructure) throws MarshalException;
753
754     /**
755      * Indicates whether a specified feature is supported.
756      *
757      * @param feature the feature name (as an absolute URI)
758      * @return <code>true</code> if the specified feature is supported,
759      * <code>false</code> otherwise
760      * @throws NullPointerException if <code>feature</code> is <code>null</code>
761      */

762     public abstract boolean isFeatureSupported(String JavaDoc feature);
763
764     /**
765      * Returns a reference to the <code>URIDereferencer</code> that is used by
766      * default to dereference URIs in {@link Reference} objects.
767      *
768      * @return a reference to the default <code>URIDereferencer</code> (never
769      * <code>null</code>)
770      */

771     public abstract URIDereferencer getURIDereferencer();
772 }
773
Popular Tags