1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. */ /* * $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $ */ package javax.xml.crypto.dsig.spec; import java.util.Collections; import java.util.Iterator; import java.util.HashMap; import java.util.Map; /** * The XML Schema Definition of the <code>XPath</code> element as defined in the * <a href="http://www.w3.org/TR/xmldsig-filter2"> * W3C Recommendation for XML-Signature XPath Filter 2.0</a>: * <pre><code> * <schema xmlns="http://www.w3.org/2001/XMLSchema" * xmlns:xf="http://www.w3.org/2002/06/xmldsig-filter2" * targetNamespace="http://www.w3.org/2002/06/xmldsig-filter2" * version="0.1" elementFormDefault="qualified"> * * <element name="XPath" * type="xf:XPathType"/> * * <complexType name="XPathType"> * <simpleContent> * <extension base="string"> * <attribute name="Filter"> * <simpleType> * <restriction base="string"> * <enumeration value="intersect"/> * <enumeration value="subtract"/> * <enumeration value="union"/> * </restriction> * </simpleType> * </attribute> * </extension> * </simpleContent> * </complexType> * </code></pre> * * @author Sean Mullan * @author JSR 105 Expert Group * @since 1.6 * @see XPathFilter2ParameterSpec */ public class XPathType { /** * Represents the filter set operation. */ public static class Filter { private final String operation; private Filter(String operation) { this.operation = operation; } /** * Returns the string form of the operation. * * @return the string form of the operation */ public String toString() { return operation; } /** * The intersect filter operation. */ public static final Filter INTERSECT = new Filter("intersect"); /** * The subtract filter operation. */ public static final Filter SUBTRACT = new Filter("subtract"); /** * The union filter operation. */ public static final Filter UNION = new Filter("union"); } private final String expression; private final Filter filter; private Map nsMap; /** * Creates an <code>XPathType</code> instance with the specified XPath * expression and filter. * * @param expression the XPath expression to be evaluated * @param filter the filter operation ({@link Filter#INTERSECT}, * {@link Filter#SUBTRACT}, or {@link Filter#UNION}) * @throws NullPointerException if <code>expression</code> or * <code>filter</code> is <code>null</code> */ public XPathType(String expression, Filter filter) { if (expression == null) { throw new NullPointerException("expression cannot be null"); } if (filter == null) { throw new NullPointerException("filter cannot be null"); } this.expression = expression; this.filter = filter; this.nsMap = Collections.EMPTY_MAP; } /** * Creates an <code>XPathType</code> instance with the specified XPath * expression, filter, and namespace map. The map is copied to protect * against subsequent modification. * * @param expression the XPath expression to be evaluated * @param filter the filter operation ({@link Filter#INTERSECT}, * {@link Filter#SUBTRACT}, or {@link Filter#UNION}) * @param namespaceMap the map of namespace prefixes. Each key is a * namespace prefix <code>String</code> that maps to a corresponding * namespace URI <code>String</code>. * @throws NullPointerException if <code>expression</code>, * <code>filter</code> or <code>namespaceMap</code> are * <code>null</code> * @throws ClassCastException if any of the map's keys or entries are * not of type <code>String</code> */ public XPathType(String expression, Filter filter, Map namespaceMap) { this(expression, filter); if (namespaceMap == null) { throw new NullPointerException("namespaceMap cannot be null"); } nsMap = new HashMap(namespaceMap); Iterator entries = nsMap.entrySet().iterator(); while (entries.hasNext()) { Map.Entry me = (Map.Entry) entries.next(); if (!(me.getKey() instanceof String) || !(me.getValue() instanceof String)) { throw new ClassCastException("not a String"); } } nsMap = Collections.unmodifiableMap(nsMap); } /** * Returns the XPath expression to be evaluated. * * @return the XPath expression to be evaluated */ public String getExpression() { return expression; } /** * Returns the filter operation. * * @return the filter operation */ public Filter getFilter() { return filter; } /** * Returns a map of namespace prefixes. Each key is a namespace prefix * <code>String</code> that maps to a corresponding namespace URI * <code>String</code>. * <p> * This implementation returns an {@link Collections#unmodifiableMap * unmodifiable map}. * * @return a <code>Map</code> of namespace prefixes to namespace URIs * (may be empty, but never <code>null</code>) */ public Map getNamespaceMap() { return nsMap; } }