jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/spec/XPathType.java
author mullan
Fri, 21 Nov 2014 15:23:36 -0500
changeset 27747 3a271dc8b758
parent 25859 3317bb8137f4
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
/*
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package javax.xml.crypto.dsig.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The XML Schema Definition of the <code>XPath</code> element as defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <a href="http://www.w3.org/TR/xmldsig-filter2">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * W3C Recommendation for XML-Signature XPath Filter 2.0</a>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * &lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *         xmlns:xf="http://www.w3.org/2002/06/xmldsig-filter2"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *         targetNamespace="http://www.w3.org/2002/06/xmldsig-filter2"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *         version="0.1" elementFormDefault="qualified"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * &lt;element name="XPath"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *          type="xf:XPathType"/&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * &lt;complexType name="XPathType"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   &lt;simpleContent&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     &lt;extension base="string"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       &lt;attribute name="Filter"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *         &lt;simpleType&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *           &lt;restriction base="string"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *             &lt;enumeration value="intersect"/&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *             &lt;enumeration value="subtract"/&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *             &lt;enumeration value="union"/&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *           &lt;/restriction&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *         &lt;/simpleType&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *       &lt;/attribute&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     &lt;/extension&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   &lt;/simpleContent&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * &lt;/complexType&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author JSR 105 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see XPathFilter2ParameterSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public class XPathType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Represents the filter set operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static class Filter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        private final String operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        private Filter(String operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            this.operation = operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * Returns the string form of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * @return the string form of the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            return operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * The intersect filter operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        public static final Filter INTERSECT = new Filter("intersect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * The subtract filter operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        public static final Filter SUBTRACT = new Filter("subtract");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * The union filter operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        public static final Filter UNION = new Filter("union");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private final String expression;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private final Filter filter;
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   108
    private final Map<String,String> nsMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Creates an <code>XPathType</code> instance with the specified XPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * expression and filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param expression the XPath expression to be evaluated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param filter the filter operation ({@link Filter#INTERSECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *    {@link Filter#SUBTRACT}, or {@link Filter#UNION})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @throws NullPointerException if <code>expression</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *    <code>filter</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public XPathType(String expression, Filter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (expression == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new NullPointerException("expression cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (filter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new NullPointerException("filter cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.expression = expression;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.filter = filter;
11276
6a7de6dddc18 7118546: fix warnings in javax.xml.crypto, javax.script
smarks
parents: 5506
diff changeset
   129
        this.nsMap = Collections.emptyMap();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Creates an <code>XPathType</code> instance with the specified XPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * expression, filter, and namespace map. The map is copied to protect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * against subsequent modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param expression the XPath expression to be evaluated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param filter the filter operation ({@link Filter#INTERSECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *    {@link Filter#SUBTRACT}, or {@link Filter#UNION})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param namespaceMap the map of namespace prefixes. Each key is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *    namespace prefix <code>String</code> that maps to a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *    namespace URI <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @throws NullPointerException if <code>expression</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *    <code>filter</code> or <code>namespaceMap</code> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @throws ClassCastException if any of the map's keys or entries are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *    not of type <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   149
    public XPathType(String expression, Filter filter,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   150
        Map<String,String> namespaceMap) {
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   151
        if (expression == null) {
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   152
            throw new NullPointerException("expression cannot be null");
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   153
        }
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   154
        if (filter == null) {
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   155
            throw new NullPointerException("filter cannot be null");
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   156
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (namespaceMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new NullPointerException("namespaceMap cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   160
        this.expression = expression;
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   161
        this.filter = filter;
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   162
        Map<String,String> tempMap = Collections.checkedMap(new HashMap<>(),
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   163
                                                            String.class,
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   164
                                                            String.class);
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   165
        tempMap.putAll(namespaceMap);
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   166
        this.nsMap = Collections.unmodifiableMap(tempMap);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns the XPath expression to be evaluated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the XPath expression to be evaluated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public String getExpression() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return expression;
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
     * Returns the filter operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return the filter operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public Filter getFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Returns a map of namespace prefixes. Each key is a namespace prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <code>String</code> that maps to a corresponding namespace URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * This implementation returns an {@link Collections#unmodifiableMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * unmodifiable map}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return a <code>Map</code> of namespace prefixes to namespace URIs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *    (may be empty, but never <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
27747
3a271dc8b758 8046949: Generify the javax.xml.crypto API
mullan
parents: 25859
diff changeset
   198
    public Map<String,String> getNamespaceMap() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return nsMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}