History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/javax/xml/crypto/dsig/spec/XPathType.java (1 of 18352 files). Show all

Unified · Split

java/pkg/javax/xml/crypto/dsig/spec/XPathType.java+199−0
@@ -0,0 +1,199 @@
1+/*
2+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+/*
26+ * $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $
27+ */
28+package javax.xml.crypto.dsig.spec;
29+
30+import java.util.Collections;
31+import java.util.Iterator;
32+import java.util.HashMap;
33+import java.util.Map;
34+
35+/**
36+ * The XML Schema Definition of the <code>XPath</code> element as defined in the
37+ * <a href="http://www.w3.org/TR/xmldsig-filter2">
38+ * W3C Recommendation for XML-Signature XPath Filter 2.0</a>:
39+ * <pre><code>
40+ * &lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
41+ * xmlns:xf="http://www.w3.org/2002/06/xmldsig-filter2"
42+ * targetNamespace="http://www.w3.org/2002/06/xmldsig-filter2"
43+ * version="0.1" elementFormDefault="qualified"&gt;
44+ *
45+ * &lt;element name="XPath"
46+ * type="xf:XPathType"/&gt;
47+ *
48+ * &lt;complexType name="XPathType"&gt;
49+ * &lt;simpleContent&gt;
50+ * &lt;extension base="string"&gt;
51+ * &lt;attribute name="Filter"&gt;
52+ * &lt;simpleType&gt;
53+ * &lt;restriction base="string"&gt;
54+ * &lt;enumeration value="intersect"/&gt;
55+ * &lt;enumeration value="subtract"/&gt;
56+ * &lt;enumeration value="union"/&gt;
57+ * &lt;/restriction&gt;
58+ * &lt;/simpleType&gt;
59+ * &lt;/attribute&gt;
60+ * &lt;/extension&gt;
61+ * &lt;/simpleContent&gt;
62+ * &lt;/complexType&gt;
63+ * </code></pre>
64+ *
65+ * @author Sean Mullan
66+ * @author JSR 105 Expert Group
67+ * @since 1.6
68+ * @see XPathFilter2ParameterSpec
69+ */
70+public class XPathType {
71+
72+ /**
73+ * Represents the filter set operation.
74+ */
75+ public static class Filter {
76+ private final String operation;
77+
78+ private Filter(String operation) {
79+ this.operation = operation;
80+ }
81+
82+ /**
83+ * Returns the string form of the operation.
84+ *
85+ * @return the string form of the operation
86+ */
87+ public String toString() {
88+ return operation;
89+ }
90+
91+ /**
92+ * The intersect filter operation.
93+ */
94+ public static final Filter INTERSECT = new Filter("intersect");
95+
96+ /**
97+ * The subtract filter operation.
98+ */
99+ public static final Filter SUBTRACT = new Filter("subtract");
100+
101+ /**
102+ * The union filter operation.
103+ */
104+ public static final Filter UNION = new Filter("union");
105+ }
106+
107+ private final String expression;
108+ private final Filter filter;
109+ private Map nsMap;
110+
111+ /**
112+ * Creates an <code>XPathType</code> instance with the specified XPath
113+ * expression and filter.
114+ *
115+ * @param expression the XPath expression to be evaluated
116+ * @param filter the filter operation ({@link Filter#INTERSECT},
117+ * {@link Filter#SUBTRACT}, or {@link Filter#UNION})
118+ * @throws NullPointerException if <code>expression</code> or
119+ * <code>filter</code> is <code>null</code>
120+ */
121+ public XPathType(String expression, Filter filter) {
122+ if (expression == null) {
123+ throw new NullPointerException("expression cannot be null");
124+ }
125+ if (filter == null) {
126+ throw new NullPointerException("filter cannot be null");
127+ }
128+ this.expression = expression;
129+ this.filter = filter;
130+ this.nsMap = Collections.EMPTY_MAP;
131+ }
132+
133+ /**
134+ * Creates an <code>XPathType</code> instance with the specified XPath
135+ * expression, filter, and namespace map. The map is copied to protect
136+ * against subsequent modification.
137+ *
138+ * @param expression the XPath expression to be evaluated
139+ * @param filter the filter operation ({@link Filter#INTERSECT},
140+ * {@link Filter#SUBTRACT}, or {@link Filter#UNION})
141+ * @param namespaceMap the map of namespace prefixes. Each key is a
142+ * namespace prefix <code>String</code> that maps to a corresponding
143+ * namespace URI <code>String</code>.
144+ * @throws NullPointerException if <code>expression</code>,
145+ * <code>filter</code> or <code>namespaceMap</code> are
146+ * <code>null</code>
147+ * @throws ClassCastException if any of the map's keys or entries are
148+ * not of type <code>String</code>
149+ */
150+ public XPathType(String expression, Filter filter, Map namespaceMap) {
151+ this(expression, filter);
152+ if (namespaceMap == null) {
153+ throw new NullPointerException("namespaceMap cannot be null");
154+ }
155+ nsMap = new HashMap(namespaceMap);
156+ Iterator entries = nsMap.entrySet().iterator();
157+ while (entries.hasNext()) {
158+ Map.Entry me = (Map.Entry) entries.next();
159+ if (!(me.getKey() instanceof String) ||
160+ !(me.getValue() instanceof String)) {
161+ throw new ClassCastException("not a String");
162+ }
163+ }
164+ nsMap = Collections.unmodifiableMap(nsMap);
165+ }
166+
167+ /**
168+ * Returns the XPath expression to be evaluated.
169+ *
170+ * @return the XPath expression to be evaluated
171+ */
172+ public String getExpression() {
173+ return expression;
174+ }
175+
176+ /**
177+ * Returns the filter operation.
178+ *
179+ * @return the filter operation
180+ */
181+ public Filter getFilter() {
182+ return filter;
183+ }
184+
185+ /**
186+ * Returns a map of namespace prefixes. Each key is a namespace prefix
187+ * <code>String</code> that maps to a corresponding namespace URI
188+ * <code>String</code>.
189+ * <p>
190+ * This implementation returns an {@link Collections#unmodifiableMap
191+ * unmodifiable map}.
192+ *
193+ * @return a <code>Map</code> of namespace prefixes to namespace URIs
194+ * (may be empty, but never <code>null</code>)
195+ */
196+ public Map getNamespaceMap() {
197+ return nsMap;
198+ }
199+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t