# Class DOMSignContext

java.lang.Object
javax.xml.crypto.dom.DOMCryptoContext
javax.xml.crypto.dsig.dom.DOMSignContext

All Implemented Interfaces:
  `XMLSignContext, XMLCryptoContext`

public class DOMSignContext extends DOMCryptoContext implements XMLSignContext
A DOM-specific `XMLSignContext`. This class contains additional methods to specify the location in a DOM tree where an `XMLSignature` object is to be marshalled when generating the signature.

Note that `DOMSignContext` instances can contain information and state specific to the XML signature structure it is used with. The results are unpredictable if a `DOMSignContext` is used with different signature structures (for example, you should not use the same `DOMSignContext` instance to sign two different `XMLSignature` objects).

Implementation Note:
  The JDK implementation supports the following properties that can be set using the `setProperty` method.
  - `org.jcp.xml.dsig.internal.dom.SignatureProvider`: value must be a `Provider`. If specified, the underlying `Signature` will be instantiated from this provider.
  - `jdk.xmldsig.SecureRandom`: value must be a `SecureRandom`. If specified, this object will be used to initialize the underlying `Signature` during signing using the `Signature.initSign(PrivateKey, SecureRandom)` method.
Since:
  1.6

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DOMSignContext(Key signingKey, Node parent)`
  Creates a `DOMSignContext` with the specified signing key and parent node.
  `DOMSignContext(Key signingKey, Node parent, Node nextSibling)`
  Creates a `DOMSignContext` with the specified signing key, parent and next sibling nodes.
  `DOMSignContext(KeySelector ks, Node parent)`
  Creates a `DOMSignContext` with the specified key selector and parent node.
  `DOMSignContext(KeySelector ks, Node parent, Node nextSibling)`
  Creates a `DOMSignContext` with the specified key selector, parent and next sibling nodes.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Node`
  `getNextSibling()`
  Returns the nextSibling node.
  `Node`
  `getParent()`
  Returns the parent node.
  `void`
  `setNextSibling(Node nextSibling)`
  Sets the next sibling node.
  `void`
  `setParent(Node parent)`
  Sets the parent node.

  ### Methods declared in class DOMCryptoContext

  `get, getBaseURI, getDefaultNamespacePrefix, getElementById, getKeySelector, getNamespacePrefix, getProperty, getURIDereferencer, iterator, put, putNamespacePrefix, setBaseURI, setDefaultNamespacePrefix, setIdAttributeNS, setKeySelector, setProperty, setURIDereferencer`
  Modifier and Type
  Method
  Description
  `Object`
  `get(Object key)`
  This implementation uses an internal `HashMap` to get the object that the specified key maps to.
  `String`
  `getBaseURI()`
  Returns the base URI.
  `String`
  `getDefaultNamespacePrefix()`
  Returns the default namespace prefix.
  `Element`
  `getElementById(String idValue)`
  Returns the `Element` with the specified ID attribute value.
  `KeySelector`
  `getKeySelector()`
  Returns the key selector for finding a key.
  `String`
  `getNamespacePrefix(String namespaceURI, String defaultPrefix)`
  This implementation uses an internal `HashMap` to get the prefix that the specified URI maps to.
  `Object`
  `getProperty(String name)`
  This implementation uses an internal `HashMap` to get the object that the specified name maps to.
  `URIDereferencer`
  `getURIDereferencer()`
  Returns a `URIDereferencer` that is used to dereference `URIReference`s.
  `Iterator<Map.Entry<String,Element>>`
  `iterator()`
  Returns a read-only iterator over the set of Id/Element mappings of this `DOMCryptoContext`.
  `Object`
  `put(Object key, Object value)`
  This implementation uses an internal `HashMap` to map the key to the specified object.
  `String`
  `putNamespacePrefix(String namespaceURI, String prefix)`
  This implementation uses an internal `HashMap` to map the URI to the specified prefix.
  `void`
  `setBaseURI(String baseURI)`
  Sets the base URI.
  `void`
  `setDefaultNamespacePrefix(String defaultPrefix)`
  Sets the default namespace prefix.
  `void`
  `setIdAttributeNS(Element element, String namespaceURI, String localName)`
  Registers the element's attribute specified by the namespace URI and local name to be of type ID.
  `void`
  `setKeySelector(KeySelector ks)`
  Sets the key selector for finding a key.
  `Object`
  `setProperty(String name, Object value)`
  This implementation uses an internal `HashMap` to map the name to the specified object.
  `void`
  `setURIDereferencer(URIDereferencer dereferencer)`
  Sets a `URIDereferencer` that is used to dereference `URIReference`s.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Constructor Details

  - ### DOMSignContext

    public DOMSignContext(Key signingKey, Node parent)
    Creates a `DOMSignContext` with the specified signing key and parent node. The signing key is stored in a `singleton KeySelector` that is returned by the `getKeySelector` method. The marshalled `XMLSignature` will be added as the last child element of the specified parent node unless a next sibling node is specified by invoking the `setNextSibling` method.
    Parameters:
      `signingKey` - the signing key
      `parent` - the parent node
    Throws:
      `NullPointerException` - if `signingKey` or `parent` is `null`

  - ### DOMSignContext

    public DOMSignContext(Key signingKey, Node parent, Node nextSibling)
    Creates a `DOMSignContext` with the specified signing key, parent and next sibling nodes. The signing key is stored in a `singleton KeySelector` that is returned by the `getKeySelector` method. The marshalled `XMLSignature` will be inserted as a child element of the specified parent node and immediately before the specified next sibling node.
    Parameters:
      `signingKey` - the signing key
      `parent` - the parent node
      `nextSibling` - the next sibling node
    Throws:
      `NullPointerException` - if `signingKey`, `parent` or `nextSibling` is `null`

  - ### DOMSignContext

    public DOMSignContext(KeySelector ks, Node parent)
    Creates a `DOMSignContext` with the specified key selector and parent node. The marshalled `XMLSignature` will be added as the last child element of the specified parent node unless a next sibling node is specified by invoking the `setNextSibling` method.
    Parameters:
      `ks` - the key selector
      `parent` - the parent node
    Throws:
      `NullPointerException` - if `ks` or `parent` is `null`

  - ### DOMSignContext

    public DOMSignContext(KeySelector ks, Node parent, Node nextSibling)
    Creates a `DOMSignContext` with the specified key selector, parent and next sibling nodes. The marshalled `XMLSignature` will be inserted as a child element of the specified parent node and immediately before the specified next sibling node.
    Parameters:
      `ks` - the key selector
      `parent` - the parent node
      `nextSibling` - the next sibling node
    Throws:
      `NullPointerException` - if `ks`, `parent` or `nextSibling` is `null`

- ## Method Details

  - ### setParent

    public void setParent(Node parent)
    Sets the parent node.
    Parameters:
      `parent` - the parent node. The marshalled `XMLSignature` will be added as a child element of this node.
    Throws:
      `NullPointerException` - if `parent` is `null`
    See Also:
      - `getParent()`

  - ### setNextSibling

    public void setNextSibling(Node nextSibling)
    Sets the next sibling node.
    Parameters:
      `nextSibling` - the next sibling node. The marshalled `XMLSignature` will be inserted immediately before this node. Specify `null` to remove the current setting.
    See Also:
      - `getNextSibling()`

  - ### getParent

    public Node getParent()
    Returns the parent node.
    Returns:
      the parent node (never `null`)
    See Also:
      - `setParent(Node)`

  - ### getNextSibling

    public Node getNextSibling()
    Returns the nextSibling node.
    Returns:
      the nextSibling node, or `null` if not specified.
    See Also:
      - `setNextSibling(Node)`