All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.xml.crypto.dsig.spec.XPathType Maven / Gradle / Ivy

Go to download

Apache XML Security for Java supports XML-Signature Syntax and Processing, W3C Recommendation 12 February 2002, and XML Encryption Syntax and Processing, W3C Recommendation 10 December 2002. As of version 1.4, the library supports the standard Java API JSR-105: XML Digital Signature APIs.

There is a newer version: 4.0.2
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
/*
 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
 */
/*
 * $Id: XPathType.java 1203720 2011-11-18 16:23:54Z mullan $
 */
package javax.xml.crypto.dsig.spec;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * The XML Schema Definition of the XPath element as defined in the
 * 
 * W3C Recommendation for XML-Signature XPath Filter 2.0:
 * 

 * <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>
 * 
* * @author Sean Mullan * @author JSR 105 Expert Group * @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 XPathType 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 expression or * filter is null */ 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 XPathType 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 String that maps to a corresponding * namespace URI String. * @throws NullPointerException if expression, * filter or namespaceMap are * null * @throws ClassCastException if any of the map's keys or entries are * not of type String */ public XPathType(String expression, Filter filter, Map namespaceMap) { this(expression, filter); if (namespaceMap == null) { throw new NullPointerException("namespaceMap cannot be null"); } nsMap = unmodifiableCopyOfMap(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"); } } } @SuppressWarnings("unchecked") private static Map unmodifiableCopyOfMap(Map map) { return Collections.unmodifiableMap(new HashMap(map)); } /** * 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 * String that maps to a corresponding namespace URI * String. *

* This implementation returns an {@link Collections#unmodifiableMap * unmodifiable map}. * * @return a Map of namespace prefixes to namespace URIs * (may be empty, but never null) */ public Map getNamespaceMap() { return nsMap; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy