Search in sources :

Example 6 with MethodParameterInfo

use of com.haulmont.cuba.core.app.scheduled.MethodParameterInfo in project cuba by cuba-platform.

the class AbstractBeansMetadata method getAvailableMethods.

protected List<MethodInfo> getAvailableMethods(String beanName) {
    List<MethodInfo> methods = new ArrayList<>();
    try {
        AutowireCapableBeanFactory beanFactory = AppContext.getApplicationContext().getAutowireCapableBeanFactory();
        if (beanFactory instanceof CubaDefaultListableBeanFactory) {
            BeanDefinition beanDefinition = ((CubaDefaultListableBeanFactory) beanFactory).getBeanDefinition(beanName);
            if (beanDefinition.isAbstract())
                return methods;
        }
        Object bean = AppBeans.get(beanName);
        @SuppressWarnings("unchecked") List<Class> classes = ClassUtils.getAllInterfaces(bean.getClass());
        for (Class aClass : classes) {
            if (aClass.getName().startsWith("org.springframework."))
                continue;
            Class<?> targetClass = bean instanceof TargetClassAware ? ((TargetClassAware) bean).getTargetClass() : bean.getClass();
            for (Method method : aClass.getMethods()) {
                if (isMethodAvailable(method)) {
                    Method targetClassMethod = targetClass.getMethod(method.getName(), method.getParameterTypes());
                    List<MethodParameterInfo> methodParameters = getMethodParameters(targetClassMethod);
                    MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters);
                    addMethod(methods, methodInfo);
                }
            }
            if (methods.isEmpty()) {
                for (Method method : bean.getClass().getMethods()) {
                    if (!method.getDeclaringClass().equals(Object.class) && isMethodAvailable(method)) {
                        List<MethodParameterInfo> methodParameters = getMethodParameters(method);
                        MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters);
                        addMethod(methods, methodInfo);
                    }
                }
            }
        }
    } catch (Throwable t) {
        log.debug(t.getMessage());
    }
    return methods;
}
Also used : TargetClassAware(org.springframework.aop.TargetClassAware) CubaDefaultListableBeanFactory(com.haulmont.cuba.core.sys.CubaDefaultListableBeanFactory) Method(java.lang.reflect.Method) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) MethodInfo(com.haulmont.cuba.core.app.scheduled.MethodInfo) MethodParameterInfo(com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)

Example 7 with MethodParameterInfo

use of com.haulmont.cuba.core.app.scheduled.MethodParameterInfo in project cuba by cuba-platform.

the class ScheduledTask method updateMethodParameters.

public void updateMethodParameters(List<MethodParameterInfo> params) {
    Document doc = DocumentHelper.createDocument();
    Element paramsEl = doc.addElement("params");
    for (MethodParameterInfo param : params) {
        Element paramEl = paramsEl.addElement("param");
        paramEl.addAttribute("type", param.getType().getName());
        paramEl.addAttribute("name", param.getName());
        paramEl.setText(param.getValue() != null ? param.getValue().toString() : "");
    }
    setMethodParamsXml(Dom4j.writeDocument(doc, true));
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document) MethodParameterInfo(com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)

Example 8 with MethodParameterInfo

use of com.haulmont.cuba.core.app.scheduled.MethodParameterInfo in project cuba by cuba-platform.

the class ScheduledTask method getMethodParametersString.

@MetaProperty
public String getMethodParametersString() {
    StringBuilder sb = new StringBuilder();
    int count = 0;
    List<MethodParameterInfo> parameters = getMethodParameters();
    for (MethodParameterInfo param : parameters) {
        sb.append(param.getType().getSimpleName()).append(" ").append(param.getName()).append(" = ").append(param.getValue());
        if (++count != parameters.size())
            sb.append(", ");
    }
    return sb.toString();
}
Also used : MethodParameterInfo(com.haulmont.cuba.core.app.scheduled.MethodParameterInfo) MetaProperty(com.haulmont.chile.core.annotations.MetaProperty)

Aggregations

MethodParameterInfo (com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)8 MethodInfo (com.haulmont.cuba.core.app.scheduled.MethodInfo)4 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 MetaProperty (com.haulmont.chile.core.annotations.MetaProperty)1 SchedulingType (com.haulmont.cuba.core.entity.SchedulingType)1 CubaDefaultListableBeanFactory (com.haulmont.cuba.core.sys.CubaDefaultListableBeanFactory)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 TargetClassAware (org.springframework.aop.TargetClassAware)1 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)1