KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 /*
5  * $Id: DOMSignContext.java,v 1.9 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.XMLSignContext;
12 import javax.xml.crypto.dsig.XMLSignature;
13 import java.security.Key JavaDoc;
14 import org.w3c.dom.Node JavaDoc;
15
16 /**
17  * A DOM-specific {@link XMLSignContext}. This class contains additional methods
18  * to specify the location in a DOM tree where an {@link XMLSignature}
19  * object is to be marshalled when generating the signature.
20  *
21  * <p>Note that <code>DOMSignContext</code> instances can contain
22  * information and state specific to the XML signature structure it is
23  * used with. The results are unpredictable if a
24  * <code>DOMSignContext</code> is used with different signature structures
25  * (for example, you should not use the same <code>DOMSignContext</code>
26  * instance to sign two different {@link XMLSignature} objects).
27  *
28  * @author Sean Mullan
29  * @author JSR 105 Expert Group
30  * @since 1.6
31  */

32 public class DOMSignContext extends DOMCryptoContext implements XMLSignContext {
33
34     private Node JavaDoc parent;
35     private Node JavaDoc nextSibling;
36
37     /**
38      * Creates a <code>DOMSignContext</code> with the specified signing key
39      * and parent node. The signing key is stored in a
40      * {@link KeySelector#singletonKeySelector singleton KeySelector} that is
41      * returned by the {@link #getKeySelector getKeySelector} method.
42      * The marshalled <code>XMLSignature</code> will be added as the last
43      * child element of the specified parent node unless a next sibling node is
44      * specified by invoking the {@link #setNextSibling setNextSibling} method.
45      *
46      * @param signingKey the signing key
47      * @param parent the parent node
48      * @throws NullPointerException if <code>signingKey</code> or
49      * <code>parent</code> is <code>null</code>
50      */

51     public DOMSignContext(Key JavaDoc signingKey, Node JavaDoc parent) {
52         if (signingKey == null) {
53             throw new NullPointerException JavaDoc("signingKey cannot be null");
54         }
55         if (parent == null) {
56             throw new NullPointerException JavaDoc("parent cannot be null");
57         }
58         setKeySelector(KeySelector.singletonKeySelector(signingKey));
59         this.parent = parent;
60     }
61
62     /**
63      * Creates a <code>DOMSignContext</code> with the specified signing key,
64      * parent and next sibling nodes. The signing key is stored in a
65      * {@link KeySelector#singletonKeySelector singleton KeySelector} that is
66      * returned by the {@link #getKeySelector getKeySelector} method.
67      * The marshalled <code>XMLSignature</code> will be inserted as a child
68      * element of the specified parent node and immediately before the
69      * specified next sibling node.
70      *
71      * @param signingKey the signing key
72      * @param parent the parent node
73      * @param nextSibling the next sibling node
74      * @throws NullPointerException if <code>signingKey</code>,
75      * <code>parent</code> or <code>nextSibling</code> is <code>null</code>
76      */

77     public DOMSignContext(Key JavaDoc signingKey, Node JavaDoc parent, Node JavaDoc nextSibling) {
78         if (signingKey == null) {
79             throw new NullPointerException JavaDoc("signingKey cannot be null");
80         }
81         if (parent == null) {
82             throw new NullPointerException JavaDoc("parent cannot be null");
83         }
84         if (nextSibling == null) {
85             throw new NullPointerException JavaDoc("nextSibling cannot be null");
86         }
87         setKeySelector(KeySelector.singletonKeySelector(signingKey));
88         this.parent = parent;
89         this.nextSibling = nextSibling;
90     }
91
92     /**
93      * Creates a <code>DOMSignContext</code> with the specified key selector
94      * and parent node. The marshalled <code>XMLSignature</code> will be added
95      * as the last child element of the specified parent node unless a next
96      * sibling node is specified by invoking the
97      * {@link #setNextSibling setNextSibling} method.
98      *
99      * @param ks the key selector
100      * @param parent the parent node
101      * @throws NullPointerException if <code>ks</code> or <code>parent</code>
102      * is <code>null</code>
103      */

104     public DOMSignContext(KeySelector ks, Node JavaDoc parent) {
105         if (ks == null) {
106             throw new NullPointerException JavaDoc("key selector cannot be null");
107         }
108         if (parent == null) {
109             throw new NullPointerException JavaDoc("parent cannot be null");
110         }
111         setKeySelector(ks);
112         this.parent = parent;
113     }
114
115     /**
116      * Creates a <code>DOMSignContext</code> with the specified key selector,
117      * parent and next sibling nodes. The marshalled <code>XMLSignature</code>
118      * will be inserted as a child element of the specified parent node and
119      * immediately before the specified next sibling node.
120      *
121      * @param ks the key selector
122      * @param parent the parent node
123      * @param nextSibling the next sibling node
124      * @throws NullPointerException if <code>ks</code>, <code>parent</code> or
125      * <code>nextSibling</code> is <code>null</code>
126      */

127     public DOMSignContext(KeySelector ks, Node JavaDoc parent, Node JavaDoc nextSibling) {
128         if (ks == null) {
129             throw new NullPointerException JavaDoc("key selector cannot be null");
130         }
131         if (parent == null) {
132             throw new NullPointerException JavaDoc("parent cannot be null");
133         }
134         if (nextSibling == null) {
135             throw new NullPointerException JavaDoc("nextSibling cannot be null");
136         }
137         setKeySelector(ks);
138         this.parent = parent;
139         this.nextSibling = nextSibling;
140     }
141
142     /**
143      * Sets the parent node.
144      *
145      * @param parent the parent node. The marshalled <code>XMLSignature</code>
146      * will be added as a child element of this node.
147      * @throws NullPointerException if <code>parent</code> is <code>null</code>
148      * @see #getParent
149      */

150     public void setParent(Node JavaDoc parent) {
151     if (parent == null) {
152         throw new NullPointerException JavaDoc("parent is null");
153     }
154     this.parent = parent;
155     }
156
157     /**
158      * Sets the next sibling node.
159      *
160      * @param nextSibling the next sibling node. The marshalled
161      * <code>XMLSignature</code> will be inserted immediately before this
162      * node. Specify <code>null</code> to remove the current setting.
163      * @see #getNextSibling
164      */

165     public void setNextSibling(Node JavaDoc nextSibling) {
166     this.nextSibling = nextSibling;
167     }
168
169     /**
170      * Returns the parent node.
171      *
172      * @return the parent node (never <code>null</code>)
173      * @see #setParent(Node)
174      */

175     public Node JavaDoc getParent() {
176     return parent;
177     }
178
179     /**
180      * Returns the nextSibling node.
181      *
182      * @return the nextSibling node, or <code>null</code> if not specified.
183      * @see #setNextSibling(Node)
184      */

185     public Node JavaDoc getNextSibling() {
186     return nextSibling;
187     }
188 }
189
Popular Tags