Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset fdbe50121f48
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.policy.sourcemodel.wspolicy; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.Collections; |
aoqi@0 | 29 | import java.util.HashMap; |
aoqi@0 | 30 | import java.util.Map; |
aoqi@0 | 31 | import javax.xml.namespace.QName; |
aoqi@0 | 32 | |
aoqi@0 | 33 | /** |
aoqi@0 | 34 | * |
aoqi@0 | 35 | * @author Marek Potociar (marek.potociar at sun.com) |
aoqi@0 | 36 | */ |
aoqi@0 | 37 | public enum NamespaceVersion { |
aoqi@0 | 38 | v1_2("http://schemas.xmlsoap.org/ws/2004/09/policy", "wsp1_2", new XmlToken[] { |
aoqi@0 | 39 | XmlToken.Policy, |
aoqi@0 | 40 | XmlToken.ExactlyOne, |
aoqi@0 | 41 | XmlToken.All, |
aoqi@0 | 42 | XmlToken.PolicyReference, |
aoqi@0 | 43 | XmlToken.UsingPolicy, |
aoqi@0 | 44 | XmlToken.Name, |
aoqi@0 | 45 | XmlToken.Optional, |
aoqi@0 | 46 | XmlToken.Ignorable, |
aoqi@0 | 47 | XmlToken.PolicyUris, |
aoqi@0 | 48 | XmlToken.Uri, |
aoqi@0 | 49 | XmlToken.Digest, |
aoqi@0 | 50 | XmlToken.DigestAlgorithm |
aoqi@0 | 51 | }), |
aoqi@0 | 52 | v1_5("http://www.w3.org/ns/ws-policy", "wsp", new XmlToken[] { |
aoqi@0 | 53 | XmlToken.Policy, |
aoqi@0 | 54 | XmlToken.ExactlyOne, |
aoqi@0 | 55 | XmlToken.All, |
aoqi@0 | 56 | XmlToken.PolicyReference, |
aoqi@0 | 57 | XmlToken.UsingPolicy, |
aoqi@0 | 58 | XmlToken.Name, |
aoqi@0 | 59 | XmlToken.Optional, |
aoqi@0 | 60 | XmlToken.Ignorable, |
aoqi@0 | 61 | XmlToken.PolicyUris, |
aoqi@0 | 62 | XmlToken.Uri, |
aoqi@0 | 63 | XmlToken.Digest, |
aoqi@0 | 64 | XmlToken.DigestAlgorithm |
aoqi@0 | 65 | }); |
aoqi@0 | 66 | |
aoqi@0 | 67 | /** |
aoqi@0 | 68 | * Resolves URI represented as a String into an enumeration value. If the URI |
aoqi@0 | 69 | * doesn't represent any existing enumeration value, method returns |
aoqi@0 | 70 | * {@code null}. |
aoqi@0 | 71 | * |
aoqi@0 | 72 | * @param uri WS-Policy namespace URI |
aoqi@0 | 73 | * @return Enumeration value that represents given URI or {@code null} if |
aoqi@0 | 74 | * no enumeration value exists for given URI. |
aoqi@0 | 75 | */ |
aoqi@0 | 76 | public static NamespaceVersion resolveVersion(String uri) { |
aoqi@0 | 77 | for (NamespaceVersion namespaceVersion : NamespaceVersion.values()) { |
aoqi@0 | 78 | if (namespaceVersion.toString().equalsIgnoreCase(uri)) { |
aoqi@0 | 79 | return namespaceVersion; |
aoqi@0 | 80 | } |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | return null; |
aoqi@0 | 84 | } |
aoqi@0 | 85 | |
aoqi@0 | 86 | /** |
aoqi@0 | 87 | * Resolves fully qualified name defined in the WS-Policy namespace into an |
aoqi@0 | 88 | * enumeration value. If the URI in the name doesn't represent any existing |
aoqi@0 | 89 | * enumeration value, method returns {@code null} |
aoqi@0 | 90 | * |
aoqi@0 | 91 | * @param name fully qualified name defined in the WS-Policy namespace |
aoqi@0 | 92 | * @return Enumeration value that represents given namespace or {@code null} if |
aoqi@0 | 93 | * no enumeration value exists for given namespace. |
aoqi@0 | 94 | */ |
aoqi@0 | 95 | public static NamespaceVersion resolveVersion(QName name) { |
aoqi@0 | 96 | return resolveVersion(name.getNamespaceURI()); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | /** |
aoqi@0 | 100 | * Returns latest supported version of the policy namespace |
aoqi@0 | 101 | * |
aoqi@0 | 102 | * @return latest supported policy namespace version. |
aoqi@0 | 103 | */ |
aoqi@0 | 104 | public static NamespaceVersion getLatestVersion() { |
aoqi@0 | 105 | return v1_5; |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | /** |
aoqi@0 | 109 | * Resolves FQN into a policy XML token. The version of the token can be determined |
aoqi@0 | 110 | * by invoking {@link #resolveVersion(QName)}. |
aoqi@0 | 111 | * |
aoqi@0 | 112 | * @param name fully qualified name defined in the WS-Policy namespace |
aoqi@0 | 113 | * @return XML token enumeration that represents this fully qualified name. |
aoqi@0 | 114 | * If the token or the namespace is not resolved {@link XmlToken#UNKNOWN} value |
aoqi@0 | 115 | * is returned. |
aoqi@0 | 116 | */ |
aoqi@0 | 117 | public static XmlToken resolveAsToken(QName name) { |
aoqi@0 | 118 | NamespaceVersion nsVersion = resolveVersion(name); |
aoqi@0 | 119 | if (nsVersion != null) { |
aoqi@0 | 120 | XmlToken token = XmlToken.resolveToken(name.getLocalPart()); |
aoqi@0 | 121 | if (nsVersion.tokenToQNameCache.containsKey(token)) { |
aoqi@0 | 122 | return token; |
aoqi@0 | 123 | } |
aoqi@0 | 124 | } |
aoqi@0 | 125 | return XmlToken.UNKNOWN; |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | private final String nsUri; |
aoqi@0 | 129 | private final String defaultNsPrefix; |
aoqi@0 | 130 | private final Map<XmlToken, QName> tokenToQNameCache; |
aoqi@0 | 131 | |
aoqi@0 | 132 | private NamespaceVersion(String uri, String prefix, XmlToken... supportedTokens) { |
aoqi@0 | 133 | nsUri = uri; |
aoqi@0 | 134 | defaultNsPrefix = prefix; |
aoqi@0 | 135 | |
aoqi@0 | 136 | Map<XmlToken, QName> temp = new HashMap<XmlToken, QName>(); |
aoqi@0 | 137 | for (XmlToken token : supportedTokens) { |
aoqi@0 | 138 | temp.put(token, new QName(nsUri, token.toString())); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | tokenToQNameCache = Collections.unmodifiableMap(temp); |
aoqi@0 | 141 | } |
aoqi@0 | 142 | |
aoqi@0 | 143 | /** |
aoqi@0 | 144 | * Method returns default namespace prefix for given namespace version. |
aoqi@0 | 145 | * |
aoqi@0 | 146 | * @return default namespace prefix for given namespace version |
aoqi@0 | 147 | */ |
aoqi@0 | 148 | public String getDefaultNamespacePrefix() { |
aoqi@0 | 149 | return defaultNsPrefix; |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | /** |
aoqi@0 | 153 | * Resolves XML token into a fully qualified name within given namespace version. |
aoqi@0 | 154 | * |
aoqi@0 | 155 | * @param token XML token enumeration value. |
aoqi@0 | 156 | * @return fully qualified name of the {@code token} within given namespace |
aoqi@0 | 157 | * version. Method returns {@code null} in case the token is not supported in |
aoqi@0 | 158 | * given namespace version or in case {@link XmlToken#UNKNOWN} was used as |
aoqi@0 | 159 | * an input parameter. |
aoqi@0 | 160 | */ |
aoqi@0 | 161 | public QName asQName(XmlToken token) throws IllegalArgumentException { |
aoqi@0 | 162 | return tokenToQNameCache.get(token); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | @Override |
aoqi@0 | 166 | public String toString() { |
aoqi@0 | 167 | return nsUri; |
aoqi@0 | 168 | } |
aoqi@0 | 169 | } |