use of jodd.madvoc.config.Targets in project jodd by oblac.
the class ContextInjectorComponent method injectContext.
/**
* Inject context into target.
*/
public void injectContext(final Object targetObject) {
final Class targetType = targetObject.getClass();
final ScopeData scopeData = scopeDataInspector.inspectClassScopesWithCache(targetType);
final Targets targets = new Targets(targetObject, scopeData);
// inject no context
scopeResolver.forEachScope(madvocScope -> madvocScope.inject(targets));
// inject special case
scopeResolver.forScope(ParamsScope.class, scope -> scope.inject(targets));
// inject servlet context
final ServletContext servletContext = madvocController.getApplicationContext();
if (servletContext != null) {
scopeResolver.forEachScope(madvocScope -> madvocScope.inject(servletContext, targets));
}
}
use of jodd.madvoc.config.Targets in project jodd by oblac.
the class ServletConfigInterceptor method inject.
/**
* Performs injection.
*/
protected void inject(final ActionRequest actionRequest) {
final Targets targets = actionRequest.getTargets();
final ServletContext servletContext = actionRequest.getHttpServletRequest().getServletContext();
scopeResolver.forEachScope(madvocScope -> madvocScope.inject(servletContext, targets));
scopeResolver.forEachScope(madvocScope -> madvocScope.inject(actionRequest, targets));
// insert all default values
targets.forEachTargetAndIn((target, injectionPoint) -> {
final String defaultValue = injectionPoint.defaultValue();
if (!defaultValue.isEmpty()) {
final Object value = target.readValue(injectionPoint);
if (value == null) {
target.writeValue(injectionPoint, defaultValue, true);
}
}
});
}
use of jodd.madvoc.config.Targets in project jodd by oblac.
the class ServletConfigInterceptor method outject.
/**
* Performs outjection.
*/
protected void outject(final ActionRequest actionRequest) {
final Targets targets = actionRequest.getTargets();
scopeResolver.forEachScope(madvocScope -> madvocScope.outject(actionRequest, targets));
}
use of jodd.madvoc.config.Targets in project jodd by oblac.
the class MadvocParamsInjectorTest method testInjection.
@Test
void testInjection() {
WebApp webapp = new WebApp();
webapp.start();
PetiteContainer madpc = webapp.madvocContainer().getPetiteContainer();
String baseName = StringUtil.uncapitalize(FooBean.class.getSimpleName());
madpc.defineParameter("foo", "1");
madpc.defineParameter(baseName + ".integer", "173");
madpc.defineParameter(baseName + ".string", "jodd");
madpc.defineParameter(baseName, "huh");
ParamsScope paramsScope = new ParamsScope();
BeanUtil.declared.setProperty(paramsScope, "madpc", madpc);
FooBean fooBean = new FooBean();
paramsScope.inject(new Targets(fooBean, null));
assertEquals(173, fooBean.getInteger().intValue());
assertEquals("jodd", fooBean.getString());
}
Aggregations