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

org.jcp.xml.dsig.internal.dom.DOMManifest 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.XMLCryptoContext;
/*     */ import javax.xml.crypto.dom.DOMCryptoContext;
/*     */ import javax.xml.crypto.dsig.Manifest;
/*     */ import javax.xml.crypto.dsig.Reference;
/*     */ import org.w3c.dom.Document;
/*     */ import org.w3c.dom.Element;
/*     */ import org.w3c.dom.Node;
/*     */ 
/*     */ public final class DOMManifest extends DOMStructure
/*     */   implements Manifest
/*     */ {
/*     */   private final List references;
/*     */   private final String id;
/*     */ 
/*     */   public DOMManifest(List references, String id)
/*     */   {
/*  42 */     if (references == null) {
/*  43 */       throw new NullPointerException("references cannot be null");
/*     */     }
/*  45 */     List refCopy = new ArrayList(references);
/*  46 */     if (refCopy.isEmpty()) {
/*  47 */       throw new IllegalArgumentException("list of references must contain at least one entry");
/*     */     }
/*     */ 
/*  50 */     int i = 0; for (int size = refCopy.size(); i < size; i++) {
/*  51 */       if (!(refCopy.get(i) instanceof Reference)) {
/*  52 */         throw new ClassCastException("references[" + i + "] is not a valid type");
/*     */       }
/*     */     }
/*     */ 
/*  56 */     this.references = Collections.unmodifiableList(refCopy);
/*  57 */     this.id = id;
/*     */   }
/*     */ 
/*     */   public DOMManifest(Element manElem, XMLCryptoContext context)
/*     */     throws MarshalException
/*     */   {
/*  67 */     this.id = DOMUtils.getAttributeValue(manElem, "Id");
/*  68 */     Element refElem = DOMUtils.getFirstChildElement(manElem);
/*  69 */     List refs = new ArrayList();
/*  70 */     while (refElem != null) {
/*  71 */       refs.add(new DOMReference(refElem, context));
/*  72 */       refElem = DOMUtils.getNextSiblingElement(refElem);
/*     */     }
/*  74 */     this.references = Collections.unmodifiableList(refs);
/*     */   }
/*     */ 
/*     */   public String getId() {
/*  78 */     return this.id;
/*     */   }
/*     */ 
/*     */   public List getReferences() {
/*  82 */     return this.references;
/*     */   }
/*     */ 
/*     */   public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) throws MarshalException
/*     */   {
/*  87 */     Document ownerDoc = DOMUtils.getOwnerDocument(parent);
/*     */ 
/*  89 */     Element manElem = DOMUtils.createElement(ownerDoc, "Manifest", "http://www.w3.org/2000/09/xmldsig#", dsPrefix);
/*     */ 
/*  92 */     DOMUtils.setAttributeID(manElem, "Id", this.id);
/*     */ 
/*  95 */     int i = 0; for (int size = this.references.size(); i < size; i++) {
/*  96 */       DOMReference ref = (DOMReference)this.references.get(i);
/*  97 */       ref.marshal(manElem, dsPrefix, context);
/*     */     }
/*  99 */     parent.appendChild(manElem);
/*     */   }
/*     */ 
/*     */   public boolean equals(Object o) {
/* 103 */     if (this == o) {
/* 104 */       return true;
/*     */     }
/*     */ 
/* 107 */     if (!(o instanceof Manifest)) {
/* 108 */       return false;
/*     */     }
/* 110 */     Manifest oman = (Manifest)o;
/*     */ 
/* 112 */     boolean idsEqual = this.id == null ? false : oman.getId() == null ? true : this.id.equals(oman.getId());
/*     */ 
/* 115 */     return (idsEqual) && (this.references.equals(oman.getReferences()));
/*     */   }
/*     */ }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy