KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > crypto > dsig > spec > XPathFilterParameterSpec


1 /*
2  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3  */

4 /*
5  * $Id: XPathFilterParameterSpec.java,v 1.4 2005/05/10 16:40:17 mullan Exp $
6  */

7 package javax.xml.crypto.dsig.spec;
8
9 import javax.xml.crypto.dsig.Transform;
10 import java.util.Collections JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.Map.Entry;
15
16 /**
17  * Parameters for the <a HREF="http://www.w3.org/TR/xmldsig-core/#sec-XPath">
18  * XPath Filtering Transform Algorithm</a>.
19  * The parameters include the XPath expression and an optional <code>Map</code>
20  * of additional namespace prefix mappings. The XML Schema Definition of
21  * the XPath Filtering transform parameters is defined as:
22  * <pre><code>
23  * &lt;element name="XPath" type="string"/&gt;
24  * </code></pre>
25  *
26  * @author Sean Mullan
27  * @author JSR 105 Expert Group
28  * @since 1.6
29  * @see Transform
30  */

31 public final class XPathFilterParameterSpec implements TransformParameterSpec {
32
33     private String JavaDoc xPath;
34     private Map JavaDoc nsMap;
35
36     /**
37      * Creates an <code>XPathFilterParameterSpec</code> with the specified
38      * XPath expression.
39      *
40      * @param xPath the XPath expression to be evaluated
41      * @throws NullPointerException if <code>xPath</code> is <code>null</code>
42      */

43     public XPathFilterParameterSpec(String JavaDoc xPath) {
44     if (xPath == null) {
45         throw new NullPointerException JavaDoc();
46     }
47     this.xPath = xPath;
48     this.nsMap = Collections.EMPTY_MAP;
49     }
50
51     /**
52      * Creates an <code>XPathFilterParameterSpec</code> with the specified
53      * XPath expression and namespace map. The map is copied to protect against
54      * subsequent modification.
55      *
56      * @param xPath the XPath expression to be evaluated
57      * @param namespaceMap the map of namespace prefixes. Each key is a
58      * namespace prefix <code>String</code> that maps to a corresponding
59      * namespace URI <code>String</code>.
60      * @throws NullPointerException if <code>xPath</code> or
61      * <code>namespaceMap</code> are <code>null</code>
62      * @throws ClassCastException if any of the map's keys or entries are not
63      * of type <code>String</code>
64      */

65     public XPathFilterParameterSpec(String JavaDoc xPath, Map JavaDoc namespaceMap) {
66         if (xPath == null || namespaceMap == null) {
67             throw new NullPointerException JavaDoc();
68         }
69         this.xPath = xPath;
70     nsMap = new HashMap JavaDoc(namespaceMap);
71     Iterator JavaDoc entries = nsMap.entrySet().iterator();
72     while (entries.hasNext()) {
73         Map.Entry JavaDoc me = (Map.Entry JavaDoc) entries.next();
74         if (!(me.getKey() instanceof String JavaDoc) ||
75         !(me.getValue() instanceof String JavaDoc)) {
76         throw new ClassCastException JavaDoc("not a String");
77         }
78     }
79     nsMap = Collections.unmodifiableMap(nsMap);
80     }
81
82     /**
83      * Returns the XPath expression to be evaluated.
84      *
85      * @return the XPath expression to be evaluated
86      */

87     public String JavaDoc getXPath() {
88     return xPath;
89     }
90
91     /**
92      * Returns a map of namespace prefixes. Each key is a namespace prefix
93      * <code>String</code> that maps to a corresponding namespace URI
94      * <code>String</code>.
95      * <p>
96      * This implementation returns an {@link Collections#unmodifiableMap
97      * unmodifiable map}.
98      *
99      * @return a <code>Map</code> of namespace prefixes to namespace URIs (may
100      * be empty, but never <code>null</code>)
101      */

102     public Map JavaDoc getNamespaceMap() {
103     return nsMap;
104     }
105 }
106
Popular Tags