--- old/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMSignatureProperties.java 2013-06-28 11:34:56.531846251 -0400 +++ new/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMSignatureProperties.java 2013-06-28 11:34:56.359851605 -0400 @@ -2,27 +2,29 @@ * reserved comment block * DO NOT REMOVE OR ALTER! */ -/* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ /* * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. */ /* - * $Id: DOMSignatureProperties.java,v 1.2 2008/07/24 15:20:32 mullan Exp $ + * $Id: DOMSignatureProperties.java 1333415 2012-05-03 12:03:51Z coheigea $ */ package org.jcp.xml.dsig.internal.dom; @@ -31,6 +33,7 @@ import javax.xml.crypto.dsig.*; import java.util.*; + import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -42,17 +45,17 @@ * * @author Sean Mullan */ -public final class DOMSignatureProperties extends DOMStructure +public final class DOMSignatureProperties extends DOMStructure implements SignatureProperties { - + private final String id; - private final List properties; + private final List properties; /** - * Creates a DOMSignatureProperties from the specified + * Creates a DOMSignatureProperties from the specified * parameters. * - * @param properties a list of one or more {@link SignatureProperty}s. The + * @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 null) * @return a DOMSignatureProperties @@ -61,20 +64,22 @@ * @throws IllegalArgumentException if properties is empty * @throws NullPointerException if properties */ - public DOMSignatureProperties(List properties, String id) { + 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)) { + this.properties = Collections.unmodifiableList( + new ArrayList(properties)); + for (int i = 0, size = this.properties.size(); i < size; i++) { + if (!(this.properties.get(i) instanceof SignatureProperty)) { throw new ClassCastException ("properties["+i+"] is not a valid type"); } } - this.properties = Collections.unmodifiableList(propsCopy); } this.id = id; } @@ -85,7 +90,9 @@ * @param propsElem a SignatureProperties element * @throws MarshalException if a marshalling error occurs */ - public DOMSignatureProperties(Element propsElem) throws MarshalException{ + public DOMSignatureProperties(Element propsElem, XMLCryptoContext context) + throws MarshalException + { // unmarshal attributes Attr attr = propsElem.getAttributeNodeNS(null, "Id"); if (attr != null) { @@ -97,11 +104,13 @@ NodeList nodes = propsElem.getChildNodes(); int length = nodes.getLength(); - List properties = new ArrayList(length); + 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)); + properties.add(new DOMSignatureProperty((Element)child, + context)); } } if (properties.isEmpty()) { @@ -120,25 +129,27 @@ } public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) - throws MarshalException { + throws MarshalException + { Document ownerDoc = DOMUtils.getOwnerDocument(parent); - - Element propsElem = DOMUtils.createElement - (ownerDoc, "SignatureProperties", XMLSignature.XMLNS, dsPrefix); + 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); + for (SignatureProperty property : properties) { + ((DOMSignatureProperty)property).marshal(propsElem, dsPrefix, + context); } - + parent.appendChild(propsElem); } + @Override public boolean equals(Object o) { if (this == o) { return true; @@ -147,11 +158,22 @@ if (!(o instanceof SignatureProperties)) { return false; } - SignatureProperties osp = (SignatureProperties) o; + SignatureProperties osp = (SignatureProperties)o; - boolean idsEqual = (id == null ? osp.getId() == null : - id.equals(osp.getId())); + boolean idsEqual = (id == null ? osp.getId() == null + : id.equals(osp.getId())); return (properties.equals(osp.getProperties()) && idsEqual); } + + @Override + public int hashCode() { + int result = 17; + if (id != null) { + result = 31 * result + id.hashCode(); + } + result = 31 * result + properties.hashCode(); + + return result; + } }