Search in sources :

Example 11 with ScopeData

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);
}
Also used : ScopeData(jodd.madvoc.ScopeData) ServletContext(javax.servlet.ServletContext)

Example 12 with ScopeData

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;
}
Also used : ScopeType(jodd.madvoc.ScopeType) ScopeData(jodd.madvoc.ScopeData)

Example 13 with 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);
                }
            }
        }
    }
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) ActionConfigSet(jodd.madvoc.ActionConfigSet) ScopeData(jodd.madvoc.ScopeData)

Example 14 with ScopeData

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);
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ScopeData(jodd.madvoc.ScopeData) ServletContext(javax.servlet.ServletContext)

Example 15 with ScopeData

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);
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ScopeData(jodd.madvoc.ScopeData)

Aggregations

ScopeData (jodd.madvoc.ScopeData)21 Enumeration (java.util.Enumeration)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ServletContext (javax.servlet.ServletContext)4 In (jodd.madvoc.meta.In)4 Out (jodd.madvoc.meta.Out)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 ScopeType (jodd.madvoc.ScopeType)2 ScopeDataResolver (jodd.madvoc.component.ScopeDataResolver)2 InOut (jodd.madvoc.meta.InOut)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 Cookie (javax.servlet.http.Cookie)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 PropertyDescriptor (jodd.introspector.PropertyDescriptor)1 ActionConfig (jodd.madvoc.ActionConfig)1 ActionConfigSet (jodd.madvoc.ActionConfigSet)1