use of jodd.madvoc.ScopeData in project jodd by oblac.
the class ContextInjectorComponent method injectContext.
/**
* Inject context into target.
*/
public void injectContext(Target target) {
Class targetType = target.resolveType();
ScopeData[] scopeData = scopeDataResolver.resolveScopeData(targetType);
ServletContext servletContext = madvocController.getApplicationContext();
injectorsManager.getMadvocContextScopeInjector().injectContext(target, scopeData, madpc);
injectorsManager.getMadvocParamsInjector().injectContext(target, scopeData, madpc);
injectorsManager.getServletContextScopeInjector().injectContext(target, scopeData, servletContext);
injectorsManager.getApplicationScopeInjector().injectContext(target, scopeData, servletContext);
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class ScopeDataResolver method resolveScopeData.
/**
* Resolves scope data in given annotations for all scope types.
* Returns <code>null</code> if no scope data exist.
*/
public ScopeData[] resolveScopeData(String name, Class type, Annotation[] annotations) {
final ScopeType[] allScopeTypes = ScopeType.values();
ScopeData[] scopeData = new ScopeData[allScopeTypes.length];
int count = 0;
for (ScopeType scopeType : allScopeTypes) {
ScopeData sd = inspectMethodParameterScopeData(name, type, annotations, scopeType);
if (sd != null) {
count++;
}
scopeData[scopeType.value()] = sd;
}
if (count == 0) {
return null;
}
return scopeData;
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class ActionPathMacroInjector method inject.
public void inject(ActionRequest actionRequest) {
ActionConfig config = actionRequest.getActionConfig();
ActionConfigSet set = config.getActionConfigSet();
if (set.actionPathMacros == null) {
// no action path macros at all, just exit
return;
}
ScopeData[] injectData = lookupScopeData(actionRequest);
if (injectData == null) {
return;
}
// inject
Target[] targets = actionRequest.getTargets();
String[] names = set.actionPathMacros.getNames();
String[] values = set.actionPathMacros.extract(actionRequest.getActionPath());
for (int ndx = 0; ndx < values.length; ndx++) {
String value = values[ndx];
if (StringUtil.isEmpty(value)) {
continue;
}
String macroName = names[ndx];
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (injectData[i] == null) {
continue;
}
ScopeData.In[] scopes = injectData[i].in;
if (scopes == null) {
continue;
}
for (ScopeData.In in : scopes) {
String name = getMatchedPropertyName(in, macroName);
if (name != null) {
setTargetProperty(target, name, value);
}
}
}
}
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class ApplicationScopeInjector method inject.
public void inject(ActionRequest actionRequest) {
Target[] targets = actionRequest.getTargets();
ScopeData[] injectData = lookupScopeData(actionRequest);
if (injectData == null) {
return;
}
ServletContext servletContext = actionRequest.getHttpServletRequest().getSession().getServletContext();
Enumeration attributeNames = servletContext.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String attrName = (String) attributeNames.nextElement();
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (injectData[i] == null) {
continue;
}
ScopeData.In[] scopes = injectData[i].in;
if (scopes == null) {
continue;
}
for (ScopeData.In in : scopes) {
String name = getMatchedPropertyName(in, attrName);
if (name != null) {
Object attrValue = servletContext.getAttribute(attrName);
setTargetProperty(target, name, attrValue);
}
}
}
}
}
use of jodd.madvoc.ScopeData in project jodd by oblac.
the class RequestScopeInjector method injectAttributes.
// ---------------------------------------------------------------- inject
/**
* Inject request attributes.
*/
protected void injectAttributes(Target[] targets, ScopeData[] injectData, HttpServletRequest servletRequest) {
Enumeration attributeNames = servletRequest.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String attrName = (String) attributeNames.nextElement();
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (injectData[i] == null) {
continue;
}
ScopeData.In[] scopes = injectData[i].in;
if (scopes == null) {
continue;
}
for (ScopeData.In in : scopes) {
String name = getMatchedPropertyName(in, attrName);
if (name != null) {
Object attrValue = servletRequest.getAttribute(attrName);
setTargetProperty(target, name, attrValue);
}
}
}
}
}
Aggregations