Search in sources :

Example 1 with MadvocException

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;
}
Also used : ClassDescriptor(jodd.introspector.ClassDescriptor) PropertyDescriptor(jodd.introspector.PropertyDescriptor) In(jodd.madvoc.meta.In) ArrayList(java.util.ArrayList) Out(jodd.madvoc.meta.Out) InOut(jodd.madvoc.meta.InOut) ScopeData(jodd.madvoc.ScopeData) InOut(jodd.madvoc.meta.InOut) MadvocException(jodd.madvoc.MadvocException)

Example 2 with MadvocException

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);
}
Also used : ActionNamingStrategy(jodd.madvoc.path.ActionNamingStrategy) Target(jodd.madvoc.injector.Target) ActionNames(jodd.madvoc.ActionNames) ActionAnnotationData(jodd.madvoc.meta.ActionAnnotationData) MadvocException(jodd.madvoc.MadvocException) MadvocException(jodd.madvoc.MadvocException)

Example 3 with MadvocException

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

Example 4 with MadvocException

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);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) MadvocException(jodd.madvoc.MadvocException) MadvocException(jodd.madvoc.MadvocException)

Example 5 with MadvocException

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

Aggregations

MadvocException (jodd.madvoc.MadvocException)9 ArrayList (java.util.ArrayList)2 File (java.io.File)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 ServletContext (javax.servlet.ServletContext)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 PropertyDescriptor (jodd.introspector.PropertyDescriptor)1 ActionConfigSet (jodd.madvoc.ActionConfigSet)1 ActionNames (jodd.madvoc.ActionNames)1 BaseActionWrapperStack (jodd.madvoc.BaseActionWrapperStack)1 ScopeData (jodd.madvoc.ScopeData)1 Target (jodd.madvoc.injector.Target)1 ActionAnnotationData (jodd.madvoc.meta.ActionAnnotationData)1 In (jodd.madvoc.meta.In)1 InOut (jodd.madvoc.meta.InOut)1 Out (jodd.madvoc.meta.Out)1 ActionNamingStrategy (jodd.madvoc.path.ActionNamingStrategy)1 ActionResult (jodd.madvoc.result.ActionResult)1