KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

7 package javax.xml.crypto.dsig.spec;
8
9 import java.util.Collections JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13
14 /**
15  * The XML Schema Definition of the <code>XPath</code> element as defined in the
16  * <a HREF="http://www.w3.org/TR/xmldsig-filter2">
17  * W3C Recommendation for XML-Signature XPath Filter 2.0</a>:
18  * <pre><code>
19  * &lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
20  * xmlns:xf="http://www.w3.org/2002/06/xmldsig-filter2"
21  * targetNamespace="http://www.w3.org/2002/06/xmldsig-filter2"
22  * version="0.1" elementFormDefault="qualified"&gt;
23  *
24  * &lt;element name="XPath"
25  * type="xf:XPathType"/&gt;
26  *
27  * &lt;complexType name="XPathType"&gt;
28  * &lt;simpleContent&gt;
29  * &lt;extension base="string"&gt;
30  * &lt;attribute name="Filter"&gt;
31  * &lt;simpleType&gt;
32  * &lt;restriction base="string"&gt;
33  * &lt;enumeration value="intersect"/&gt;
34  * &lt;enumeration value="subtract"/&gt;
35  * &lt;enumeration value="union"/&gt;
36  * &lt;/restriction&gt;
37  * &lt;/simpleType&gt;
38  * &lt;/attribute&gt;
39  * &lt;/extension&gt;
40  * &lt;/simpleContent&gt;
41  * &lt;/complexType&gt;
42  * </code></pre>
43  *
44  * @author Sean Mullan
45  * @author JSR 105 Expert Group
46  * @since 1.6
47  * @see XPathFilter2ParameterSpec
48  */

49 public class XPathType {
50
51     /**
52      * Represents the filter set operation.
53      */

54     public static class Filter {
55         private final String JavaDoc operation;
56
57         private Filter(String JavaDoc operation) {
58             this.operation = operation;
59         }
60
61         /**
62          * Returns the string form of the operation.
63          *
64          * @return the string form of the operation
65          */

66         public String JavaDoc toString() {
67             return operation;
68         }
69
70         /**
71          * The intersect filter operation.
72          */

73         public static final Filter INTERSECT = new Filter("intersect");
74
75         /**
76          * The subtract filter operation.
77          */

78         public static final Filter SUBTRACT = new Filter("subtract");
79
80         /**
81          * The union filter operation.
82          */

83         public static final Filter UNION = new Filter("union");
84     }
85
86     private final String JavaDoc expression;
87     private final Filter filter;
88     private Map JavaDoc nsMap;
89
90     /**
91      * Creates an <code>XPathType</code> instance with the specified XPath
92      * expression and filter.
93      *
94      * @param expression the XPath expression to be evaluated
95      * @param filter the filter operation ({@link Filter#INTERSECT},
96      * {@link Filter#SUBTRACT}, or {@link Filter#UNION})
97      * @throws NullPointerException if <code>expression</code> or
98      * <code>filter</code> is <code>null</code>
99      */

100     public XPathType(String JavaDoc expression, Filter filter) {
101         if (expression == null) {
102             throw new NullPointerException JavaDoc("expression cannot be null");
103         }
104         if (filter == null) {
105             throw new NullPointerException JavaDoc("filter cannot be null");
106         }
107         this.expression = expression;
108         this.filter = filter;
109         this.nsMap = Collections.EMPTY_MAP;
110     }
111
112     /**
113      * Creates an <code>XPathType</code> instance with the specified XPath
114      * expression, filter, and namespace map. The map is copied to protect
115      * against subsequent modification.
116      *
117      * @param expression the XPath expression to be evaluated
118      * @param filter the filter operation ({@link Filter#INTERSECT},
119      * {@link Filter#SUBTRACT}, or {@link Filter#UNION})
120      * @param namespaceMap the map of namespace prefixes. Each key is a
121      * namespace prefix <code>String</code> that maps to a corresponding
122      * namespace URI <code>String</code>.
123      * @throws NullPointerException if <code>expression</code>,
124      * <code>filter</code> or <code>namespaceMap</code> are
125      * <code>null</code>
126      * @throws ClassCastException if any of the map's keys or entries are
127      * not of type <code>String</code>
128      */

129     public XPathType(String JavaDoc expression, Filter filter, Map JavaDoc namespaceMap) {
130         this(expression, filter);
131         if (namespaceMap == null) {
132             throw new NullPointerException JavaDoc("namespaceMap cannot be null");
133         }
134         nsMap = new HashMap JavaDoc(namespaceMap);
135         Iterator JavaDoc entries = nsMap.entrySet().iterator();
136         while (entries.hasNext()) {
137             Map.Entry JavaDoc me = (Map.Entry JavaDoc) entries.next();
138             if (!(me.getKey() instanceof String JavaDoc) ||
139                 !(me.getValue() instanceof String JavaDoc)) {
140                 throw new ClassCastException JavaDoc("not a String");
141             }
142         }
143         nsMap = Collections.unmodifiableMap(nsMap);
144     }
145
146     /**
147      * Returns the XPath expression to be evaluated.
148      *
149      * @return the XPath expression to be evaluated
150      */

151     public String JavaDoc getExpression() {
152         return expression;
153     }
154
155     /**
156      * Returns the filter operation.
157      *
158      * @return the filter operation
159      */

160     public Filter getFilter() {
161         return filter;
162     }
163
164     /**
165      * Returns a map of namespace prefixes. Each key is a namespace prefix
166      * <code>String</code> that maps to a corresponding namespace URI
167      * <code>String</code>.
168      * <p>
169      * This implementation returns an {@link Collections#unmodifiableMap
170      * unmodifiable map}.
171      *
172      * @return a <code>Map</code> of namespace prefixes to namespace URIs
173      * (may be empty, but never <code>null</code>)
174      */

175     public Map JavaDoc getNamespaceMap() {
176         return nsMap;
177     }
178 }
179
Popular Tags