use of jodd.madvoc.MadvocException in project jodd by oblac.
the class ScopeDataResolver method inspectClassScopeData.
/**
* Inspect action for all In/Out annotations.
* Returns <code>null</code> if there are no In and Out data.
*/
protected ScopeData inspectClassScopeData(Class actionClass, ScopeType scopeType) {
ClassDescriptor cd = ClassIntrospector.lookup(actionClass);
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
List<ScopeData.In> listIn = new ArrayList<>(allProperties.length);
List<ScopeData.Out> listOut = new ArrayList<>(allProperties.length);
for (PropertyDescriptor pd : allProperties) {
// collect annotations
In in = null;
if (pd.getFieldDescriptor() != null) {
in = pd.getFieldDescriptor().getField().getAnnotation(In.class);
}
if (in == null && pd.getWriteMethodDescriptor() != null) {
in = pd.getWriteMethodDescriptor().getMethod().getAnnotation(In.class);
}
if (in == null && pd.getReadMethodDescriptor() != null) {
in = pd.getReadMethodDescriptor().getMethod().getAnnotation(In.class);
}
InOut inout = null;
if (pd.getFieldDescriptor() != null) {
inout = pd.getFieldDescriptor().getField().getAnnotation(InOut.class);
}
if (inout == null && pd.getWriteMethodDescriptor() != null) {
inout = pd.getWriteMethodDescriptor().getMethod().getAnnotation(InOut.class);
}
if (inout == null && pd.getReadMethodDescriptor() != null) {
inout = pd.getReadMethodDescriptor().getMethod().getAnnotation(InOut.class);
}
Out out = null;
if (pd.getFieldDescriptor() != null) {
out = pd.getFieldDescriptor().getField().getAnnotation(Out.class);
}
if (out == null && pd.getWriteMethodDescriptor() != null) {
out = pd.getWriteMethodDescriptor().getMethod().getAnnotation(Out.class);
}
if (out == null && pd.getReadMethodDescriptor() != null) {
out = pd.getReadMethodDescriptor().getMethod().getAnnotation(Out.class);
}
if (inout != null) {
if (in != null || out != null) {
throw new MadvocException("@InOut can not be used with @In or @Out: " + pd.getClassDescriptor().getClass() + '#' + pd.getName());
}
}
// inspect all
ScopeData.In ii = inspectIn(in, scopeType, pd.getName(), pd.getType());
if (ii != null) {
listIn.add(ii);
}
ii = inspectIn(inout, scopeType, pd.getName(), pd.getType());
if (ii != null) {
listIn.add(ii);
}
ScopeData.Out oi = inspectOut(out, scopeType, pd.getName(), pd.getType());
if (oi != null) {
listOut.add(oi);
}
oi = inspectOut(inout, scopeType, pd.getName(), pd.getType());
if (oi != null) {
listOut.add(oi);
}
}
if ((listIn.isEmpty()) && (listOut.isEmpty())) {
return null;
}
ScopeData scopeData = new ScopeData();
if (!listIn.isEmpty()) {
scopeData.in = listIn.toArray(new ScopeData.In[listIn.size()]);
}
if (!listOut.isEmpty()) {
scopeData.out = listOut.toArray(new ScopeData.Out[listOut.size()]);
}
return scopeData;
}
use of jodd.madvoc.MadvocException in project jodd by oblac.
the class ActionMethodParser method parseActionDef.
/**
* Parses action class and method and creates {@link jodd.madvoc.ActionDef parsed action definition}.
*/
public ActionDef parseActionDef(final Class<?> actionClass, final Method actionMethod) {
ActionAnnotationData annotationData = detectActionAnnotationData(actionMethod);
// collector for all action names
final ActionNames actionNames = new ActionNames();
readPackageActionPath(actionNames, actionClass);
readClassActionPath(actionNames, actionClass);
readMethodActionPath(actionNames, actionMethod.getName(), annotationData);
readMethodExtension(actionNames, annotationData);
readMethodHttpMethod(actionNames, annotationData);
final Class<? extends ActionNamingStrategy> actionPathNamingStrategy = parseMethodNamingStrategy(annotationData);
ActionNamingStrategy namingStrategy;
try {
namingStrategy = actionPathNamingStrategy.newInstance();
contextInjectorComponent.injectContext(new Target(namingStrategy));
} catch (Exception ex) {
throw new MadvocException(ex);
}
return namingStrategy.buildActionDef(actionClass, actionMethod, actionNames);
}
use of jodd.madvoc.MadvocException in project jodd by oblac.
the class ActionsManager method registerAction.
/**
* Registers manually created {@link ActionConfig action configurations}.
* Optionally, if action path with the same name already exist,
* exception will be thrown.
*/
public ActionConfig registerAction(ActionConfig actionConfig) {
String actionPath = actionConfig.actionPath;
if (log.isDebugEnabled()) {
log.debug("Registering Madvoc action: " + actionConfig.actionPath + " to: " + actionConfig.getActionString());
}
ActionConfigSet set = createActionConfigSet(actionConfig.actionPath);
if (set.actionPathMacros != null) {
// new action patch contain macros
int ndx = -1;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).actionPath.equals(actionPath)) {
ndx = i;
break;
}
}
if (ndx < 0) {
list.add(set);
} else {
set = list.get(ndx);
}
} else {
// action path is without macros
if (!map.containsKey(actionConfig.actionPath)) {
map.put(actionConfig.actionPath, set);
} else {
set = map.get(actionConfig.actionPath);
}
}
boolean isDuplicate = set.add(actionConfig);
if (madvocConfig.isDetectDuplicatePathsEnabled()) {
if (isDuplicate) {
throw new MadvocException("Duplicate action path for " + actionConfig);
}
}
// finally
configs.put(actionConfig.getActionString(), actionConfig);
if (!isDuplicate) {
actionsCount++;
}
// async check
if (actionConfig.isAsync()) {
asyncMode = true;
}
return actionConfig;
}
use of jodd.madvoc.MadvocException in project jodd by oblac.
the class Target method createValueInstance.
/**
* Creates new instance of a type and stores it in the value.
*/
@SuppressWarnings({ "unchecked", "NullArgumentToVariableArgMethod" })
protected void createValueInstance() {
try {
Constructor ctor = type.getDeclaredConstructor(null);
ctor.setAccessible(true);
value = ctor.newInstance();
} catch (Exception ex) {
throw new MadvocException(ex);
}
}
use of jodd.madvoc.MadvocException in project jodd by oblac.
the class AutomagicMadvocConfigurator method configure.
/**
* Configures web application from specified classpath. The whole process is done in the following steps:
* <ol>
* <li>scanning web application classpath</li>
* <li>invoking external configurations, if exist</li>
* <li>applying defaults</li>
* </ol>
* @see #configure()
*/
public void configure(File[] classpath) {
elapsed = System.currentTimeMillis();
rulesEntries.smartMode();
try {
scanPaths(classpath);
} catch (Exception ex) {
throw new MadvocException("Scan classpath error", ex);
}
elapsed = System.currentTimeMillis() - elapsed;
log.info("Madvoc configured in " + elapsed + " ms. Total actions: " + actionsManager.getActionsCount());
}
Aggregations