Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset fdbe50121f48
1 /*
2 * Copyright (c) 1997, 2010, 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 */
26 package com.sun.xml.internal.ws.policy.sourcemodel.wspolicy;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.Map;
31 import javax.xml.namespace.QName;
33 /**
34 *
35 * @author Marek Potociar (marek.potociar at sun.com)
36 */
37 public enum NamespaceVersion {
38 v1_2("http://schemas.xmlsoap.org/ws/2004/09/policy", "wsp1_2", new XmlToken[] {
39 XmlToken.Policy,
40 XmlToken.ExactlyOne,
41 XmlToken.All,
42 XmlToken.PolicyReference,
43 XmlToken.UsingPolicy,
44 XmlToken.Name,
45 XmlToken.Optional,
46 XmlToken.Ignorable,
47 XmlToken.PolicyUris,
48 XmlToken.Uri,
49 XmlToken.Digest,
50 XmlToken.DigestAlgorithm
51 }),
52 v1_5("http://www.w3.org/ns/ws-policy", "wsp", new XmlToken[] {
53 XmlToken.Policy,
54 XmlToken.ExactlyOne,
55 XmlToken.All,
56 XmlToken.PolicyReference,
57 XmlToken.UsingPolicy,
58 XmlToken.Name,
59 XmlToken.Optional,
60 XmlToken.Ignorable,
61 XmlToken.PolicyUris,
62 XmlToken.Uri,
63 XmlToken.Digest,
64 XmlToken.DigestAlgorithm
65 });
67 /**
68 * Resolves URI represented as a String into an enumeration value. If the URI
69 * doesn't represent any existing enumeration value, method returns
70 * {@code null}.
71 *
72 * @param uri WS-Policy namespace URI
73 * @return Enumeration value that represents given URI or {@code null} if
74 * no enumeration value exists for given URI.
75 */
76 public static NamespaceVersion resolveVersion(String uri) {
77 for (NamespaceVersion namespaceVersion : NamespaceVersion.values()) {
78 if (namespaceVersion.toString().equalsIgnoreCase(uri)) {
79 return namespaceVersion;
80 }
81 }
83 return null;
84 }
86 /**
87 * Resolves fully qualified name defined in the WS-Policy namespace into an
88 * enumeration value. If the URI in the name doesn't represent any existing
89 * enumeration value, method returns {@code null}
90 *
91 * @param name fully qualified name defined in the WS-Policy namespace
92 * @return Enumeration value that represents given namespace or {@code null} if
93 * no enumeration value exists for given namespace.
94 */
95 public static NamespaceVersion resolveVersion(QName name) {
96 return resolveVersion(name.getNamespaceURI());
97 }
99 /**
100 * Returns latest supported version of the policy namespace
101 *
102 * @return latest supported policy namespace version.
103 */
104 public static NamespaceVersion getLatestVersion() {
105 return v1_5;
106 }
108 /**
109 * Resolves FQN into a policy XML token. The version of the token can be determined
110 * by invoking {@link #resolveVersion(QName)}.
111 *
112 * @param name fully qualified name defined in the WS-Policy namespace
113 * @return XML token enumeration that represents this fully qualified name.
114 * If the token or the namespace is not resolved {@link XmlToken#UNKNOWN} value
115 * is returned.
116 */
117 public static XmlToken resolveAsToken(QName name) {
118 NamespaceVersion nsVersion = resolveVersion(name);
119 if (nsVersion != null) {
120 XmlToken token = XmlToken.resolveToken(name.getLocalPart());
121 if (nsVersion.tokenToQNameCache.containsKey(token)) {
122 return token;
123 }
124 }
125 return XmlToken.UNKNOWN;
126 }
128 private final String nsUri;
129 private final String defaultNsPrefix;
130 private final Map<XmlToken, QName> tokenToQNameCache;
132 private NamespaceVersion(String uri, String prefix, XmlToken... supportedTokens) {
133 nsUri = uri;
134 defaultNsPrefix = prefix;
136 Map<XmlToken, QName> temp = new HashMap<XmlToken, QName>();
137 for (XmlToken token : supportedTokens) {
138 temp.put(token, new QName(nsUri, token.toString()));
139 }
140 tokenToQNameCache = Collections.unmodifiableMap(temp);
141 }
143 /**
144 * Method returns default namespace prefix for given namespace version.
145 *
146 * @return default namespace prefix for given namespace version
147 */
148 public String getDefaultNamespacePrefix() {
149 return defaultNsPrefix;
150 }
152 /**
153 * Resolves XML token into a fully qualified name within given namespace version.
154 *
155 * @param token XML token enumeration value.
156 * @return fully qualified name of the {@code token} within given namespace
157 * version. Method returns {@code null} in case the token is not supported in
158 * given namespace version or in case {@link XmlToken#UNKNOWN} was used as
159 * an input parameter.
160 */
161 public QName asQName(XmlToken token) throws IllegalArgumentException {
162 return tokenToQNameCache.get(token);
163 }
165 @Override
166 public String toString() {
167 return nsUri;
168 }
169 }