All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jcp.xml.dsig.internal.dom.DOMSignatureProperties 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.dom.DOMCryptoContext;
/*     */ import javax.xml.crypto.dsig.SignatureProperties;
/*     */ 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 DOMSignatureProperties extends DOMStructure
/*     */   implements SignatureProperties
/*     */ {
/*     */   private final String id;
/*     */   private final List properties;
/*     */ 
/*     */   public DOMSignatureProperties(List properties, String id)
/*     */   {
/*  44 */     if (properties == null)
/*  45 */       throw new NullPointerException("properties cannot be null");
/*  46 */     if (properties.isEmpty()) {
/*  47 */       throw new IllegalArgumentException("properties cannot be empty");
/*     */     }
/*  49 */     List propsCopy = new ArrayList(properties);
/*  50 */     int i = 0; for (int size = propsCopy.size(); i < size; i++) {
/*  51 */       if (!(propsCopy.get(i) instanceof SignatureProperty)) {
/*  52 */         throw new ClassCastException("properties[" + i + "] is not a valid type");
/*     */       }
/*     */     }
/*     */ 
/*  56 */     this.properties = Collections.unmodifiableList(propsCopy);
/*     */ 
/*  58 */     this.id = id;
/*     */   }
/*     */ 
/*     */   public DOMSignatureProperties(Element propsElem)
/*     */     throws MarshalException
/*     */   {
/*  69 */     this.id = DOMUtils.getAttributeValue(propsElem, "Id");
/*     */ 
/*  71 */     NodeList nodes = propsElem.getChildNodes();
/*  72 */     int length = nodes.getLength();
/*  73 */     List properties = new ArrayList(length);
/*  74 */     for (int i = 0; i < length; i++) {
/*  75 */       Node child = nodes.item(i);
/*  76 */       if (child.getNodeType() == 1) {
/*  77 */         properties.add(new DOMSignatureProperty((Element)child));
/*     */       }
/*     */     }
/*  80 */     if (properties.isEmpty()) {
/*  81 */       throw new MarshalException("properties cannot be empty");
/*     */     }
/*  83 */     this.properties = Collections.unmodifiableList(properties);
/*     */   }
/*     */ 
/*     */   public List getProperties()
/*     */   {
/*  88 */     return this.properties;
/*     */   }
/*     */ 
/*     */   public String getId() {
/*  92 */     return this.id;
/*     */   }
/*     */ 
/*     */   public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) throws MarshalException
/*     */   {
/*  97 */     Document ownerDoc = DOMUtils.getOwnerDocument(parent);
/*     */ 
/*  99 */     Element propsElem = DOMUtils.createElement(ownerDoc, "SignatureProperties", "http://www.w3.org/2000/09/xmldsig#", dsPrefix);
/*     */ 
/* 103 */     DOMUtils.setAttributeID(propsElem, "Id", this.id);
/*     */ 
/* 106 */     int i = 0; for (int size = this.properties.size(); i < size; i++) {
/* 107 */       DOMSignatureProperty property = (DOMSignatureProperty)this.properties.get(i);
/*     */ 
/* 109 */       property.marshal(propsElem, dsPrefix, context);
/*     */     }
/*     */ 
/* 112 */     parent.appendChild(propsElem);
/*     */   }
/*     */ 
/*     */   public boolean equals(Object o) {
/* 116 */     if (this == o) {
/* 117 */       return true;
/*     */     }
/*     */ 
/* 120 */     if (!(o instanceof SignatureProperties)) {
/* 121 */       return false;
/*     */     }
/* 123 */     SignatureProperties osp = (SignatureProperties)o;
/*     */ 
/* 125 */     boolean idsEqual = this.id == null ? false : osp.getId() == null ? true : this.id.equals(osp.getId());
/*     */ 
/* 128 */     return (this.properties.equals(osp.getProperties())) && (idsEqual);
/*     */   }
/*     */ }

/* Location:           E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
 * Qualified Name:     org.jcp.xml.dsig.internal.dom.DOMSignatureProperties
 * JD-Core Version:    0.6.2
 */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy