alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (XPathType.java)

This example Java source code file (XPathType.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

classcastexception, filter, hashmap, intersect, iterator, map, nullpointerexception, string, subtract, suppresswarnings, union, util, xpathtype

The XPathType.java Java example source code

/*
 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
/*
 * $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 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>
 * <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>
* * @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<String,String> nsMap; /** * Creates an <code>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 <code>expression or * <code>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.emptyMap(); } /** * Creates an <code>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 <code>String that maps to a corresponding * namespace URI <code>String. * @throws NullPointerException if <code>expression, * <code>filter or namespaceMap are * <code>null * @throws ClassCastException if any of the map's keys or entries are * not of type <code>String */ @SuppressWarnings("rawtypes") public XPathType(String expression, Filter filter, Map namespaceMap) { this(expression, filter); if (namespaceMap == null) { throw new NullPointerException("namespaceMap cannot be null"); } Map<?,?> copy = new HashMap<>((Map)namespaceMap); Iterator<? extends Map.Entry entries = copy.entrySet().iterator(); while (entries.hasNext()) { Map.Entry<?,?> me = entries.next(); if (!(me.getKey() instanceof String) || !(me.getValue() instanceof String)) { throw new ClassCastException("not a String"); } } @SuppressWarnings("unchecked") Map<String,String> temp = (Map)copy; nsMap = Collections.unmodifiableMap(temp); } /** * 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 that maps to a corresponding namespace URI * <code>String. * <p> * This implementation returns an {@link Collections#unmodifiableMap * unmodifiable map}. * * @return a <code>Map of namespace prefixes to namespace URIs * (may be empty, but never <code>null) */ @SuppressWarnings("rawtypes") public Map getNamespaceMap() { return nsMap; } }

Other Java examples (source code examples)

Here is a short list of links related to this Java XPathType.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.