Skip to content

Commit d463ed4

Browse files
committed
Fixes #246: make ConstraintValidators injectable
Also removes useless DependencyProvider SPI (for optional dependencies which are now handled directly). Also improves instantiation of the EL ExpressionFactory. Also makes the validation message interpolator automatically adapt to whether the runtime environment supports EL or not.
1 parent 58f0f3d commit d463ed4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+830
-627
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
* [new] Java 9 compatibility.
44
* [new] Refactored and improved integration testing API.
5-
* [brk] Removed Arquillian support (to its own add-on) in favor of Undertow-based Web integration testing.
65
* [fix] Defer JNDI lookup through `@Resource` annotation until the instance containing the injection is created.
7-
6+
* [fix] Fix lack of injection in custom ConstraintValidators.
87

98
# Version 3.4.2 (2018-01-12)
109

core/src/main/java/org/seedstack/seed/core/internal/dependency/DependencyClassProxy.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

core/src/main/java/org/seedstack/seed/core/internal/dependency/DependencyModule.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

core/src/main/java/org/seedstack/seed/core/internal/dependency/DependencyPlugin.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

core/src/main/java/org/seedstack/seed/core/internal/dependency/DependencyProxy.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

core/src/main/java/org/seedstack/seed/core/internal/el/ELContextBuilderImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class ELContextBuilderImpl implements ELContextBuilder {
2929
private ExpressionFactory expressionFactory;
3030

3131
static ELContext createDefaultELContext(ExpressionFactory expressionFactory) {
32-
if (ELPlugin.EL3_OPTIONAL.isPresent()) {
32+
if (ELPlugin.EL_3_CONTEXT_CLASS != null) {
3333
try {
34-
return ELPlugin.EL3_OPTIONAL.get().getConstructor(ExpressionFactory.class).newInstance(
34+
return ELPlugin.EL_3_CONTEXT_CLASS.getConstructor(ExpressionFactory.class).newInstance(
3535
expressionFactory);
3636
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException |
3737
InstantiationException e) {
3838
throw new RuntimeException("Unable to instantiate StandardELContext", e);
3939
}
40-
} else if (ELPlugin.JUEL_OPTIONAL.isPresent()) {
40+
} else if (ELPlugin.JUEL_CONTEXT_CLASS != null) {
4141
try {
42-
return ELPlugin.JUEL_OPTIONAL.get().newInstance();
42+
return ELPlugin.JUEL_CONTEXT_CLASS.newInstance();
4343
} catch (IllegalAccessException | InstantiationException e) {
4444
throw new RuntimeException("Unable to instantiate JUEL SimpleContext", e);
4545
}
@@ -76,12 +76,12 @@ public ELPropertyProvider withProperty(String name, Object object) {
7676
@Override
7777
public ELPropertyProvider withFunction(String prefix, String localName, Method method) {
7878
checkArgument(!Strings.isNullOrEmpty(localName), "A function local name is required");
79-
if (ELPlugin.EL3_OPTIONAL.isPresent()) {
79+
if (ELPlugin.isLevel3()) {
8080
elContext.getFunctionMapper().mapFunction(prefix, localName, method);
81-
} else if (ELPlugin.JUEL_OPTIONAL.isPresent()) {
82-
if (ELPlugin.JUEL_OPTIONAL.get().isAssignableFrom(elContext.getClass())) {
81+
} else if (ELPlugin.JUEL_CONTEXT_CLASS != null) {
82+
if (ELPlugin.JUEL_CONTEXT_CLASS.isAssignableFrom(elContext.getClass())) {
8383
try {
84-
ELPlugin.JUEL_OPTIONAL.get().getMethod("setFunction", String.class, String.class,
84+
ELPlugin.JUEL_CONTEXT_CLASS.getMethod("setFunction", String.class, String.class,
8585
Method.class).invoke(elContext, prefix, localName, method);
8686
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
8787
throw SeedException.wrap(e, ExpressionLanguageErrorCode.UNEXPECTED_EXCEPTION);
@@ -92,7 +92,7 @@ public ELPropertyProvider withFunction(String prefix, String localName, Method m
9292
}
9393
} else {
9494
throw new UnsupportedOperationException(
95-
"Function mapping is not supported in this environment (EL level 3+ required)");
95+
"Function mapping is not supported in this environment (EL level 3+ or JUEL required)");
9696
}
9797
return this;
9898
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright © 2013-2018, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.seed.core.internal.el;
9+
10+
import org.seedstack.shed.exception.ErrorCode;
11+
12+
public enum ELErrorCode implements ErrorCode {
13+
UNABLE_TO_INSTANTIATE_EXPRESSION_FACTORY
14+
}

core/src/main/java/org/seedstack/seed/core/internal/el/ELModule.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
import org.seedstack.seed.el.spi.ELHandler;
2020

2121
class ELModule extends AbstractModule {
22-
private static final TypeLiteral<Map<Class<? extends Annotation>, Class<ELHandler>>> MAP_TYPE_LITERAL = new
23-
TypeLiteral<Map<Class<? extends Annotation>, Class<ELHandler>>>() {
24-
};
22+
private final ExpressionFactory expressionFactory;
2523
private final Map<Class<? extends Annotation>, Class<ELHandler>> elMap;
2624

27-
ELModule(Map<Class<? extends Annotation>, Class<ELHandler>> elMap) {
25+
ELModule(ExpressionFactory expressionFactory, Map<Class<? extends Annotation>, Class<ELHandler>> elMap) {
26+
this.expressionFactory = expressionFactory;
2827
this.elMap = elMap;
2928
}
3029

3130
@Override
3231
protected void configure() {
33-
bind(ExpressionFactory.class).toInstance(ExpressionFactory.newInstance());
32+
bind(ExpressionFactory.class).toInstance(expressionFactory);
3433
bind(ELService.class).to(ELServiceInternal.class);
3534
bind(ELContextBuilder.class).to(ELContextBuilderImpl.class);
3635

@@ -39,6 +38,10 @@ protected void configure() {
3938
}
4039

4140
// bind the map of annotation -> ELHandler
42-
bind(MAP_TYPE_LITERAL).toInstance(ImmutableMap.copyOf(elMap));
41+
bind(new AnnotationHandlersTypeLiteral()).toInstance(ImmutableMap.copyOf(elMap));
42+
}
43+
44+
private static class AnnotationHandlersTypeLiteral
45+
extends TypeLiteral<Map<Class<? extends Annotation>, Class<ELHandler>>> {
4346
}
4447
}

0 commit comments

Comments
 (0)