| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2007, 2009 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | package org.eclipse.pde.api.tools.internal.provisional; |
| 12 | |
| 13 | /** |
| 14 | * Class containing constants and utility methods for @since values. |
| 15 | * |
| 16 | * This covers the corresponding profiles: |
| 17 | * <ul> |
| 18 | * <li>CDC-1.0_Foundation-1.0</li> |
| 19 | * <li>CDC-1.1_Foundation-1.1</li> |
| 20 | * <li>J2SE-1.2</li> |
| 21 | * <li>J2SE-1.3</li> |
| 22 | * <li>J2SE-1.4</li> |
| 23 | * <li>J2SE-1.5</li> |
| 24 | * <li>JavaSE-1.6</li> |
| 25 | * <li>JRE-1.1</li> |
| 26 | * <li>OSGi_Minimum-1.0</li> |
| 27 | * <li>OSGi_Minimum-1.1</li> |
| 28 | * <li>OSGi_Minimum-1.2</li> |
| 29 | * </ul> |
| 30 | * |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | public final class ProfileModifiers { |
| 34 | |
| 35 | public static final int NO_PROFILE_VALUE = 0; |
| 36 | |
| 37 | public static final String CDC_1_0_FOUNDATION_1_0_NAME = "CDC-1.0/Foundation-1.0"; //$NON-NLS-1$ |
| 38 | public static final String CDC_1_1_FOUNDATION_1_1_NAME = "CDC-1.1/Foundation-1.1"; //$NON-NLS-1$ |
| 39 | public static final String J2SE_1_2_NAME = "J2SE-1.2"; //$NON-NLS-1$ |
| 40 | public static final String J2SE_1_3_NAME = "J2SE-1.3"; //$NON-NLS-1$ |
| 41 | public static final String J2SE_1_4_NAME = "J2SE-1.4"; //$NON-NLS-1$ |
| 42 | public static final String J2SE_1_5_NAME = "J2SE-1.5"; //$NON-NLS-1$ |
| 43 | public static final String JAVASE_1_6_NAME = "JavaSE-1.6"; //$NON-NLS-1$ |
| 44 | public static final String JRE_1_1_NAME = "JRE-1.1"; //$NON-NLS-1$ |
| 45 | public static final String OSGI_MINIMUM_1_0_NAME = "OSGi/Minimum-1.0"; //$NON-NLS-1$ |
| 46 | public static final String OSGI_MINIMUM_1_1_NAME = "OSGi/Minimum-1.1"; //$NON-NLS-1$ |
| 47 | public static final String OSGI_MINIMUM_1_2_NAME = "OSGi/Minimum-1.2"; //$NON-NLS-1$ |
| 48 | |
| 49 | /** |
| 50 | * Constant indicating the corresponding element has been defined in the CDC-1.0_Foundation-1.0 profile |
| 51 | */ |
| 52 | public static final int CDC_1_0_FOUNDATION_1_0 = 0x0001; |
| 53 | |
| 54 | /** |
| 55 | * Constant indicating the corresponding element has been defined in the CDC-1.1_Foundation-1.1 profile |
| 56 | */ |
| 57 | public static final int CDC_1_1_FOUNDATION_1_1 = 0x0002; |
| 58 | |
| 59 | /** |
| 60 | * Constant indicating the corresponding element has been defined in the JRE-1.1 profile |
| 61 | */ |
| 62 | public static final int JRE_1_1 = 0x0004; |
| 63 | |
| 64 | /** |
| 65 | * Constant indicating the corresponding element has been defined in the J2SE-1.2 profile |
| 66 | */ |
| 67 | public static final int J2SE_1_2 = 0x0008; |
| 68 | |
| 69 | /** |
| 70 | * Constant indicating the corresponding element has been defined in the J2SE-1.3 profile |
| 71 | */ |
| 72 | public static final int J2SE_1_3 = 0x0010; |
| 73 | |
| 74 | /** |
| 75 | * Constant indicating the corresponding element has been defined in the J2SE-1.4 profile |
| 76 | */ |
| 77 | public static final int J2SE_1_4 = 0x0020; |
| 78 | |
| 79 | /** |
| 80 | * Constant indicating the corresponding element has been defined in the J2SE-1.5 profile |
| 81 | */ |
| 82 | public static final int J2SE_1_5 = 0x0040; |
| 83 | |
| 84 | /** |
| 85 | * Constant indicating the corresponding element has been defined in the JavaSE-1.6 profile |
| 86 | */ |
| 87 | public static final int JAVASE_1_6 = 0x0080; |
| 88 | |
| 89 | /** |
| 90 | * Constant indicating the corresponding element has been defined in the OSGi_Minimum-1.0 profile |
| 91 | */ |
| 92 | public static final int OSGI_MINIMUM_1_0 = 0x0100; |
| 93 | |
| 94 | /** |
| 95 | * Constant indicating the corresponding element has been defined in the OSGi_Minimum-1.1 profile |
| 96 | */ |
| 97 | public static final int OSGI_MINIMUM_1_1 = 0x0200; |
| 98 | |
| 99 | /** |
| 100 | * Constant indicating the corresponding element has been defined in the OSGi_Minimum-1.2 profile |
| 101 | */ |
| 102 | public static final int OSGI_MINIMUM_1_2 = 0x0400; |
| 103 | |
| 104 | /** |
| 105 | * Constant indicating all the OSGi profiles are defined |
| 106 | */ |
| 107 | public static final int OSGI_MINIMUM_MASK = 0x0700; |
| 108 | |
| 109 | /** |
| 110 | * Constant indicating all the CDC/Foundation profiles are defined |
| 111 | */ |
| 112 | public static final int CDC_FOUNDATION_MAX = 0x0003; |
| 113 | |
| 114 | /** |
| 115 | * Constant indicating all the jres profiles are defined |
| 116 | */ |
| 117 | public static final int JRES_MAX = 0x00FC; |
| 118 | |
| 119 | /** |
| 120 | * Constructor |
| 121 | * no instantiating |
| 122 | */ |
| 123 | private ProfileModifiers() {} |
| 124 | |
| 125 | /** |
| 126 | * Returns if the CDC_1_0_FOUNDATION_1_0 modifier has been set in the given modifiers. |
| 127 | * |
| 128 | * @param modifiers the given modifiers |
| 129 | * @return true if the CDC_1_0_FOUNDATION_1_0 modifier has been set in the specified modifiers, false otherwise |
| 130 | */ |
| 131 | public static boolean isCDC_1_0_FOUNDATION_1_0(int modifiers) { |
| 132 | return (modifiers & CDC_1_0_FOUNDATION_1_0) > 0; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns if the CDC_1_1_FOUNDATION_1_1 modifier has been set in the given modifiers. |
| 137 | * |
| 138 | * @param modifiers the given modifiers |
| 139 | * @return true if the CDC_1_1_FOUNDATION_1_1 modifier has been set in the specified modifiers, false otherwise |
| 140 | */ |
| 141 | public static boolean isCDC_1_1_FOUNDATION_1_1(int modifiers) { |
| 142 | return (modifiers & CDC_1_1_FOUNDATION_1_1) > 0; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns if the J2SE_1_2 modifier has been set in the given modifiers. |
| 147 | * |
| 148 | * @param modifiers the given modifiers |
| 149 | * @return true if the J2SE_1_2 modifier has been set in the specified modifiers, false otherwise |
| 150 | */ |
| 151 | public static boolean isJ2SE_1_2(int modifiers) { |
| 152 | return (modifiers & J2SE_1_2) > 0; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Returns if the J2SE_1_3 modifier has been set in the given modifiers. |
| 157 | * |
| 158 | * @param modifiers the given modifiers |
| 159 | * @return true if the J2SE_1_3 modifier has been set in the specified modifiers, false otherwise |
| 160 | */ |
| 161 | public static boolean isJ2SE_1_3(int modifiers) { |
| 162 | return (modifiers & J2SE_1_3) > 0; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Returns if the J2SE_1_4 modifier has been set in the given modifiers. |
| 167 | * |
| 168 | * @param modifiers the given modifiers |
| 169 | * @return true if the J2SE_1_4 modifier has been set in the specified modifiers, false otherwise |
| 170 | */ |
| 171 | public static boolean isJ2SE_1_4(int modifiers) { |
| 172 | return (modifiers & J2SE_1_4) > 0; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Returns if the J2SE_1_5 modifier has been set in the given modifiers. |
| 177 | * |
| 178 | * @param modifiers the given modifiers |
| 179 | * @return true if the J2SE_1_5 modifier has been set in the specified modifiers, false otherwise |
| 180 | */ |
| 181 | public static boolean isJ2SE_1_5(int modifiers) { |
| 182 | return (modifiers & J2SE_1_5) > 0; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Returns if the JAVASE_1_6 modifier has been set in the given modifiers. |
| 187 | * |
| 188 | * @param modifiers the given modifiers |
| 189 | * @return true if the JAVASE_1_6 modifier has been set in the specified modifiers, false otherwise |
| 190 | */ |
| 191 | public static boolean isJAVASE_1_6(int modifiers) { |
| 192 | return (modifiers & JAVASE_1_6) > 0; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Returns if the JRE_1_1 modifier has been set in the given modifiers. |
| 197 | * |
| 198 | * @param modifiers the given modifiers |
| 199 | * @return true if the JRE_1_1 modifier has been set in the specified modifiers, false otherwise |
| 200 | */ |
| 201 | public static boolean isJRE_1_1(int modifiers) { |
| 202 | return (modifiers & JRE_1_1) > 0; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Returns if the OSGI_MINIMUM_1_0 modifier has been set in the given modifiers. |
| 207 | * |
| 208 | * @param modifiers the given modifiers |
| 209 | * @return true if the OSGI_MINIMUM_1_0 modifier has been set in the specified modifiers, false otherwise |
| 210 | */ |
| 211 | public static boolean isOSGI_MINIMUM_1_0(int modifiers) { |
| 212 | return (modifiers & OSGI_MINIMUM_1_0) > 0; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Returns if the OSGI_MINIMUM_1_1 modifier has been set in the given modifiers. |
| 217 | * |
| 218 | * @param modifiers the given modifiers |
| 219 | * @return true if the OSGI_MINIMUM_1_1 modifier has been set in the specified modifiers, false otherwise |
| 220 | */ |
| 221 | public static boolean isOSGI_MINIMUM_1_1(int modifiers) { |
| 222 | return (modifiers & OSGI_MINIMUM_1_1) > 0; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Returns if the OSGI_MINIMUM_1_2 modifier has been set in the given modifiers. |
| 227 | * |
| 228 | * @param modifiers the given modifiers |
| 229 | * @return true if the OSGI_MINIMUM_1_2 modifier has been set in the specified modifiers, false otherwise |
| 230 | */ |
| 231 | public static boolean isOSGI_MINIMUM_1_2(int modifiers) { |
| 232 | return (modifiers & OSGI_MINIMUM_1_2) > 0; |
| 233 | } |
| 234 | |
| 235 | public static int getValue(String profileName) { |
| 236 | if (profileName == null) { |
| 237 | return NO_PROFILE_VALUE; |
| 238 | } |
| 239 | if (CDC_1_0_FOUNDATION_1_0_NAME.equals(profileName)) { |
| 240 | return CDC_1_0_FOUNDATION_1_0; |
| 241 | } |
| 242 | if (CDC_1_1_FOUNDATION_1_1_NAME.equals(profileName)) { |
| 243 | return CDC_1_1_FOUNDATION_1_1; |
| 244 | } |
| 245 | if (J2SE_1_2_NAME.equals(profileName)) { |
| 246 | return J2SE_1_2; |
| 247 | } |
| 248 | if (J2SE_1_3_NAME.equals(profileName)) { |
| 249 | return J2SE_1_3; |
| 250 | } |
| 251 | if (J2SE_1_4_NAME.equals(profileName)) { |
| 252 | return J2SE_1_4; |
| 253 | } |
| 254 | if (J2SE_1_5_NAME.equals(profileName)) { |
| 255 | return J2SE_1_5; |
| 256 | } |
| 257 | if (JAVASE_1_6_NAME.equals(profileName)) { |
| 258 | return JAVASE_1_6; |
| 259 | } |
| 260 | if (JRE_1_1_NAME.equals(profileName)) { |
| 261 | return JRE_1_1; |
| 262 | } |
| 263 | if (OSGI_MINIMUM_1_0_NAME.equals(profileName)) { |
| 264 | return OSGI_MINIMUM_1_0; |
| 265 | } |
| 266 | if (OSGI_MINIMUM_1_1_NAME.equals(profileName)) { |
| 267 | return OSGI_MINIMUM_1_1; |
| 268 | } |
| 269 | if (OSGI_MINIMUM_1_2_NAME.equals(profileName)) { |
| 270 | return OSGI_MINIMUM_1_2; |
| 271 | } |
| 272 | return NO_PROFILE_VALUE; |
| 273 | } |
| 274 | |
| 275 | public static String getName(int profile) { |
| 276 | switch(profile) { |
| 277 | case CDC_1_0_FOUNDATION_1_0 : |
| 278 | return CDC_1_0_FOUNDATION_1_0_NAME; |
| 279 | case CDC_1_1_FOUNDATION_1_1 : |
| 280 | return CDC_1_1_FOUNDATION_1_1_NAME; |
| 281 | case J2SE_1_2 : |
| 282 | return J2SE_1_2_NAME; |
| 283 | case J2SE_1_3 : |
| 284 | return J2SE_1_3_NAME; |
| 285 | case J2SE_1_4 : |
| 286 | return J2SE_1_4_NAME; |
| 287 | case J2SE_1_5 : |
| 288 | return J2SE_1_5_NAME; |
| 289 | case JAVASE_1_6 : |
| 290 | return JAVASE_1_6_NAME; |
| 291 | case JRE_1_1 : |
| 292 | return JRE_1_1_NAME; |
| 293 | case OSGI_MINIMUM_1_0 : |
| 294 | return OSGI_MINIMUM_1_0_NAME; |
| 295 | case OSGI_MINIMUM_1_1 : |
| 296 | return OSGI_MINIMUM_1_1_NAME; |
| 297 | case OSGI_MINIMUM_1_2 : |
| 298 | return OSGI_MINIMUM_1_2_NAME; |
| 299 | default: |
| 300 | return null; |
| 301 | } |
| 302 | } |
| 303 | public static boolean isJRE(int value) { |
| 304 | return (value & JRES_MAX) != 0; |
| 305 | } |
| 306 | public static boolean isJRE(String name) { |
| 307 | int value = getValue(name); |
| 308 | return isJRE(value); |
| 309 | } |
| 310 | public static boolean isOSGi(String name) { |
| 311 | int value = getValue(name); |
| 312 | return isOSGi(value); |
| 313 | } |
| 314 | public static boolean isOSGi(int value) { |
| 315 | return (value & OSGI_MINIMUM_MASK) != 0; |
| 316 | } |
| 317 | public static boolean isCDC_Foundation(String name) { |
| 318 | int value = getValue(name); |
| 319 | return isCDC_Foundation(value); |
| 320 | } |
| 321 | public static boolean isCDC_Foundation(int value) { |
| 322 | return (value & CDC_FOUNDATION_MAX) != 0; |
| 323 | } |
| 324 | |
| 325 | public static int[] getAllIds() { |
| 326 | return new int[] { |
| 327 | CDC_1_0_FOUNDATION_1_0, |
| 328 | CDC_1_1_FOUNDATION_1_1, |
| 329 | JRE_1_1, |
| 330 | J2SE_1_2, |
| 331 | J2SE_1_3, |
| 332 | J2SE_1_4, |
| 333 | J2SE_1_5, |
| 334 | JAVASE_1_6, |
| 335 | OSGI_MINIMUM_1_0, |
| 336 | OSGI_MINIMUM_1_1, |
| 337 | OSGI_MINIMUM_1_2, |
| 338 | }; |
| 339 | } |
| 340 | } |
| 341 | |