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);
}
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);
}
}
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;
}
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);
}
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);
}
}
}
}
}
Aggregations