Skip to content

Commit 8cbae6f

Browse files
committed
chore: add DefaultConditionContext prototype implementation
1 parent 07c8686 commit 8cbae6f

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.otavio.jakarta.cdi.extension;
2+
3+
import com.otavio.jakarta.cdi.ConditionContext;
4+
import jakarta.enterprise.util.TypeLiteral;
5+
6+
import java.lang.annotation.Annotation;
7+
import java.util.logging.Level;
8+
import java.util.logging.Logger;
9+
10+
class DefaultConditionContext implements ConditionContext {
11+
12+
private static final Logger LOGGER = Logger.getLogger(RequiresConditionExtension.class.getName());
13+
14+
@Override
15+
public <T> boolean hasBean(Class<T> type, Annotation... qualifiers) {
16+
LOGGER.log(Level.FINE,
17+
"ConditionContext.hasBean(Class, Annotation...) is not implemented "
18+
+ "in this prototype. Returning false for type {0}.",
19+
type.getName());
20+
return false;
21+
}
22+
23+
@Override
24+
public <T> boolean hasBean(TypeLiteral<T> type, Annotation... qualifiers) {
25+
LOGGER.log(Level.FINE,
26+
"ConditionContext.hasBean(TypeLiteral, Annotation...) is not implemented "
27+
+ "in this prototype. Returning false for type {0}.",
28+
type.getType());
29+
return false;
30+
}
31+
32+
@Override
33+
public <T> boolean hasClass(Class<T> type) {
34+
return type != null;
35+
}
36+
37+
@Override
38+
public boolean hasClasspathResource(String path) {
39+
if (path == null || path.isBlank()) {
40+
return false;
41+
}
42+
43+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
44+
45+
if (classLoader == null) {
46+
classLoader = RequiresConditionExtension.class.getClassLoader();
47+
}
48+
49+
return classLoader.getResource(path) != null;
50+
}
51+
}

0 commit comments

Comments
 (0)