jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMRetrievalMethod.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1337 e8d6cef36199
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Portions Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * (C) Copyright IBM Corp. 2003 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * $Id: DOMRetrievalMethod.java,v 1.24 2005/05/12 19:28:32 mullan Exp $
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.xml.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.xml.crypto.dsig.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.xml.crypto.dom.DOMCryptoContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.xml.crypto.dom.DOMURIReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.xml.crypto.dsig.keyinfo.RetrievalMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.xml.parsers.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * DOM-based implementation of RetrievalMethod.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Joyce Leung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public final class DOMRetrievalMethod extends DOMStructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    implements RetrievalMethod, DOMURIReference {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final List transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private String uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private Attr here;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Creates a <code>DOMRetrievalMethod</code> containing the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * URIReference and List of Transforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param uri the URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param type the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param transforms a list of {@link Transform}s. The list is defensively
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *    copied to prevent subsequent modification. May be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *    or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @throws IllegalArgumentException if the format of <code>uri</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *    invalid, as specified by Reference's URI attribute in the W3C
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *    specification for XML-Signature Syntax and Processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @throws NullPointerException if <code>uriReference</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *    is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @throws ClassCastException if <code>transforms</code> contains any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *    entries that are not of type {@link Transform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public DOMRetrievalMethod(String uri, String type, List transforms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (uri == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new NullPointerException("uri cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (transforms == null || transforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            this.transforms = Collections.EMPTY_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            List transformsCopy = new ArrayList(transforms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            for (int i = 0, size = transformsCopy.size(); i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                if (!(transformsCopy.get(i) instanceof Transform)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    throw new ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        ("transforms["+i+"] is not a valid type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            this.transforms = Collections.unmodifiableList(transformsCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.uri = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if ((uri != null) && (!uri.equals(""))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                new URI(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                throw new IllegalArgumentException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Creates a <code>DOMRetrievalMethod</code> from an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param rmElem a RetrievalMethod element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public DOMRetrievalMethod(Element rmElem, XMLCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // get URI and Type attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        uri = DOMUtils.getAttributeValue(rmElem, "URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        type = DOMUtils.getAttributeValue(rmElem, "Type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // get here node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        here = rmElem.getAttributeNodeNS(null, "URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // get Transforms, if specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        List transforms = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Element transformsElem = DOMUtils.getFirstChildElement(rmElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (transformsElem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            Element transformElem =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                DOMUtils.getFirstChildElement(transformsElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            while (transformElem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                transforms.add(new DOMTransform(transformElem, context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                transformElem = DOMUtils.getNextSiblingElement(transformElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (transforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            this.transforms = Collections.EMPTY_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            this.transforms = Collections.unmodifiableList(transforms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public String getURI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public List getTransforms() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Document ownerDoc = DOMUtils.getOwnerDocument(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        Element rmElem = DOMUtils.createElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            (ownerDoc, "RetrievalMethod", XMLSignature.XMLNS, dsPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // add URI and Type attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        DOMUtils.setAttribute(rmElem, "URI", uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        DOMUtils.setAttribute(rmElem, "Type", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // add Transforms elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (!transforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            Element transformsElem = DOMUtils.createElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                (ownerDoc, "Transforms", XMLSignature.XMLNS, dsPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            rmElem.appendChild(transformsElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            for (int i = 0, size = transforms.size(); i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                ((DOMTransform) transforms.get(i)).marshal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    (transformsElem, dsPrefix, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        parent.appendChild(rmElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // save here node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        here = rmElem.getAttributeNodeNS(null, "URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public Node getHere() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return here;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public Data dereference(XMLCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        throws URIReferenceException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new NullPointerException("context cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * If URIDereferencer is specified in context; use it, otherwise use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * built-in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        URIDereferencer deref = context.getURIDereferencer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (deref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            deref = DOMURIDereferencer.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        Data data = deref.dereference(this, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // pass dereferenced data through Transforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            for (int i = 0, size = transforms.size(); i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                Transform transform = (Transform) transforms.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                data = ((DOMTransform) transform).transform(data, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new URIReferenceException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public XMLStructure dereferenceAsXMLStructure(XMLCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        throws URIReferenceException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            ApacheData data = (ApacheData) dereference(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            dbf.setNamespaceAware(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            DocumentBuilder db = dbf.newDocumentBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            Document doc = db.parse(new ByteArrayInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                (data.getXMLSignatureInput().getBytes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Element kiElem = doc.getDocumentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (kiElem.getLocalName().equals("X509Data")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                return new DOMX509Data(kiElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                return null; // unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            throw new URIReferenceException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!(obj instanceof RetrievalMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        RetrievalMethod orm = (RetrievalMethod) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        boolean typesEqual = (type == null ? orm.getType() == null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            type.equals(orm.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return (uri.equals(orm.getURI()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            transforms.equals(orm.getTransforms()) && typesEqual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}