src/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java

Print this page




  41 import org.w3c.dom.Document;
  42 import org.w3c.dom.Element;
  43 import org.w3c.dom.Node;
  44 
  45 /**
  46  * DOM-based implementation of XMLSignatureFactory.
  47  *
  48  * @author Sean Mullan
  49  */
  50 public final class DOMXMLSignatureFactory extends XMLSignatureFactory {
  51 
  52     /**
  53      * Initializes a new instance of this class.
  54      */
  55     public DOMXMLSignatureFactory() {}
  56 
  57     public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki) {
  58         return new DOMXMLSignature(si, ki, null, null, null);
  59     }
  60 
  61     @SuppressWarnings("unchecked")
  62     public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki,
  63         List objects, String id, String signatureValueId) {
  64         return new DOMXMLSignature(si, ki, objects, id, signatureValueId);
  65     }
  66 
  67     public Reference newReference(String uri, DigestMethod dm) {
  68         return newReference(uri, dm, null, null, null);
  69     }
  70 
  71     @SuppressWarnings("unchecked")
  72     public Reference newReference(String uri, DigestMethod dm, List transforms,
  73         String type, String id) {
  74         return new DOMReference(uri, type, dm, transforms, id, getProvider());
  75     }
  76 
  77     @SuppressWarnings("unchecked")
  78     public Reference newReference(String uri, DigestMethod dm,
  79         List appliedTransforms, Data result, List transforms, String type,
  80         String id) {
  81         if (appliedTransforms == null) {
  82             throw new NullPointerException("appliedTransforms cannot be null");
  83         }
  84         if (appliedTransforms.isEmpty()) {
  85             throw new NullPointerException("appliedTransforms cannot be empty");
  86         }
  87         if (result == null) {
  88             throw new NullPointerException("result cannot be null");
  89         }
  90         return new DOMReference
  91             (uri, type, dm, appliedTransforms, result, transforms, id, getProvider());
  92     }
  93 
  94     @SuppressWarnings("unchecked")
  95     public Reference newReference(String uri, DigestMethod dm, List transforms,
  96         String type, String id, byte[] digestValue) {
  97         if (digestValue == null) {
  98             throw new NullPointerException("digestValue cannot be null");
  99         }
 100         return new DOMReference
 101             (uri, type, dm, null, null, transforms, id, digestValue, getProvider());
 102     }
 103 
 104     @SuppressWarnings("unchecked")
 105     public SignedInfo newSignedInfo(CanonicalizationMethod cm,
 106         SignatureMethod sm, List references) {
 107         return newSignedInfo(cm, sm, references, null);
 108     }
 109 
 110     @SuppressWarnings("unchecked")
 111     public SignedInfo newSignedInfo(CanonicalizationMethod cm,
 112         SignatureMethod sm, List references, String id) {
 113         return new DOMSignedInfo(cm, sm, references, id);
 114     }
 115 
 116     // Object factory methods
 117     @SuppressWarnings("unchecked")
 118     public XMLObject newXMLObject(List content, String id, String mimeType,
 119         String encoding) {
 120         return new DOMXMLObject(content, id, mimeType, encoding);
 121     }
 122 
 123     @SuppressWarnings("unchecked")
 124     public Manifest newManifest(List references) {
 125         return newManifest(references, null);
 126     }
 127 
 128     @SuppressWarnings("unchecked")
 129     public Manifest newManifest(List references, String id) {
 130         return new DOMManifest(references, id);
 131     }
 132 
 133     @SuppressWarnings("unchecked")
 134     public SignatureProperties newSignatureProperties(List props, String id) {
 135         return new DOMSignatureProperties(props, id);
 136     }
 137 
 138     @SuppressWarnings("unchecked")
 139     public SignatureProperty newSignatureProperty
 140         (List info, String target, String id) {
 141         return new DOMSignatureProperty(info, target, id);
 142     }
 143 
 144     public XMLSignature unmarshalXMLSignature(XMLValidateContext context)
 145         throws MarshalException {
 146 
 147         if (context == null) {
 148             throw new NullPointerException("context cannot be null");
 149         }
 150         return unmarshal(((DOMValidateContext) context).getNode(), context);
 151     }
 152 
 153     public XMLSignature unmarshalXMLSignature(XMLStructure xmlStructure)
 154         throws MarshalException {
 155 
 156         if (xmlStructure == null) {
 157             throw new NullPointerException("xmlStructure cannot be null");
 158         }




  41 import org.w3c.dom.Document;
  42 import org.w3c.dom.Element;
  43 import org.w3c.dom.Node;
  44 
  45 /**
  46  * DOM-based implementation of XMLSignatureFactory.
  47  *
  48  * @author Sean Mullan
  49  */
  50 public final class DOMXMLSignatureFactory extends XMLSignatureFactory {
  51 
  52     /**
  53      * Initializes a new instance of this class.
  54      */
  55     public DOMXMLSignatureFactory() {}
  56 
  57     public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki) {
  58         return new DOMXMLSignature(si, ki, null, null, null);
  59     }
  60 
  61     @SuppressWarnings({ "unchecked", "rawtypes" })
  62     public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki,
  63         List objects, String id, String signatureValueId) {
  64         return new DOMXMLSignature(si, ki, objects, id, signatureValueId);
  65     }
  66 
  67     public Reference newReference(String uri, DigestMethod dm) {
  68         return newReference(uri, dm, null, null, null);
  69     }
  70 
  71     @SuppressWarnings({ "unchecked", "rawtypes" })
  72     public Reference newReference(String uri, DigestMethod dm, List transforms,
  73         String type, String id) {
  74         return new DOMReference(uri, type, dm, transforms, id, getProvider());
  75     }
  76 
  77     @SuppressWarnings({ "unchecked", "rawtypes" })
  78     public Reference newReference(String uri, DigestMethod dm,
  79         List appliedTransforms, Data result, List transforms, String type,
  80         String id) {
  81         if (appliedTransforms == null) {
  82             throw new NullPointerException("appliedTransforms cannot be null");
  83         }
  84         if (appliedTransforms.isEmpty()) {
  85             throw new NullPointerException("appliedTransforms cannot be empty");
  86         }
  87         if (result == null) {
  88             throw new NullPointerException("result cannot be null");
  89         }
  90         return new DOMReference
  91             (uri, type, dm, appliedTransforms, result, transforms, id, getProvider());
  92     }
  93 
  94     @SuppressWarnings({ "unchecked", "rawtypes" })
  95     public Reference newReference(String uri, DigestMethod dm, List transforms,
  96         String type, String id, byte[] digestValue) {
  97         if (digestValue == null) {
  98             throw new NullPointerException("digestValue cannot be null");
  99         }
 100         return new DOMReference
 101             (uri, type, dm, null, null, transforms, id, digestValue, getProvider());
 102     }
 103 
 104     @SuppressWarnings("rawtypes")
 105     public SignedInfo newSignedInfo(CanonicalizationMethod cm,
 106         SignatureMethod sm, List references) {
 107         return newSignedInfo(cm, sm, references, null);
 108     }
 109 
 110     @SuppressWarnings({ "unchecked", "rawtypes" })
 111     public SignedInfo newSignedInfo(CanonicalizationMethod cm,
 112         SignatureMethod sm, List references, String id) {
 113         return new DOMSignedInfo(cm, sm, references, id);
 114     }
 115 
 116     // Object factory methods
 117     @SuppressWarnings({ "unchecked", "rawtypes" })
 118     public XMLObject newXMLObject(List content, String id, String mimeType,
 119         String encoding) {
 120         return new DOMXMLObject(content, id, mimeType, encoding);
 121     }
 122 
 123     @SuppressWarnings("rawtypes")
 124     public Manifest newManifest(List references) {
 125         return newManifest(references, null);
 126     }
 127 
 128     @SuppressWarnings({ "unchecked", "rawtypes" })
 129     public Manifest newManifest(List references, String id) {
 130         return new DOMManifest(references, id);
 131     }
 132 
 133     @SuppressWarnings({ "unchecked", "rawtypes" })
 134     public SignatureProperties newSignatureProperties(List props, String id) {
 135         return new DOMSignatureProperties(props, id);
 136     }
 137 
 138     @SuppressWarnings({ "unchecked", "rawtypes" })
 139     public SignatureProperty newSignatureProperty
 140         (List info, String target, String id) {
 141         return new DOMSignatureProperty(info, target, id);
 142     }
 143 
 144     public XMLSignature unmarshalXMLSignature(XMLValidateContext context)
 145         throws MarshalException {
 146 
 147         if (context == null) {
 148             throw new NullPointerException("context cannot be null");
 149         }
 150         return unmarshal(((DOMValidateContext) context).getNode(), context);
 151     }
 152 
 153     public XMLSignature unmarshalXMLSignature(XMLStructure xmlStructure)
 154         throws MarshalException {
 155 
 156         if (xmlStructure == null) {
 157             throw new NullPointerException("xmlStructure cannot be null");
 158         }