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