项目:Camel
文件:DefaultCamelBeanPostProcessor.java
/**
* A strategy method to allow implementations to perform some custom JBI
* based injection of the POJO
*
* @param bean the bean to be injected
*/
protected void injectFields(final Object bean,final String beanName) {
ReflectionHelper.doWithFields(bean.getClass(),new ReflectionHelper.FieldCallback() {
public void doWith(Field field) throws IllegalArgumentException,illegalaccessexception {
PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
if (propertyInject != null && getPostProcessorHelper().matchContext(propertyInject.context())) {
injectFieldProperty(field,propertyInject.value(),propertyInject.defaultValue(),bean,beanName);
}
BeanInject beanInject = field.getAnnotation(BeanInject.class);
if (beanInject != null && getPostProcessorHelper().matchContext(beanInject.context())) {
injectFieldBean(field,beanInject.value(),beanName);
}
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
if (endpointInject != null && getPostProcessorHelper().matchContext(endpointInject.context())) {
injectField(field,endpointInject.uri(),endpointInject.ref(),endpointInject.property(),beanName);
}
Produce produce = field.getAnnotation(Produce.class);
if (produce != null && getPostProcessorHelper().matchContext(produce.context())) {
injectField(field,produce.uri(),produce.ref(),produce.property(),beanName);
}
}
});
}
项目:Camel
文件:DefaultCamelBeanPostProcessor.java
protected void setterInjection(Method method,Object bean,String beanName) {
PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
if (propertyInject != null && getPostProcessorHelper().matchContext(propertyInject.context())) {
setterPropertyInjection(method,beanName);
}
BeanInject beanInject = method.getAnnotation(BeanInject.class);
if (beanInject != null && getPostProcessorHelper().matchContext(beanInject.context())) {
setterBeanInjection(method,beanName);
}
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
if (endpointInject != null && getPostProcessorHelper().matchContext(endpointInject.context())) {
setterInjection(method,beanName,endpointInject.property());
}
Produce produce = method.getAnnotation(Produce.class);
if (produce != null && getPostProcessorHelper().matchContext(produce.context())) {
setterInjection(method,produce.property());
}
}
项目:Camel
文件:CamelNamespaceHandler.java
protected void setterInjection(Method method,String beanName) {
PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
if (propertyInject != null && matchContext(propertyInject.context())) {
setterPropertyInjection(method,beanName);
}
BeanInject beanInject = method.getAnnotation(BeanInject.class);
if (beanInject != null && matchContext(beanInject.context())) {
setterBeanInjection(method,beanName);
}
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
if (endpointInject != null && matchContext(endpointInject.context())) {
setterInjection(method,endpointInject.property());
}
Produce produce = method.getAnnotation(Produce.class);
if (produce != null && matchContext(produce.context())) {
setterInjection(method,produce.property());
}
}
项目:Camel
文件:CdiCamelExtension.java
private void processAnnotatedType(@Observes ProcessAnnotatedType<?> pat) {
if (pat.getAnnotatedType().isAnnotationPresent(Vetoed.class)) {
pat.veto();
}
if (hasAnnotation(pat.getAnnotatedType(),Converter.class)) {
converters.add(pat.getAnnotatedType().getJavaClass());
}
if (hasAnnotation(pat.getAnnotatedType(),BeanInject.class,Consume.class,EndpointInject.class,Produce.class,PropertyInject.class)) {
camelBeans.add(pat.getAnnotatedType());
}
if (hasAnnotation(pat.getAnnotatedType(),Consume.class)) {
eagerBeans.add(pat.getAnnotatedType());
}
if (hasAnnotation(pat.getAnnotatedType(),ImportResource.class)) {
resources.add(pat.getAnnotatedType().getAnnotation(ImportResource.class));
}
}
项目:Camel
文件:CamelNamespaceHandler.java
/**
* A strategy method to allow implementations to perform some custom JBI
* based injection of the POJO
*
* @param bean the bean to be injected
*/
protected void injectFields(final Object bean,final String beanName) {
Class<?> clazz = bean.getClass();
do {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
if (propertyInject != null && matchContext(propertyInject.context())) {
injectFieldProperty(field,beanName);
}
BeanInject beanInject = field.getAnnotation(BeanInject.class);
if (beanInject != null && matchContext(beanInject.context())) {
injectFieldBean(field,beanName);
}
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
if (endpointInject != null && matchContext(endpointInject.context())) {
injectField(field,beanName);
}
Produce produce = field.getAnnotation(Produce.class);
if (produce != null && matchContext(produce.context())) {
injectField(field,beanName);
}
}
clazz = clazz.getSuperclass();
} while (clazz != null && clazz != Object.class);
}
项目:Camel
文件:ProduceInjector.java
public Object provide(Produce inject,TypeLiteral<?> typeLiteral,Field field) {
Class<?> type = field.getType();
String injectionPointName = field.getName();
String endpointRef = inject.ref();
String uri = inject.uri();
String property = inject.property();
return getInjectionValue(type,uri,endpointRef,property,injectionPointName,null,null);
}
项目:Camel
文件:ProduceInjector.java
public Object provide(Produce inject,Method method,Class<?> aClass,int index) {
Class<?>[] parameterTypes = method.getParameterTypes();
Class<?> type = parameterTypes[index];
String injectionPointName = ObjectHelper.getPropertyName(method);
String endpointRef = inject.ref();
String uri = inject.uri();
String property = inject.property();
return getInjectionValue(type,null);
}
项目:Camel
文件:CdiCamelExtension.java
private boolean shouldDeployDefaultCamelContext(Set<Bean<?>> beans) {
return beans.stream()
// Is there a Camel bean with the @Default qualifier?
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.filter(hasType(CamelContextAware.class).or(hasType(Component.class))
.or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
.map(Bean::getQualifiers)
.flatMap(Set::stream)
.filter(isEqual(DEFAULT))
.findAny()
.isPresent()
// Or a bean with Camel annotations?
|| concat(camelBeans.stream().map(AnnotatedType::getFields),camelBeans.stream().map(AnnotatedType::getmethods))
.flatMap(Set::stream)
.map(Annotated::getAnnotations)
.flatMap(Set::stream)
.filter(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
.or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
.or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject) a).context().isEmpty()))
.or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
.or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject) a).context().isEmpty())))
.findAny()
.isPresent()
// Or an injection point for Camel primitives?
|| beans.stream()
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.map(Bean::getInjectionPoints)
.flatMap(Set::stream)
.filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
.map(InjectionPoint::getQualifiers)
.flatMap(Set::stream)
.filter(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)))
.findAny()
.isPresent();
}
项目:camel-cdi
文件:CdiCamelExtension.java
private boolean shouldDeployDefaultCamelContext(BeanManager manager,Set<SyntheticBean<?>> beans) {
// Todo: find a way to 'pre-filter' by refining the bean types passed to the bean manager
return concat(manager.getBeans(Object.class,ANY).stream(),beans.stream())
// Is there a Camel bean with the @Default qualifier?
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.filter(hasType(CamelContextAware.class).or(hasType(Component.class))
.or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
.map(Bean::getQualifiers)
.flatMap(Set::stream)
.anyMatch(isEqual(DEFAULT))
// Or a bean with Camel annotations?
|| concat(camelBeans.stream().map(AnnotatedType::getFields),camelBeans.stream().map(AnnotatedType::getmethods))
.flatMap(Set::stream)
.map(Annotated::getAnnotations)
.flatMap(Set::stream)
.anyMatch(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
.or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
.or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject) a).context().isEmpty()))
.or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
.or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject) a).context().isEmpty())))
// Or an injection point for Camel primitives?
|| concat(manager.getBeans(Object.class,beans.stream())
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.map(Bean::getInjectionPoints)
.flatMap(Set::stream)
.filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
.map(InjectionPoint::getQualifiers)
.flatMap(Set::stream)
.anyMatch(isAnnotationType(Uri.class).or(isEqual(DEFAULT)));
}
项目:Camel
文件:Echo.java
@Produce(uri = "direct:hello")
String hello(String name);
项目:Camel
文件:ProduceInjector.java
项目:camel-cdi
文件:CdiCamelExtension.java
private void camelAnnotations(@Observes @WithAnnotations({BeanInject.class,PropertyInject.class}) ProcessAnnotatedType<?> pat) {
camelBeans.add(pat.getAnnotatedType());
}
项目:Camel
文件:CamelModule.java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。