Showing the changes to java/pkg/javax/xml/crypto/dsig/spec/XPathType.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,199 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | /* | ||
| 26 | * $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $ | ||
| 27 | */ | ||
| 28 | package javax.xml.crypto.dsig.spec; | ||
| 29 | |||
| 30 | import java.util.Collections; | ||
| 31 | import java.util.Iterator; | ||
| 32 | import java.util.HashMap; | ||
| 33 | import java.util.Map; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * The XML Schema Definition of the <code>XPath</code> element as defined in the | ||
| 37 | * <a href="http://www.w3.org/TR/xmldsig-filter2"> | ||
| 38 | * W3C Recommendation for XML-Signature XPath Filter 2.0</a>: | ||
| 39 | * <pre><code> | ||
| 40 | * <schema xmlns="http://www.w3.org/2001/XMLSchema" | ||
| 41 | * xmlns:xf="http://www.w3.org/2002/06/xmldsig-filter2" | ||
| 42 | * targetNamespace="http://www.w3.org/2002/06/xmldsig-filter2" | ||
| 43 | * version="0.1" elementFormDefault="qualified"> | ||
| 44 | * | ||
| 45 | * <element name="XPath" | ||
| 46 | * type="xf:XPathType"/> | ||
| 47 | * | ||
| 48 | * <complexType name="XPathType"> | ||
| 49 | * <simpleContent> | ||
| 50 | * <extension base="string"> | ||
| 51 | * <attribute name="Filter"> | ||
| 52 | * <simpleType> | ||
| 53 | * <restriction base="string"> | ||
| 54 | * <enumeration value="intersect"/> | ||
| 55 | * <enumeration value="subtract"/> | ||
| 56 | * <enumeration value="union"/> | ||
| 57 | * </restriction> | ||
| 58 | * </simpleType> | ||
| 59 | * </attribute> | ||
| 60 | * </extension> | ||
| 61 | * </simpleContent> | ||
| 62 | * </complexType> | ||
| 63 | * </code></pre> | ||
| 64 | * | ||
| 65 | * @author Sean Mullan | ||
| 66 | * @author JSR 105 Expert Group | ||
| 67 | * @since 1.6 | ||
| 68 | * @see XPathFilter2ParameterSpec | ||
| 69 | */ | ||
| 70 | public class XPathType { | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Represents the filter set operation. | ||
| 74 | */ | ||
| 75 | public static class Filter { | ||
| 76 | private final String operation; | ||
| 77 | |||
| 78 | private Filter(String operation) { | ||
| 79 | this.operation = operation; | ||
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Returns the string form of the operation. | ||
| 84 | * | ||
| 85 | * @return the string form of the operation | ||
| 86 | */ | ||
| 87 | public String toString() { | ||
| 88 | return operation; | ||
| 89 | } | ||
| 90 | |||
| 91 | /** | ||
| 92 | * The intersect filter operation. | ||
| 93 | */ | ||
| 94 | public static final Filter INTERSECT = new Filter("intersect"); | ||
| 95 | |||
| 96 | /** | ||
| 97 | * The subtract filter operation. | ||
| 98 | */ | ||
| 99 | public static final Filter SUBTRACT = new Filter("subtract"); | ||
| 100 | |||
| 101 | /** | ||
| 102 | * The union filter operation. | ||
| 103 | */ | ||
| 104 | public static final Filter UNION = new Filter("union"); | ||
| 105 | } | ||
| 106 | |||
| 107 | private final String expression; | ||
| 108 | private final Filter filter; | ||
| 109 | private Map nsMap; | ||
| 110 | |||
| 111 | /** | ||
| 112 | * Creates an <code>XPathType</code> instance with the specified XPath | ||
| 113 | * expression and filter. | ||
| 114 | * | ||
| 115 | * @param expression the XPath expression to be evaluated | ||
| 116 | * @param filter the filter operation ({@link Filter#INTERSECT}, | ||
| 117 | * {@link Filter#SUBTRACT}, or {@link Filter#UNION}) | ||
| 118 | * @throws NullPointerException if <code>expression</code> or | ||
| 119 | * <code>filter</code> is <code>null</code> | ||
| 120 | */ | ||
| 121 | public XPathType(String expression, Filter filter) { | ||
| 122 | if (expression == null) { | ||
| 123 | throw new NullPointerException("expression cannot be null"); | ||
| 124 | } | ||
| 125 | if (filter == null) { | ||
| 126 | throw new NullPointerException("filter cannot be null"); | ||
| 127 | } | ||
| 128 | this.expression = expression; | ||
| 129 | this.filter = filter; | ||
| 130 | this.nsMap = Collections.EMPTY_MAP; | ||
| 131 | } | ||
| 132 | |||
| 133 | /** | ||
| 134 | * Creates an <code>XPathType</code> instance with the specified XPath | ||
| 135 | * expression, filter, and namespace map. The map is copied to protect | ||
| 136 | * against subsequent modification. | ||
| 137 | * | ||
| 138 | * @param expression the XPath expression to be evaluated | ||
| 139 | * @param filter the filter operation ({@link Filter#INTERSECT}, | ||
| 140 | * {@link Filter#SUBTRACT}, or {@link Filter#UNION}) | ||
| 141 | * @param namespaceMap the map of namespace prefixes. Each key is a | ||
| 142 | * namespace prefix <code>String</code> that maps to a corresponding | ||
| 143 | * namespace URI <code>String</code>. | ||
| 144 | * @throws NullPointerException if <code>expression</code>, | ||
| 145 | * <code>filter</code> or <code>namespaceMap</code> are | ||
| 146 | * <code>null</code> | ||
| 147 | * @throws ClassCastException if any of the map's keys or entries are | ||
| 148 | * not of type <code>String</code> | ||
| 149 | */ | ||
| 150 | public XPathType(String expression, Filter filter, Map namespaceMap) { | ||
| 151 | this(expression, filter); | ||
| 152 | if (namespaceMap == null) { | ||
| 153 | throw new NullPointerException("namespaceMap cannot be null"); | ||
| 154 | } | ||
| 155 | nsMap = new HashMap(namespaceMap); | ||
| 156 | Iterator entries = nsMap.entrySet().iterator(); | ||
| 157 | while (entries.hasNext()) { | ||
| 158 | Map.Entry me = (Map.Entry) entries.next(); | ||
| 159 | if (!(me.getKey() instanceof String) || | ||
| 160 | !(me.getValue() instanceof String)) { | ||
| 161 | throw new ClassCastException("not a String"); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | nsMap = Collections.unmodifiableMap(nsMap); | ||
| 165 | } | ||
| 166 | |||
| 167 | /** | ||
| 168 | * Returns the XPath expression to be evaluated. | ||
| 169 | * | ||
| 170 | * @return the XPath expression to be evaluated | ||
| 171 | */ | ||
| 172 | public String getExpression() { | ||
| 173 | return expression; | ||
| 174 | } | ||
| 175 | |||
| 176 | /** | ||
| 177 | * Returns the filter operation. | ||
| 178 | * | ||
| 179 | * @return the filter operation | ||
| 180 | */ | ||
| 181 | public Filter getFilter() { | ||
| 182 | return filter; | ||
| 183 | } | ||
| 184 | |||
| 185 | /** | ||
| 186 | * Returns a map of namespace prefixes. Each key is a namespace prefix | ||
| 187 | * <code>String</code> that maps to a corresponding namespace URI | ||
| 188 | * <code>String</code>. | ||
| 189 | * <p> | ||
| 190 | * This implementation returns an {@link Collections#unmodifiableMap | ||
| 191 | * unmodifiable map}. | ||
| 192 | * | ||
| 193 | * @return a <code>Map</code> of namespace prefixes to namespace URIs | ||
| 194 | * (may be empty, but never <code>null</code>) | ||
| 195 | */ | ||
| 196 | public Map getNamespaceMap() { | ||
| 197 | return nsMap; | ||
| 198 | } | ||
| 199 | } | ||