Search in sources :

Example 1 with BeanExpression

use of org.apache.camel.language.bean.BeanExpression in project camel by apache.

the class MethodCallExpression method createExpression.

@Override
public Expression createExpression(CamelContext camelContext) {
    Expression answer;
    if (beanType == null && beanTypeName != null) {
        try {
            beanType = camelContext.getClassResolver().resolveMandatoryClass(beanTypeName);
        } catch (ClassNotFoundException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }
    BeanHolder holder;
    if (beanType != null) {
        // create a bean if there is a default public no-arg constructor
        if (ObjectHelper.hasDefaultPublicNoArgConstructor(beanType)) {
            instance = camelContext.getInjector().newInstance(beanType);
            holder = new ConstantBeanHolder(instance, camelContext);
        } else {
            holder = new ConstantStaticTypeBeanHolder(beanType, camelContext);
        }
    } else if (instance != null) {
        holder = new ConstantBeanHolder(instance, camelContext);
    } else {
        String ref = beanName();
        // if its a ref then check that the ref exists
        BeanHolder regHolder = new RegistryBean(camelContext, ref);
        // get the bean which will check that it exists
        instance = regHolder.getBean();
        holder = new ConstantBeanHolder(instance, camelContext);
    }
    // create answer using the holder
    answer = new BeanExpression(holder, getMethod());
    // and do sanity check that if a method name was given, that it exists
    validateHasMethod(camelContext, instance, beanType, getMethod());
    return answer;
}
Also used : BeanExpression(org.apache.camel.language.bean.BeanExpression) Expression(org.apache.camel.Expression) ConstantBeanHolder(org.apache.camel.component.bean.ConstantBeanHolder) ConstantStaticTypeBeanHolder(org.apache.camel.component.bean.ConstantStaticTypeBeanHolder) BeanHolder(org.apache.camel.component.bean.BeanHolder) RegistryBean(org.apache.camel.component.bean.RegistryBean) ConstantBeanHolder(org.apache.camel.component.bean.ConstantBeanHolder) ConstantStaticTypeBeanHolder(org.apache.camel.component.bean.ConstantStaticTypeBeanHolder) BeanExpression(org.apache.camel.language.bean.BeanExpression)

Aggregations

Expression (org.apache.camel.Expression)1 BeanHolder (org.apache.camel.component.bean.BeanHolder)1 ConstantBeanHolder (org.apache.camel.component.bean.ConstantBeanHolder)1 ConstantStaticTypeBeanHolder (org.apache.camel.component.bean.ConstantStaticTypeBeanHolder)1 RegistryBean (org.apache.camel.component.bean.RegistryBean)1 BeanExpression (org.apache.camel.language.bean.BeanExpression)1