Search in sources :

Example 1 with ActionConfig

use of jodd.madvoc.ActionConfig in project jodd by oblac.

the class ActionMethodParser method parse.

/**
 * Parses java action method annotation and returns its action runtime.
 *
 * @param actionClass action class
 * @param actionMethod action method
 * @param actionDefinition optional action def, usually <code>null</code> so to be parsed
 */
public ActionRuntime parse(final Class<?> actionClass, final Method actionMethod, ActionDefinition actionDefinition) {
    final ActionAnnotationValues annotationValues = detectActionAnnotationValues(actionMethod);
    final ActionConfig actionConfig = resolveActionConfig(annotationValues);
    // interceptors
    final ActionInterceptor[] actionInterceptors = parseActionInterceptors(actionClass, actionMethod, actionConfig);
    // filters
    final ActionFilter[] actionFilters = parseActionFilters(actionClass, actionMethod, actionConfig);
    // build action definition when not provided
    if (actionDefinition == null) {
        actionDefinition = parseActionDefinition(actionClass, actionMethod);
    }
    detectAndRegisterAlias(annotationValues, actionDefinition);
    final boolean async = parseMethodAsyncFlag(actionMethod);
    final boolean auth = parseMethodAuthFlag(actionMethod);
    final Class<? extends ActionResult> actionResult = parseActionResult(actionMethod);
    final Class<? extends ActionResult> defaultActionResult = actionConfig.getActionResult();
    return createActionRuntime(null, actionClass, actionMethod, actionResult, defaultActionResult, actionFilters, actionInterceptors, actionDefinition, async, auth);
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) ActionInterceptor(jodd.madvoc.interceptor.ActionInterceptor) ActionFilter(jodd.madvoc.filter.ActionFilter) ActionAnnotationValues(jodd.madvoc.meta.ActionAnnotationValues)

Example 2 with ActionConfig

use of jodd.madvoc.ActionConfig in project jodd by oblac.

the class ActionConfigManager method createActionConfig.

protected ActionConfig createActionConfig(final Class<? extends ActionConfig> actionConfigClass) {
    try {
        final Constructor<? extends ActionConfig> ctor = actionConfigClass.getDeclaredConstructor();
        final ActionConfig actionConfig = ctor.newInstance();
        contextInjectorComponent.injectContext(actionConfig);
        return actionConfig;
    } catch (final Exception ex) {
        throw new MadvocException("Invalid action configuration class: " + actionConfigClass.getSimpleName(), ex);
    }
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) MadvocException(jodd.madvoc.MadvocException) MadvocException(jodd.madvoc.MadvocException)

Example 3 with ActionConfig

use of jodd.madvoc.ActionConfig in project jodd by oblac.

the class ActionConfigManager method registerNewActionConfiguration.

/**
 * Registers action configuration for given type.
 */
protected ActionConfig registerNewActionConfiguration(final Class<? extends ActionConfig> actionConfigClass) {
    final ActionConfig newActionConfig = createActionConfig(actionConfigClass);
    actionConfigs.put(actionConfigClass, newActionConfig);
    return newActionConfig;
}
Also used : ActionConfig(jodd.madvoc.ActionConfig)

Example 4 with ActionConfig

use of jodd.madvoc.ActionConfig in project jodd by oblac.

the class ActionsManager method lookup.

// ---------------------------------------------------------------- look-up
/**
	 * Returns action configurations for provided action path.
	 * First it lookups for exact <code>actionPath</code>.
	 * If action path is not registered, it is split into chunks
	 * and match against macros.
	 * Returns <code>null</code> if action path is not registered.
	 * <code>method</code> must be in uppercase.
	 */
public ActionConfig lookup(String actionPath, String method) {
    // 1st try: the map
    ActionConfigSet actionConfigSet = map.get(actionPath);
    if (actionConfigSet != null) {
        ActionConfig actionConfig = actionConfigSet.lookup(method);
        if (actionConfig != null) {
            return actionConfig;
        }
    }
    // 2nd try: the list
    int actionPathDeep = StringUtil.count(actionPath, '/');
    int len = list.size();
    int lastMatched = -1;
    int maxMatchedChars = -1;
    for (int i = 0; i < len; i++) {
        actionConfigSet = list.get(i);
        int deep = actionConfigSet.deep;
        if (deep < actionPathDeep) {
            continue;
        }
        if (deep > actionPathDeep) {
            break;
        }
        // same deep level, try the fully match
        int matchedChars = actionConfigSet.actionPathMacros.match(actionPath);
        if (matchedChars == -1) {
            continue;
        }
        if (matchedChars > maxMatchedChars) {
            maxMatchedChars = matchedChars;
            lastMatched = i;
        }
    }
    if (lastMatched < 0) {
        return null;
    }
    ActionConfigSet set = list.get(lastMatched);
    return set.lookup(method);
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) ActionConfigSet(jodd.madvoc.ActionConfigSet)

Example 5 with ActionConfig

use of jodd.madvoc.ActionConfig 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)

Aggregations

ActionConfig (jodd.madvoc.ActionConfig)7 ActionConfigSet (jodd.madvoc.ActionConfigSet)2 MadvocException (jodd.madvoc.MadvocException)2 ActionAnnotationValues (jodd.madvoc.meta.ActionAnnotationValues)2 ScopeData (jodd.madvoc.ScopeData)1 ActionNames (jodd.madvoc.config.ActionNames)1 ActionFilter (jodd.madvoc.filter.ActionFilter)1 ActionInterceptor (jodd.madvoc.interceptor.ActionInterceptor)1 ActionNamingStrategy (jodd.madvoc.path.ActionNamingStrategy)1 AnnotationParser (jodd.util.AnnotationParser)1