/** * Convenience method to determine if the current JVM is at least * Java 1.5 (Java 5). * @return <code>true</code> if the current JVM is at least Java 1.5 * @see #getMajorJavaVersion() * @see #JAVA_15 * @see #JAVA_16 * @see #JAVA_17 */ public static boolean isAtLeastJava15() { return getMajorJavaVersion() >= JAVA_15; }
/** * Convenience method to determine if the current JVM is at least * Java 1.6 (Java 6). * @return <code>true</code> if the current JVM is at least Java 1.6 * @see #getMajorJavaVersion() * @see #JAVA_16 * @see #JAVA_17 */ public static boolean isAtLeastJava16() { return getMajorJavaVersion() >= JAVA_16; }
private boolean isJdk5Enum(Class type) { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) { return type.isEnum(); } else { return false; } }
public static Class<?> getAnnotationTransactionAttributeSourceClass() { if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) { throw new IllegalStateException( "AnnotationTransactionAttributeSource is only available on Java 1.5 and higher"); } try { return ClassUtils.forName( ANNOTATION_TRANSACTION_ATTRIBUTE_SOURCE_CLASS_NAME, TxNamespaceUtils.class.getClassLoader()); } catch (Throwable ex) { throw new IllegalStateException("Unable to load Java 1.5 dependent class [" + ANNOTATION_TRANSACTION_ATTRIBUTE_SOURCE_CLASS_NAME + "]", ex); } }
private boolean isJdk5Enum(Class type) { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) { return EnumUtils.isEnum(type); } else { return false; } }
public DefaultVisitor() { if (JdkVersion.getMajorJavaVersion() != JdkVersion.JAVA_13) { this.dateParser = new DefaultDateParser(); } }
public static void dumpThreads(StringBuilder msg) { try { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_16) { Class<?> dumperClass = Class.forName("org.artifactory.thread.ThreadDumper"); Object dumper = dumperClass.newInstance(); Method method = dumperClass.getDeclaredMethod("dumpThreads"); CharSequence dump = (CharSequence) method.invoke(dumper); log.info("Printing locking debug information..."); msg.append("\n").append(dump); } } catch (Throwable t) { log.info("Could not dump threads", t); } } }
/** * Create a linked set if possible: that is, if running on JDK >= 1.4 * or if Commons Collections 3.x is available. Prefers a JDK 1.4+ * LinkedHashSet to a Commons Collections 3.x ListOrderedSet. * @param initialCapacity the initial capacity of the set * @return the new set instance * @see java.util.LinkedHashSet * @see org.apache.commons.collections.set.ListOrderedSet */ public static Set createLinkedSetIfPossible(int initialCapacity) { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_14) { logger.debug("Creating [java.util.LinkedHashSet]"); return Jdk14CollectionFactory.createLinkedHashSet(initialCapacity); } else if (commonsCollections3xAvailable) { logger.debug("Creating [org.apache.commons.collections.set.ListOrderedSet]"); return CommonsCollectionFactory.createListOrderedSet(initialCapacity); } else { logger.debug("Falling back to [java.util.HashSet] for linked set"); return new HashSet(initialCapacity); } }
/** * Create an identity map if possible: that is, if running on JDK >= 1.4 * or if Commons Collections 3.x is available. Prefers a JDK 1.4+ * IdentityHashMap to a Commons Collections 3.x IdentityMap. * @param initialCapacity the initial capacity of the map * @return the new map instance * @see java.util.IdentityHashMap * @see org.apache.commons.collections.map.IdentityMap */ public static Map createIdentityMapIfPossible(int initialCapacity) { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_14) { logger.debug("Creating [java.util.IdentityHashMap]"); return Jdk14CollectionFactory.createIdentityHashMap(initialCapacity); } else if (commonsCollections3xAvailable) { logger.debug("Creating [org.apache.commons.collections.map.IdentityMap]"); return CommonsCollectionFactory.createIdentityMap(initialCapacity); } else { logger.debug("Falling back to [java.util.HashMap] for identity map"); return new HashMap(initialCapacity); } }
/** * Create a linked map if possible: that is, if running on JDK >= 1.4 * or if Commons Collections 3.x is available. Prefers a JDK 1.4+ * LinkedHashMap to a Commons Collections 3.x LinkedMap. * @param initialCapacity the initial capacity of the map * @return the new map instance * @see java.util.LinkedHashMap * @see org.apache.commons.collections.map.LinkedMap */ public static Map createLinkedMapIfPossible(int initialCapacity) { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_14) { logger.debug("Creating [java.util.LinkedHashMap]"); return Jdk14CollectionFactory.createLinkedHashMap(initialCapacity); } else if (commonsCollections3xAvailable) { logger.debug("Creating [org.apache.commons.collections.map.LinkedMap]"); return CommonsCollectionFactory.createLinkedMap(initialCapacity); } else { logger.debug("Falling back to [java.util.HashMap] for linked map"); return new HashMap(initialCapacity); } }
/** * Create a linked case-insensitive map if possible: if Commons Collections * 3.x is available, a CaseInsensitiveMap with ListOrderedMap decorator will * be created. Else, a JDK 1.4+ LinkedHashMap or plain HashMap will be used. * @param initialCapacity the initial capacity of the map * @return the new map instance * @see org.apache.commons.collections.map.CaseInsensitiveMap * @see org.apache.commons.collections.map.ListOrderedMap */ public static Map createLinkedCaseInsensitiveMapIfPossible(int initialCapacity) { if (commonsCollections3xAvailable) { logger.debug("Creating [org.apache.commons.collections.map.ListOrderedMap/CaseInsensitiveMap]"); return CommonsCollectionFactory.createListOrderedCaseInsensitiveMap(initialCapacity); } else if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_14) { logger.debug("Falling back to [java.util.LinkedHashMap] for linked case-insensitive map"); return Jdk14CollectionFactory.createLinkedHashMap(initialCapacity); } else { logger.debug("Falling back to [java.util.HashMap] for linked case-insensitive map"); return new HashMap(initialCapacity); } }
private ConversationId nextId() { if (JdkVersion.getMajorJavaVersion() == JdkVersion.JAVA_15) { return new SimpleConversationId(Integer.valueOf(++conversationIdSequence)); } else { return new SimpleConversationId(new Integer(++conversationIdSequence)); } }
/** * URL-encode the given input String with the configured encoding scheme. * <p> * Default implementation uses <code>URLEncoder.encode(input, enc)</code> on JDK 1.4+, falling back to * <code>URLEncoder.encode(input)</code> (which uses the platform default encoding) on JDK 1.3. * @param input the unencoded input String * @return the encoded output String */ private String urlEncode(String input) { if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_14) { return URLEncoder.encode(input); } try { return URLEncoder.encode(input, getUrlEncodingScheme()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Cannot encode URL " + input); } } }
/** * Find the root cause of given throwable. */ protected Throwable findRootCause(Throwable t) { if (JdkVersion.getMajorJavaVersion() == JdkVersion.JAVA_13) { return findRootCause13(t); } else { return findRootCause14(t); } }
public static ControlFlow createControlFlow() { return JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_14 ? (ControlFlow) new Jdk14ControlFlow() : (ControlFlow) new Jdk13ControlFlow(); }
/** * Find the mapped target state resolver for given exception. Returns <code>null</code> if no mapping can be found * for given exception. Will try all exceptions in the exception cause chain. */ protected TargetStateResolver getTargetStateResolver(FlowExecutionException e) { if (JdkVersion.getMajorJavaVersion() == JdkVersion.JAVA_13) { return getTargetStateResolver13(e); } else { return getTargetStateResolver14(e); } }
/** * When running on Java 1.5+, returns a jdk5 concurrent lock. When running on older JDKs with the 'util.concurrent' * package available, returns a util concurrent lock. In all other cases a "no-op" lock is returned. */ public static ConversationLock createLock() { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) { return new JdkConcurrentConversationLock(); } else if (utilConcurrentPresent) { return new UtilConcurrentConversationLock(); } else { logger.warn("Unable to enable conversation locking. Switch to Java 5 or above, " + "or put the 'util.concurrent' package on the classpath " + "to enable locking in your environment."); return NoOpConversationLock.INSTANCE; } } }
/** * Create the actual pointcut: by default, a Perl5RegexpMethodPointcut * will be created if Perl5 syntax is enforced or when running on JDK 1.3. * Else, a JdkRegexpMethodPointcut (JDK 1.4+) will be used. * @see #setPerl5 * @see Perl5RegexpMethodPointcut * @see JdkRegexpMethodPointcut */ protected AbstractRegexpMethodPointcut createPointcut() { if (this.perl5 || JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_14) { logger.debug("Creating Perl5RegexpMethodPointcut (Jakarta ORO needs to be available)"); // needs Jakarta ORO on the classpath return new Perl5RegexpMethodPointcut(); } else { logger.debug("Creating JdkRegexpMethodPointcut"); // needs to run on JDK >= 1.4 return new JdkRegexpMethodPointcut(); } }
/** * When running on Java 1.5+, returns a jdk5 concurrent lock. When running on older JDKs with the * 'backport-util-concurrent' package available, returns a backport concurrent lock. In all other cases a "no-op" * lock is returned. */ public ConversationLock createLock() { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) { return new JdkConcurrentConversationLock(timeoutSeconds); } else if (backportConcurrentPresent) { return new JdkBackportConcurrentConversationLock(timeoutSeconds); } else { logger.warn("Unable to enable conversation locking. Switch to Java 5 or above, " + "or put the 'backport-util-concurrent' package on the classpath " + "to enable locking in your Java 1.4 environment."); return NoOpConversationLock.INSTANCE; } } }
/** * Constructor for use as a JavaBean. * The SqlErrorCodes or DataSource property must be set. */ public SQLErrorCodeSQLExceptionTranslator() { if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_16) { setFallbackTranslator(new SQLExceptionSubclassTranslator()); } else { setFallbackTranslator(new SQLStateSQLExceptionTranslator()); } }