API Overview API Index Package Overview Direct link to this page
JDK 1.6
  org.jcp.xml.dsig.internal.dom. DOMSignatureProperties View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

/*
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 */
/*
 * $Id: DOMSignatureProperties.java,v 1.12 2005/05/12 19:28:32 mullan Exp $
 */
package org.jcp.xml.dsig.internal.dom;

import javax.xml.crypto.*;
import javax.xml.crypto.dom.DOMCryptoContext;
import javax.xml.crypto.dsig.*;

import java.util.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * DOM-based implementation of SignatureProperties.
 *
 * @author Sean Mullan
 */
public final class DOMSignatureProperties extends DOMStructure 
    implements SignatureProperties {
 
    private final String id;
    private final List properties;

    /**
     * Creates a <code>DOMSignatureProperties</code> from the specified 
     * parameters.
     *
     * @param properties a list of one or more {@link SignatureProperty}s. The 
     *    list is defensively copied to protect against subsequent modification.
     * @param id the Id (may be <code>null</code>)
     * @return a <code>DOMSignatureProperties</code>
     * @throws ClassCastException if <code>properties</code> contains any
     *    entries that are not of type {@link SignatureProperty}
     * @throws IllegalArgumentException if <code>properties</code> is empty
     * @throws NullPointerException if <code>properties</code>
     */
    public DOMSignatureProperties(List properties, String id) {
	if (properties == null) {
	    throw new NullPointerException("properties cannot be null");
	} else if (properties.isEmpty()) {
	    throw new IllegalArgumentException("properties cannot be empty");
        } else {
            List propsCopy = new ArrayList(properties);
            for (int i = 0, size = propsCopy.size(); i < size; i++) {
                if (!(propsCopy.get(i) instanceof SignatureProperty)) {
                    throw new ClassCastException
                        ("properties["+i+"] is not a valid type");
                }
            }
            this.properties = Collections.unmodifiableList(propsCopy);
        }
	this.id = id;
    }

    /**
     * Creates a <code>DOMSignatureProperties</code> from an element.
     *
     * @param propsElem a SignatureProperties element
     * @throws MarshalException if a marshalling error occurs
     */
    public DOMSignatureProperties(Element propsElem) throws MarshalException{
	// unmarshal attributes
        id = DOMUtils.getAttributeValue(propsElem, "Id");

	NodeList nodes = propsElem.getChildNodes();
	int length = nodes.getLength();
	List properties = new ArrayList(length);
	for (int i = 0; i < length; i++) {
	    Node child = nodes.item(i);
	    if (child.getNodeType() == Node.ELEMENT_NODE) {
	        properties.add(new DOMSignatureProperty((Element) child));
	    }
	}
        if (properties.isEmpty()) {
	    throw new MarshalException("properties cannot be empty");
        } else {
            this.properties = Collections.unmodifiableList(properties);
        }
    }

    public List getProperties() {
        return properties;
    }

    public String getId() {
        return id;
    }

    public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
	throws MarshalException {
        Document ownerDoc = DOMUtils.getOwnerDocument(parent);

        Element propsElem = DOMUtils.createElement
            (ownerDoc, "SignatureProperties", XMLSignature.XMLNS, dsPrefix);

	// set attributes
        DOMUtils.setAttributeID(propsElem, "Id", id);

        // create and append any properties
	for (int i = 0, size = properties.size(); i < size; i++) {
	    DOMSignatureProperty property = 
		(DOMSignatureProperty) properties.get(i);
	    property.marshal(propsElem, dsPrefix, context);
        }
	    
	parent.appendChild(propsElem);
    }

    public boolean equals(Object o) {
	if (this == o) {
            return true;
	}

        if (!(o instanceof SignatureProperties)) {
            return false;
	}
        SignatureProperties osp = (SignatureProperties) o;

	boolean idsEqual = (id == null ? osp.getId() == null :
            id.equals(osp.getId()));

	return (properties.equals(osp.getProperties()) && idsEqual);
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar