Home » openjdk-7 » javax » xml » crypto » dsig » dom » [javadoc | source]

    1   /*
    2    * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   /*
   26    * $Id: DOMValidateContext.java,v 1.8 2005/05/10 16:31:14 mullan Exp $
   27    */
   28   package javax.xml.crypto.dsig.dom;
   29   
   30   import javax.xml.crypto.KeySelector;
   31   import javax.xml.crypto.dom.DOMCryptoContext;
   32   import javax.xml.crypto.dsig.XMLSignature;
   33   import javax.xml.crypto.dsig.XMLSignatureFactory;
   34   import javax.xml.crypto.dsig.XMLValidateContext;
   35   import java.security.Key;
   36   import org.w3c.dom.Node;
   37   
   38   /**
   39    * A DOM-specific {@link XMLValidateContext}. This class contains additional
   40    * methods to specify the location in a DOM tree where an {@link XMLSignature}
   41    * is to be unmarshalled and validated from.
   42    *
   43    * <p>Note that the behavior of an unmarshalled <code>XMLSignature</code>
   44    * is undefined if the contents of the underlying DOM tree are modified by the
   45    * caller after the <code>XMLSignature</code> is created.
   46    *
   47    * <p>Also, note that <code>DOMValidateContext</code> instances can contain
   48    * information and state specific to the XML signature structure it is
   49    * used with. The results are unpredictable if a
   50    * <code>DOMValidateContext</code> is used with different signature structures
   51    * (for example, you should not use the same <code>DOMValidateContext</code>
   52    * instance to validate two different {@link XMLSignature} objects).
   53    *
   54    * @author Sean Mullan
   55    * @author JSR 105 Expert Group
   56    * @since 1.6
   57    * @see XMLSignatureFactory#unmarshalXMLSignature(XMLValidateContext)
   58    */
   59   public class DOMValidateContext extends DOMCryptoContext
   60       implements XMLValidateContext {
   61   
   62       private Node node;
   63   
   64       /**
   65        * Creates a <code>DOMValidateContext</code> containing the specified key
   66        * selector and node.
   67        *
   68        * @param ks a key selector for finding a validation key
   69        * @param node the node
   70        * @throws NullPointerException if <code>ks</code> or <code>node</code> is
   71        *    <code>null</code>
   72        */
   73       public DOMValidateContext(KeySelector ks, Node node) {
   74           if (ks == null) {
   75               throw new NullPointerException("key selector is null");
   76           }
   77           if (node == null) {
   78               throw new NullPointerException("node is null");
   79           }
   80           setKeySelector(ks);
   81           this.node = node;
   82       }
   83   
   84       /**
   85        * Creates a <code>DOMValidateContext</code> containing the specified key
   86        * and node. The validating key will be stored in a
   87        * {@link KeySelector#singletonKeySelector singleton KeySelector} that
   88        * is returned when the {@link #getKeySelector getKeySelector}
   89        * method is called.
   90        *
   91        * @param validatingKey the validating key
   92        * @param node the node
   93        * @throws NullPointerException if <code>validatingKey</code> or
   94        *    <code>node</code> is <code>null</code>
   95        */
   96       public DOMValidateContext(Key validatingKey, Node node) {
   97           if (validatingKey == null) {
   98               throw new NullPointerException("validatingKey is null");
   99           }
  100           if (node == null) {
  101               throw new NullPointerException("node is null");
  102           }
  103           setKeySelector(KeySelector.singletonKeySelector(validatingKey));
  104           this.node = node;
  105       }
  106   
  107       /**
  108        * Sets the node.
  109        *
  110        * @param node the node
  111        * @throws NullPointerException if <code>node</code> is <code>null</code>
  112        * @see #getNode
  113        */
  114       public void setNode(Node node) {
  115           if (node == null) {
  116               throw new NullPointerException();
  117           }
  118           this.node = node;
  119       }
  120   
  121       /**
  122        * Returns the node.
  123        *
  124        * @return the node (never <code>null</code>)
  125        * @see #setNode(Node)
  126        */
  127       public Node getNode() {
  128           return node;
  129       }
  130   }

Home » openjdk-7 » javax » xml » crypto » dsig » dom » [javadoc | source]