private static Class<?> getBound(Type[] bounds) { if (bounds.length == 0) { return Object.class; } else { return getRawType(bounds[0]); } }
static Class<?> getRawType(Type type) { if (type instanceof Class<?>) { return Class.class.cast(type); } else if (type instanceof ParameterizedType) { return getRawType(ParameterizedType.class.cast(type).getRawType()); } else if (type instanceof TypeVariable<?>) { return getBound(TypeVariable.class.cast(type).getBounds()); } else if (type instanceof WildcardType) { return getBound(WildcardType.class.cast(type).getUpperBounds()); } else if (type instanceof GenericArrayType) { Class<?> rawType = getRawType(GenericArrayType.class.cast(type).getGenericComponentType()); if (rawType != null) { return Array.newInstance(rawType, 0).getClass(); } } throw new UnsupportedOperationException("Unable to retrieve raw type for [" + type + "]"); }
private void beans(@Observes ProcessBean<?> pb, BeanManager manager) { cdiBeans.add(pb.getBean()); // Lookup for CDI event endpoint injection points pb.getBean().getInjectionPoints().stream() .filter(ip -> CdiEventEndpoint.class.equals(getRawType(ip.getType()))) .forEach(ip -> { Type type = ip.getType() instanceof ParameterizedType ? ((ParameterizedType) ip.getType()).getActualTypeArguments()[0] : Object.class; String uri = eventEndpointUri(type, ip.getQualifiers()); cdiEventEndpoints.put(uri, new CdiEventEndpoint<>(uri, type, ip.getQualifiers(), manager)); }); }
.map(Bean::getInjectionPoints) .flatMap(Set::stream) .filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel")) .map(InjectionPoint::getQualifiers) .flatMap(Set::stream)
private static CamelContextNameStrategy nameStrategy(Annotated annotated) { if (annotated.isAnnotationPresent(ContextName.class)) { return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value()); } else if (annotated.isAnnotationPresent(Named.class)) { // TODO: support stereotype with empty @Named annotation String name = annotated.getAnnotation(Named.class).value(); if (name.isEmpty()) { if (annotated instanceof AnnotatedField) { name = ((AnnotatedField) annotated).getJavaMember().getName(); } else if (annotated instanceof AnnotatedMethod) { name = ((AnnotatedMethod) annotated).getJavaMember().getName(); if (name.startsWith("get")) { name = decapitalize(name.substring(3)); } } else { name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName()); } } return new ExplicitCamelContextNameStrategy(name); } else { // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created return new CdiCamelContextNameStrategy(); } } }