Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-1767 Optimize how optional features are detected
- Loading branch information
Showing
2 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...src/main/java/org/hibernate/validator/internal/util/privilegedactions/IsClassPresent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.internal.util.privilegedactions; | ||
|
||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* Checks if an external class is present in the provided class loader. | ||
*/ | ||
public final class IsClassPresent implements PrivilegedAction<Boolean> { | ||
|
||
private final String className; | ||
|
||
private final ClassLoader classLoader; | ||
|
||
public static IsClassPresent action(String className, ClassLoader classLoader) { | ||
return new IsClassPresent( className, classLoader ); | ||
} | ||
|
||
private IsClassPresent(String className, ClassLoader classLoader) { | ||
this.className = className; | ||
this.classLoader = classLoader; | ||
} | ||
|
||
@Override | ||
public Boolean run() { | ||
try { | ||
Class.forName( className, false, classLoader ); | ||
return Boolean.TRUE; | ||
} | ||
catch (ClassNotFoundException e) { | ||
return Boolean.FALSE; | ||
} | ||
} | ||
} |