public void inject(final ServletContext servletContext, final Targets targets) { targets.forEachTargetAndIn(madvocScope, (target, in) -> { final Class inType = in.type(); Object value = null; if (inType == ServletContext.class) { value = servletContext; } if (value != null) { target.writeValue(in, value, true); } }); }
/** * Creates a common target over a method param. */ public static Target ofMethodParam(final MethodParam methodParam, final Object object) { return new Target(object, methodParam.type(), methodParam.scopeData(), methodParam.mapperFunction(), VALUE_INSTANCE_CREATOR); } /**
/** * Reads value from the target. If something goes wrong, exception * is thrown. We assume that outjection is controlled by developer * and that each reading of a value must be a successful operation. */ public Object readValue(final InjectionPoint injectionPoint) { return readValue(injectionPoint.targetName()); } public Object readValue(final String name) {
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final HttpServletResponse servletResponse = actionRequest.getHttpServletResponse(); targets.forEachTargetAndOut(this, (target, out) -> { final String value = (String) target.readValue(out); if (value != null) { servletResponse.setHeader(out.name(), value); } }); } }
@Override public void inject(final Targets targets) { targets.forEachTargetAndIn(this, (target, in) -> { final Object value = madpc.getBean(in.name()); if (value != null) { target.writeValue(in, value, false); } }); }
public Targets(final ActionRequest actionRequest) { targets = makeTargets( Target.ofValue(actionRequest.getAction(), actionRequest.getActionRuntime().getScopeData()), actionRequest.getActionRuntime().getMethodParams()); }
/** * Writes value to this target. Depending on a flag, writing the value can be * completely silent, when no exception is thrown and with top performances. * Otherwise, an exception is thrown on a failure. */ public void writeValue(final InjectionPoint injectionPoint, final Object propertyValue, final boolean silent) { writeValue(injectionPoint.targetName(), propertyValue, silent); } public void writeValue(final String name, final Object propertyValue, final boolean silent) {
private ActionRuntime lookupFrom(final RouteChunk chunk, final String[] path) { // matched, scan children RouteChunk[] children = chunk.children(); if (children == null) { return null; } for (RouteChunk child : children) { ActionRuntime matched = match(child, path, 0); if (matched != null) { return matched; } } return null; }
@Override public String toString() { return pathValue(); }
protected RouteChunk(final Routes routes, final RouteChunk parent, final String value) { this.routes = routes; this.parent = parent; this.value = value; this.pathMacros = routes.buildActionPathMacros(value); if (pathMacros != null) { this.hasMacros = true; } else { this.hasMacros = parent != null && parent.hasMacros; } }
/** * Collects all parameters from target into an array. */ public Object[] extractParametersValues() { final Object[] values = new Object[targets.length - 1]; for (int i = 1; i < targets.length; i++) { values[i - 1] = targets[i].value(); } return values; }
/** * Creates a common target over a value, with known scope data. */ public static Target ofValue(final Object value, final ScopeData scopeData) { return new Target(value, null, scopeData, null, VALUE_INSTANCE_CREATOR); } /**
/** * Binds chunk to an action runtime. */ public void bind(final ActionRuntime actionRuntime) { this.actionRuntime = actionRuntime; this.actionRuntime.bind(this); }
@Override public String toString() { return "action: " + actionPath + (actionMethod == null ? "" : '#' + actionMethod) + " --> " + createActionString(); }
public Routes(final ActionsManager actionsManager) { this.root = new RouteChunk(this, null, StringPool.EMPTY); this.actionsManager = actionsManager; }
public ScopeDataInspector() { NO_SCOPE_DATA = new ScopeData(this, null, null); }
public Targets(final Object actionOrTarget, final ScopeData scopeData) { targets = new Target[]{Target.ofValue(actionOrTarget, scopeData)}; }
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); targets.forEachTargetAndOut(this, (target, out) -> { final Object value = target.readValue(out); servletRequest.setAttribute(out.name(), value); }); }
/** * Creates a common target over a method param. */ public static Target ofMethodParam(final MethodParam methodParam, final Function<Class, Object> valueInstanceCreator) { return new Target(null, methodParam.type(), methodParam.scopeData(), methodParam.mapperFunction(), valueInstanceCreator); }
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final ServletContext context = actionRequest.getHttpServletRequest().getServletContext(); targets.forEachTargetAndOut(this, (target, out) -> { final Object value = target.readValue(out); context.setAttribute(out.name(), value); }); }