jdk/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLObject.java
author mullan
Fri, 21 Nov 2014 15:23:36 -0500
changeset 27747 3a271dc8b758
parent 25859 3317bb8137f4
child 32003 acb12269398a
permissions -rw-r--r--
8046949: Generify the javax.xml.crypto API Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     2
 * reserved comment block
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    11
 * "License"); you may not use this file except in compliance
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    12
 * with the License. You may obtain a copy of the License at
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    17
 * software distributed under the License is distributed on an
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    19
 * KIND, either express or implied. See the License for the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    21
 * under the License.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    22
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    23
/*
24970
094bfaa699c3 8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents: 23010
diff changeset
    24
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    25
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    26
/*
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    27
 * $Id: DOMXMLObject.java 1333415 2012-05-03 12:03:51Z coheigea $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.xml.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.xml.crypto.dom.DOMCryptoContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.xml.crypto.dsig.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    35
import java.security.Provider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    37
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
    38
import org.w3c.dom.Attr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * DOM-based implementation of XMLObject.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public final class DOMXMLObject extends DOMStructure implements XMLObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final String mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final String encoding;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    54
    private final List<XMLStructure> content;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    55
    private Element objectElem;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Creates an <code>XMLObject</code> from the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param content a list of {@link XMLStructure}s. The list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *    is defensively copied to protect against subsequent modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *    May be <code>null</code> or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param id the Id (may be <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param mimeType the mime type (may be <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param encoding the encoding (may be <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @return an <code>XMLObject</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @throws ClassCastException if <code>content</code> contains any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *    entries that are not of type {@link XMLStructure}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    70
    public DOMXMLObject(List<? extends XMLStructure> content, String id,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    71
                        String mimeType, String encoding)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    72
    {
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    73
        List<XMLStructure> tempList =
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    74
            Collections.checkedList(new ArrayList<XMLStructure>(),
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    75
                                    XMLStructure.class);
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    76
        if (content != null) {
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    77
            tempList.addAll(content);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
    79
        this.content = Collections.unmodifiableList(tempList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        this.mimeType = mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this.encoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Creates an <code>XMLObject</code> from an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param objElem an Object element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @throws MarshalException if there is an error when unmarshalling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    91
    public DOMXMLObject(Element objElem, XMLCryptoContext context,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    92
                        Provider provider)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    93
    throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    94
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // unmarshal attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding");
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
    97
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
    98
        Attr attr = objElem.getAttributeNodeNS(null, "Id");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
    99
        if (attr != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   100
            this.id = attr.getValue();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   101
            objElem.setIdAttributeNode(attr, true);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   102
        } else {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   103
            this.id = null;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   104
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.mimeType = DOMUtils.getAttributeValue(objElem, "MimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        NodeList nodes = objElem.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int length = nodes.getLength();
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   109
        List<XMLStructure> content = new ArrayList<XMLStructure>(length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Node child = nodes.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (child.getNodeType() == Node.ELEMENT_NODE) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   113
                Element childElem = (Element)child;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                String tag = childElem.getLocalName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                if (tag.equals("Manifest")) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   116
                    content.add(new DOMManifest(childElem, context, provider));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                } else if (tag.equals("SignatureProperties")) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   119
                    content.add(new DOMSignatureProperties(childElem, context));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                } else if (tag.equals("X509Data")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    content.add(new DOMX509Data(childElem));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                //@@@FIXME: check for other dsig structures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            content.add(new javax.xml.crypto.dom.DOMStructure(child));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (content.isEmpty()) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   130
            this.content = Collections.emptyList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            this.content = Collections.unmodifiableList(content);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   134
        this.objectElem = objElem;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
24970
094bfaa699c3 8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents: 23010
diff changeset
   137
    public List<XMLStructure> getContent() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public String getId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public String getMimeType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public String getEncoding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Document ownerDoc = DOMUtils.getOwnerDocument(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   157
        Element objElem = objectElem != null ? objectElem : null;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   158
        if (objElem == null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   159
            objElem = DOMUtils.createElement(ownerDoc, "Object",
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   160
                                             XMLSignature.XMLNS, dsPrefix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   162
            // set attributes
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   163
            DOMUtils.setAttributeID(objElem, "Id", id);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   164
            DOMUtils.setAttribute(objElem, "MimeType", mimeType);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   165
            DOMUtils.setAttribute(objElem, "Encoding", encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   167
            // create and append any elements and mixed content, if necessary
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   168
            for (XMLStructure object : content) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   169
                if (object instanceof DOMStructure) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   170
                    ((DOMStructure)object).marshal(objElem, dsPrefix, context);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   171
                } else {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   172
                    javax.xml.crypto.dom.DOMStructure domObject =
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   173
                        (javax.xml.crypto.dom.DOMStructure)object;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   174
                    DOMUtils.appendChild(objElem, domObject.getNode());
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   175
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        parent.appendChild(objElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   182
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (this == o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (!(o instanceof XMLObject)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   191
        XMLObject oxo = (XMLObject)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   193
        boolean idsEqual = (id == null ? oxo.getId() == null
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   194
                                       : id.equals(oxo.getId()));
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   195
        boolean encodingsEqual =
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   196
            (encoding == null ? oxo.getEncoding() == null
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   197
                              : encoding.equals(oxo.getEncoding()));
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   198
        boolean mimeTypesEqual =
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   199
            (mimeType == null ? oxo.getMimeType() == null
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   200
                              : mimeType.equals(oxo.getMimeType()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   202
        List<XMLStructure> oxoContent = oxo.getContent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return (idsEqual && encodingsEqual && mimeTypesEqual &&
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   204
                equalsContent(oxoContent));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   207
    @Override
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   208
    public int hashCode() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   209
        int result = 17;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   210
        if (id != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   211
            result = 31 * result + id.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   212
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   213
        if (encoding != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   214
            result = 31 * result + encoding.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   215
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   216
        if (mimeType != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   217
            result = 31 * result + mimeType.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   218
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   219
        result = 31 * result + content.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   220
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   221
        return result;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   222
    }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   223
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   224
    private boolean equalsContent(List<XMLStructure> otherContent) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (content.size() != otherContent.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        for (int i = 0, osize = otherContent.size(); i < osize; i++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   229
            XMLStructure oxs = otherContent.get(i);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   230
            XMLStructure xs = content.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (oxs instanceof javax.xml.crypto.dom.DOMStructure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                if (!(xs instanceof javax.xml.crypto.dom.DOMStructure)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   235
                Node onode = ((javax.xml.crypto.dom.DOMStructure)oxs).getNode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   236
                Node node = ((javax.xml.crypto.dom.DOMStructure)xs).getNode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if (!DOMUtils.nodesEqual(node, onode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                if (!(xs.equals(oxs))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}