org.jcp.xml.dsig.internal.dom.DOMSignatureProperty Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import java.util.ArrayList;
/* */ import java.util.Collections;
/* */ import java.util.List;
/* */ import javax.xml.crypto.MarshalException;
/* */ import javax.xml.crypto.XMLStructure;
/* */ import javax.xml.crypto.dom.DOMCryptoContext;
/* */ import javax.xml.crypto.dsig.SignatureProperty;
/* */ import org.w3c.dom.Document;
/* */ import org.w3c.dom.Element;
/* */ import org.w3c.dom.Node;
/* */ import org.w3c.dom.NodeList;
/* */
/* */ public final class DOMSignatureProperty extends DOMStructure
/* */ implements SignatureProperty
/* */ {
/* */ private final String id;
/* */ private final String target;
/* */ private final List content;
/* */
/* */ public DOMSignatureProperty(List content, String target, String id)
/* */ {
/* 46 */ if (target == null)
/* 47 */ throw new NullPointerException("target cannot be null");
/* 48 */ if (content == null)
/* 49 */ throw new NullPointerException("content cannot be null");
/* 50 */ if (content.isEmpty()) {
/* 51 */ throw new IllegalArgumentException("content cannot be empty");
/* */ }
/* 53 */ List contentCopy = new ArrayList(content);
/* 54 */ int i = 0; for (int size = contentCopy.size(); i < size; i++) {
/* 55 */ if (!(contentCopy.get(i) instanceof XMLStructure)) {
/* 56 */ throw new ClassCastException("content[" + i + "] is not a valid type");
/* */ }
/* */ }
/* */
/* 60 */ this.content = Collections.unmodifiableList(contentCopy);
/* */
/* 62 */ this.target = target;
/* 63 */ this.id = id;
/* */ }
/* */
/* */ public DOMSignatureProperty(Element propElem)
/* */ throws MarshalException
/* */ {
/* 73 */ this.target = DOMUtils.getAttributeValue(propElem, "Target");
/* 74 */ if (this.target == null) {
/* 75 */ throw new MarshalException("target cannot be null");
/* */ }
/* 77 */ this.id = DOMUtils.getAttributeValue(propElem, "Id");
/* */
/* 79 */ NodeList nodes = propElem.getChildNodes();
/* 80 */ int length = nodes.getLength();
/* 81 */ List content = new ArrayList(length);
/* 82 */ for (int i = 0; i < length; i++) {
/* 83 */ content.add(new javax.xml.crypto.dom.DOMStructure(nodes.item(i)));
/* */ }
/* 85 */ if (content.isEmpty()) {
/* 86 */ throw new MarshalException("content cannot be empty");
/* */ }
/* 88 */ this.content = Collections.unmodifiableList(content);
/* */ }
/* */
/* */ public List getContent()
/* */ {
/* 93 */ return this.content;
/* */ }
/* */
/* */ public String getId() {
/* 97 */ return this.id;
/* */ }
/* */
/* */ public String getTarget() {
/* 101 */ return this.target;
/* */ }
/* */
/* */ public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) throws MarshalException
/* */ {
/* 106 */ Document ownerDoc = DOMUtils.getOwnerDocument(parent);
/* */
/* 108 */ Element propElem = DOMUtils.createElement(ownerDoc, "SignatureProperty", "http://www.w3.org/2000/09/xmldsig#", dsPrefix);
/* */
/* 112 */ DOMUtils.setAttributeID(propElem, "Id", this.id);
/* 113 */ DOMUtils.setAttribute(propElem, "Target", this.target);
/* */
/* 116 */ int i = 0; for (int size = this.content.size(); i < size; i++) {
/* 117 */ javax.xml.crypto.dom.DOMStructure property = (javax.xml.crypto.dom.DOMStructure)this.content.get(i);
/* */
/* 119 */ DOMUtils.appendChild(propElem, property.getNode());
/* */ }
/* */
/* 122 */ parent.appendChild(propElem);
/* */ }
/* */
/* */ public boolean equals(Object o) {
/* 126 */ if (this == o) {
/* 127 */ return true;
/* */ }
/* */
/* 130 */ if (!(o instanceof SignatureProperty)) {
/* 131 */ return false;
/* */ }
/* 133 */ SignatureProperty osp = (SignatureProperty)o;
/* */
/* 135 */ boolean idsEqual = this.id == null ? false : osp.getId() == null ? true : this.id.equals(osp.getId());
/* */
/* 138 */ return (equalsContent(osp.getContent())) && (this.target.equals(osp.getTarget())) && (idsEqual);
/* */ }
/* */
/* */ private boolean equalsContent(List otherContent)
/* */ {
/* 143 */ int osize = otherContent.size();
/* 144 */ if (this.content.size() != osize) {
/* 145 */ return false;
/* */ }
/* 147 */ for (int i = 0; i < osize; i++) {
/* 148 */ XMLStructure oxs = (XMLStructure)otherContent.get(i);
/* 149 */ XMLStructure xs = (XMLStructure)this.content.get(i);
/* 150 */ if ((oxs instanceof javax.xml.crypto.dom.DOMStructure)) {
/* 151 */ if (!(xs instanceof javax.xml.crypto.dom.DOMStructure)) {
/* 152 */ return false;
/* */ }
/* 154 */ Node onode = ((javax.xml.crypto.dom.DOMStructure)oxs).getNode();
/* */
/* 156 */ Node node = ((javax.xml.crypto.dom.DOMStructure)xs).getNode();
/* */
/* 158 */ if (!DOMUtils.nodesEqual(node, onode)) {
/* 159 */ return false;
/* */ }
/* */ }
/* 162 */ else if (!xs.equals(oxs)) {
/* 163 */ return false;
/* */ }
/* */
/* */ }
/* */
/* 168 */ return true;
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMSignatureProperty
* JD-Core Version: 0.6.2
*/