1 /* |
1 /* |
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
26 * $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $ |
26 * $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $ |
27 */ |
27 */ |
28 package javax.xml.crypto.dsig.spec; |
28 package javax.xml.crypto.dsig.spec; |
29 |
29 |
30 import java.util.Collections; |
30 import java.util.Collections; |
31 import java.util.Iterator; |
|
32 import java.util.HashMap; |
31 import java.util.HashMap; |
33 import java.util.Map; |
32 import java.util.Map; |
34 |
33 |
35 /** |
34 /** |
36 * The XML Schema Definition of the <code>XPath</code> element as defined in the |
35 * The XML Schema Definition of the <code>XPath</code> element as defined in the |
104 public static final Filter UNION = new Filter("union"); |
103 public static final Filter UNION = new Filter("union"); |
105 } |
104 } |
106 |
105 |
107 private final String expression; |
106 private final String expression; |
108 private final Filter filter; |
107 private final Filter filter; |
109 private Map<String,String> nsMap; |
108 private final Map<String,String> nsMap; |
110 |
109 |
111 /** |
110 /** |
112 * Creates an <code>XPathType</code> instance with the specified XPath |
111 * Creates an <code>XPathType</code> instance with the specified XPath |
113 * expression and filter. |
112 * expression and filter. |
114 * |
113 * |
145 * <code>filter</code> or <code>namespaceMap</code> are |
144 * <code>filter</code> or <code>namespaceMap</code> are |
146 * <code>null</code> |
145 * <code>null</code> |
147 * @throws ClassCastException if any of the map's keys or entries are |
146 * @throws ClassCastException if any of the map's keys or entries are |
148 * not of type <code>String</code> |
147 * not of type <code>String</code> |
149 */ |
148 */ |
150 @SuppressWarnings("rawtypes") |
149 public XPathType(String expression, Filter filter, |
151 public XPathType(String expression, Filter filter, Map namespaceMap) { |
150 Map<String,String> namespaceMap) { |
152 this(expression, filter); |
151 if (expression == null) { |
|
152 throw new NullPointerException("expression cannot be null"); |
|
153 } |
|
154 if (filter == null) { |
|
155 throw new NullPointerException("filter cannot be null"); |
|
156 } |
153 if (namespaceMap == null) { |
157 if (namespaceMap == null) { |
154 throw new NullPointerException("namespaceMap cannot be null"); |
158 throw new NullPointerException("namespaceMap cannot be null"); |
155 } |
159 } |
156 Map<?,?> copy = new HashMap<>((Map<?,?>)namespaceMap); |
160 this.expression = expression; |
157 Iterator<? extends Map.Entry<?,?>> entries = copy.entrySet().iterator(); |
161 this.filter = filter; |
158 while (entries.hasNext()) { |
162 Map<String,String> tempMap = Collections.checkedMap(new HashMap<>(), |
159 Map.Entry<?,?> me = entries.next(); |
163 String.class, |
160 if (!(me.getKey() instanceof String) || |
164 String.class); |
161 !(me.getValue() instanceof String)) { |
165 tempMap.putAll(namespaceMap); |
162 throw new ClassCastException("not a String"); |
166 this.nsMap = Collections.unmodifiableMap(tempMap); |
163 } |
|
164 } |
|
165 |
|
166 @SuppressWarnings("unchecked") |
|
167 Map<String,String> temp = (Map<String,String>)copy; |
|
168 |
|
169 nsMap = Collections.unmodifiableMap(temp); |
|
170 } |
167 } |
171 |
168 |
172 /** |
169 /** |
173 * Returns the XPath expression to be evaluated. |
170 * Returns the XPath expression to be evaluated. |
174 * |
171 * |