KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > crypto > dsig > dom > DOMValidateContext


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

4 /*
5  * $Id: DOMValidateContext.java,v 1.8 2005/05/10 16:31:14 mullan Exp $
6  */

7 package javax.xml.crypto.dsig.dom;
8
9 import javax.xml.crypto.KeySelector;
10 import javax.xml.crypto.dom.DOMCryptoContext;
11 import javax.xml.crypto.dsig.XMLSignature;
12 import javax.xml.crypto.dsig.XMLSignatureFactory;
13 import javax.xml.crypto.dsig.XMLValidateContext;
14 import java.security.Key JavaDoc;
15 import org.w3c.dom.Node JavaDoc;
16
17 /**
18  * A DOM-specific {@link XMLValidateContext}. This class contains additional
19  * methods to specify the location in a DOM tree where an {@link XMLSignature}
20  * is to be unmarshalled and validated from.
21  *
22  * <p>Note that the behavior of an unmarshalled <code>XMLSignature</code>
23  * is undefined if the contents of the underlying DOM tree are modified by the
24  * caller after the <code>XMLSignature</code> is created.
25  *
26  * <p>Also, note that <code>DOMValidateContext</code> instances can contain
27  * information and state specific to the XML signature structure it is
28  * used with. The results are unpredictable if a
29  * <code>DOMValidateContext</code> is used with different signature structures
30  * (for example, you should not use the same <code>DOMValidateContext</code>
31  * instance to validate two different {@link XMLSignature} objects).
32  *
33  * @author Sean Mullan
34  * @author JSR 105 Expert Group
35  * @since 1.6
36  * @see XMLSignatureFactory#unmarshalXMLSignature(XMLValidateContext)
37  */

38 public class DOMValidateContext extends DOMCryptoContext
39     implements XMLValidateContext {
40
41     private Node JavaDoc node;
42
43     /**
44      * Creates a <code>DOMValidateContext</code> containing the specified key
45      * selector and node.
46      *
47      * @param ks a key selector for finding a validation key
48      * @param node the node
49      * @throws NullPointerException if <code>ks</code> or <code>node</code> is
50      * <code>null</code>
51      */

52     public DOMValidateContext(KeySelector ks, Node JavaDoc node) {
53     if (ks == null) {
54         throw new NullPointerException JavaDoc("key selector is null");
55     }
56     if (node == null) {
57         throw new NullPointerException JavaDoc("node is null");
58     }
59     setKeySelector(ks);
60     this.node = node;
61     }
62
63     /**
64      * Creates a <code>DOMValidateContext</code> containing the specified key
65      * and node. The validating key will be stored in a
66      * {@link KeySelector#singletonKeySelector singleton KeySelector} that
67      * is returned when the {@link #getKeySelector getKeySelector}
68      * method is called.
69      *
70      * @param validatingKey the validating key
71      * @param node the node
72      * @throws NullPointerException if <code>validatingKey</code> or
73      * <code>node</code> is <code>null</code>
74      */

75     public DOMValidateContext(Key JavaDoc validatingKey, Node JavaDoc node) {
76     if (validatingKey == null) {
77         throw new NullPointerException JavaDoc("validatingKey is null");
78     }
79     if (node == null) {
80         throw new NullPointerException JavaDoc("node is null");
81     }
82     setKeySelector(KeySelector.singletonKeySelector(validatingKey));
83     this.node = node;
84     }
85
86     /**
87      * Sets the node.
88      *
89      * @param node the node
90      * @throws NullPointerException if <code>node</code> is <code>null</code>
91      * @see #getNode
92      */

93     public void setNode(Node JavaDoc node) {
94     if (node == null) {
95         throw new NullPointerException JavaDoc();
96     }
97     this.node = node;
98     }
99
100     /**
101      * Returns the node.
102      *
103      * @return the node (never <code>null</code>)
104      * @see #setNode(Node)
105      */

106     public Node JavaDoc getNode() {
107     return node;
108     }
109 }
110
Popular Tags