Fri, 14 Feb 2014 11:13:45 +0100
8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.ws.util; |
ohair@286 | 27 | |
ohair@286 | 28 | import java.util.StringTokenizer; |
ohair@286 | 29 | |
ohair@286 | 30 | |
ohair@286 | 31 | /** |
ohair@286 | 32 | * Provides some version utilities. |
ohair@286 | 33 | * |
ohair@286 | 34 | * @author JAX-WS Development Team |
ohair@286 | 35 | */ |
ohair@286 | 36 | |
ohair@286 | 37 | public final class VersionUtil { |
ohair@286 | 38 | |
ohair@286 | 39 | public static boolean isVersion20(String version) { |
ohair@286 | 40 | return JAXWS_VERSION_20.equals(version); |
ohair@286 | 41 | } |
ohair@286 | 42 | |
ohair@286 | 43 | /** |
ohair@286 | 44 | * @param version |
ohair@286 | 45 | * @return true if version is a 2.0 version |
ohair@286 | 46 | */ |
ohair@286 | 47 | public static boolean isValidVersion(String version) { |
ohair@286 | 48 | return isVersion20(version); |
ohair@286 | 49 | } |
ohair@286 | 50 | |
ohair@286 | 51 | public static String getValidVersionString() { |
ohair@286 | 52 | return JAXWS_VERSION_20; |
ohair@286 | 53 | } |
ohair@286 | 54 | |
ohair@286 | 55 | /** |
ohair@286 | 56 | * BugFix# 4948171 |
ohair@286 | 57 | * Method getCanonicalVersion. |
ohair@286 | 58 | * |
ohair@286 | 59 | * Converts a given version to the format "a.b.c.d" |
ohair@286 | 60 | * a - major version |
ohair@286 | 61 | * b - minor version |
ohair@286 | 62 | * c - minor minor version |
ohair@286 | 63 | * d - patch version |
ohair@286 | 64 | * |
ohair@286 | 65 | * @return int[] Canonical version number |
ohair@286 | 66 | */ |
ohair@286 | 67 | public static int[] getCanonicalVersion(String version) { |
ohair@286 | 68 | int[] canonicalVersion = new int[4]; |
ohair@286 | 69 | |
ohair@286 | 70 | // initialize the default version numbers |
ohair@286 | 71 | canonicalVersion[0] = 1; |
ohair@286 | 72 | canonicalVersion[1] = 1; |
ohair@286 | 73 | canonicalVersion[2] = 0; |
ohair@286 | 74 | canonicalVersion[3] = 0; |
ohair@286 | 75 | |
ohair@286 | 76 | final String DASH_DELIM = "_"; |
ohair@286 | 77 | final String DOT_DELIM = "."; |
ohair@286 | 78 | |
ohair@286 | 79 | StringTokenizer tokenizer = |
ohair@286 | 80 | new StringTokenizer(version, DOT_DELIM); |
ohair@286 | 81 | String token = tokenizer.nextToken(); |
ohair@286 | 82 | |
ohair@286 | 83 | // first token is major version and must not have "_" |
ohair@286 | 84 | canonicalVersion[0] = Integer.parseInt(token); |
ohair@286 | 85 | |
ohair@286 | 86 | // resolve the minor version |
ohair@286 | 87 | token = tokenizer.nextToken(); |
ohair@286 | 88 | if (token.indexOf(DASH_DELIM) == -1) { |
ohair@286 | 89 | // a.b |
ohair@286 | 90 | canonicalVersion[1] = Integer.parseInt(token); |
ohair@286 | 91 | } else { |
ohair@286 | 92 | // a.b_c |
ohair@286 | 93 | StringTokenizer subTokenizer = |
ohair@286 | 94 | new StringTokenizer(token, DASH_DELIM); |
ohair@286 | 95 | canonicalVersion[1] = Integer.parseInt(subTokenizer.nextToken()); |
ohair@286 | 96 | // leave minorMinor default |
ohair@286 | 97 | |
ohair@286 | 98 | canonicalVersion[3] = Integer.parseInt(subTokenizer.nextToken()); |
ohair@286 | 99 | } |
ohair@286 | 100 | |
ohair@286 | 101 | // resolve the minorMinor and patch version, if any |
ohair@286 | 102 | if (tokenizer.hasMoreTokens()) { |
ohair@286 | 103 | token = tokenizer.nextToken(); |
ohair@286 | 104 | if (token.indexOf(DASH_DELIM) == -1) { |
ohair@286 | 105 | // minorMinor |
ohair@286 | 106 | canonicalVersion[2] = Integer.parseInt(token); |
ohair@286 | 107 | |
ohair@286 | 108 | // resolve patch, if any |
ohair@286 | 109 | if (tokenizer.hasMoreTokens()) |
ohair@286 | 110 | canonicalVersion[3] = Integer.parseInt(tokenizer.nextToken()); |
ohair@286 | 111 | } else { |
ohair@286 | 112 | // a.b.c_d |
ohair@286 | 113 | StringTokenizer subTokenizer = |
ohair@286 | 114 | new StringTokenizer(token, DASH_DELIM); |
ohair@286 | 115 | // minorMinor |
ohair@286 | 116 | canonicalVersion[2] = Integer.parseInt(subTokenizer.nextToken()); |
ohair@286 | 117 | |
ohair@286 | 118 | // patch |
ohair@286 | 119 | canonicalVersion[3] = Integer.parseInt(subTokenizer.nextToken()); |
ohair@286 | 120 | } |
ohair@286 | 121 | } |
ohair@286 | 122 | |
ohair@286 | 123 | return canonicalVersion; |
ohair@286 | 124 | } |
ohair@286 | 125 | |
ohair@286 | 126 | /** |
ohair@286 | 127 | * |
ohair@286 | 128 | * @param version1 |
ohair@286 | 129 | * @param version2 |
ohair@286 | 130 | * @return -1, 0 or 1 based upon the comparison results |
ohair@286 | 131 | * -1 if version1 is less than version2 |
ohair@286 | 132 | * 0 if version1 is equal to version2 |
ohair@286 | 133 | * 1 if version1 is greater than version2 |
ohair@286 | 134 | */ |
ohair@286 | 135 | public static int compare(String version1, String version2) { |
ohair@286 | 136 | int[] canonicalVersion1 = getCanonicalVersion(version1); |
ohair@286 | 137 | int[] canonicalVersion2 = getCanonicalVersion(version2); |
ohair@286 | 138 | |
ohair@286 | 139 | if (canonicalVersion1[0] < canonicalVersion2[0]) { |
ohair@286 | 140 | return -1; |
ohair@286 | 141 | } else if (canonicalVersion1[0] > canonicalVersion2[0]) { |
ohair@286 | 142 | return 1; |
ohair@286 | 143 | } else { |
ohair@286 | 144 | if (canonicalVersion1[1] < canonicalVersion2[1]) { |
ohair@286 | 145 | return -1; |
ohair@286 | 146 | } else if (canonicalVersion1[1] > canonicalVersion2[1]) { |
ohair@286 | 147 | return 1; |
ohair@286 | 148 | } else { |
ohair@286 | 149 | if (canonicalVersion1[2] < canonicalVersion2[2]) { |
ohair@286 | 150 | return -1; |
ohair@286 | 151 | } else if (canonicalVersion1[2] > canonicalVersion2[2]) { |
ohair@286 | 152 | return 1; |
ohair@286 | 153 | } else { |
ohair@286 | 154 | if (canonicalVersion1[3] < canonicalVersion2[3]) { |
ohair@286 | 155 | return -1; |
ohair@286 | 156 | } else if (canonicalVersion1[3] > canonicalVersion2[3]) { |
ohair@286 | 157 | return 1; |
ohair@286 | 158 | } else |
ohair@286 | 159 | return 0; |
ohair@286 | 160 | } |
ohair@286 | 161 | } |
ohair@286 | 162 | } |
ohair@286 | 163 | } |
ohair@286 | 164 | |
ohair@286 | 165 | public static final String JAXWS_VERSION_20 = "2.0"; |
ohair@286 | 166 | // the latest version is default |
ohair@286 | 167 | public static final String JAXWS_VERSION_DEFAULT = JAXWS_VERSION_20; |
ohair@286 | 168 | } |