1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
/* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. */ /* * $Id: DOMValidateContext.java,v 1.8 2005/05/10 16:31:14 mullan Exp $ */ package javax.xml.crypto.dsig.dom; import javax.xml.crypto.KeySelector; import javax.xml.crypto.dom.DOMCryptoContext; import javax.xml.crypto.dsig.XMLSignature; import javax.xml.crypto.dsig.XMLSignatureFactory; import javax.xml.crypto.dsig.XMLValidateContext; import java.security.Key; import org.w3c.dom.Node; /** * A DOM-specific {@link XMLValidateContext}. This class contains additional * methods to specify the location in a DOM tree where an {@link XMLSignature} * is to be unmarshalled and validated from. * * <p>Note that the behavior of an unmarshalled <code>XMLSignature</code> * is undefined if the contents of the underlying DOM tree are modified by the * caller after the <code>XMLSignature</code> is created. * * <p>Also, note that <code>DOMValidateContext</code> instances can contain * information and state specific to the XML signature structure it is * used with. The results are unpredictable if a * <code>DOMValidateContext</code> is used with different signature structures * (for example, you should not use the same <code>DOMValidateContext</code> * instance to validate two different {@link XMLSignature} objects). * * @author Sean Mullan * @author JSR 105 Expert Group * @since 1.6 * @see XMLSignatureFactory#unmarshalXMLSignature(XMLValidateContext) */ public class DOMValidateContext extends DOMCryptoContext implements XMLValidateContext { private Node node; /** * Creates a <code>DOMValidateContext</code> containing the specified key * selector and node. * * @param ks a key selector for finding a validation key * @param node the node * @throws NullPointerException if <code>ks</code> or <code>node</code> is * <code>null</code> */ public DOMValidateContext(KeySelector ks, Node node) { if (ks == null) { throw new NullPointerException("key selector is null"); } if (node == null) { throw new NullPointerException("node is null"); } setKeySelector(ks); this.node = node; } /** * Creates a <code>DOMValidateContext</code> containing the specified key * and node. The validating key will be stored in a * {@link KeySelector#singletonKeySelector singleton KeySelector} that * is returned when the {@link #getKeySelector getKeySelector} * method is called. * * @param validatingKey the validating key * @param node the node * @throws NullPointerException if <code>validatingKey</code> or * <code>node</code> is <code>null</code> */ public DOMValidateContext(Key validatingKey, Node node) { if (validatingKey == null) { throw new NullPointerException("validatingKey is null"); } if (node == null) { throw new NullPointerException("node is null"); } setKeySelector(KeySelector.singletonKeySelector(validatingKey)); this.node = node; } /** * Sets the node. * * @param node the node * @throws NullPointerException if <code>node</code> is <code>null</code> * @see #getNode */ public void setNode(Node node) { if (node == null) { throw new NullPointerException(); } this.node = node; } /** * Returns the node. * * @return the node (never <code>null</code>) * @see #setNode(Node) */ public Node getNode() { return node; } }