本文整理汇总了Java中javax.enterprise.inject.spi.AnnotatedType类的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedType类的具体用法?Java AnnotatedType怎么用?Java AnnotatedType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotatedType类属于javax.enterprise.inject.spi包,在下文中一共展示了AnnotatedType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldDeployDefaultCamelContext
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
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();
}
示例2: beanManager
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public static BeanManager beanManager(final CompletableFuture<Registry> injector) {
return Reflection.newProxy(BeanManager.class, (proxy, method, args) -> {
final String name = method.getName();
switch (name) {
case "createAnnotatedType":
return createAnnotatedType((Class) args[0]);
case "createInjectionTarget":
return createInjectionTarget(injector, ((AnnotatedType) args[0]).getJavaClass());
case "createCreationalContext":
return createCreationalContext();
case "toString":
return injector.toString();
default:
throw new UnsupportedOperationException(method.toString());
}
});
}
示例3: handles_annotation
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
@Test
@NoPostConstructFor(String.class)
public void handles_annotation() throws NoSuchMethodException {
final Method method = getClass().getMethod("handles_annotation");
final NoPostConstructExtension extension = new ExtensionFactory().create(method);
assertNotNull(extension);
when(annotatedType.getJavaClass()).thenReturn(String.class);
extension.processAnnotatedType(processAnnotatedType);
ArgumentCaptor<AnnotatedType> captor = ArgumentCaptor.forClass(AnnotatedType.class);
verify(processAnnotatedType).setAnnotatedType(captor.capture());
final AnnotatedType newType = captor.getValue();
assertNotNull(newType.getAnnotation(NoPostConstructIntercepted.class));
}
示例4: testInjectionTarget
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
@Test
public void testInjectionTarget() {
BeanManager beanManager = current().getBeanManager();
// CDI uses an AnnotatedType object to read the annotations of a class
AnnotatedType<String> type = beanManager.createAnnotatedType(String.class);
// The extension uses an InjectionTarget to delegate instantiation,
// dependency injection
// and lifecycle callbacks to the CDI container
InjectionTarget<String> it = beanManager.createInjectionTarget(type);
// each instance needs its own CDI CreationalContext
CreationalContext<String> ctx = beanManager.createCreationalContext(null);
// instantiate the framework component and inject its dependencies
String instance = it.produce(ctx); // call the constructor
it.inject(instance, ctx); // call initializer methods and perform field
// injection
it.postConstruct(instance); // call the @PostConstruct method
// destroy the framework component instance and clean up dependent
// objects
assertNotNull("the String instance is injected now", instance);
assertTrue("the String instance is injected now but it's empty", instance.isEmpty());
it.preDestroy(instance); // call the @PreDestroy method
it.dispose(instance); // it is now safe to discard the instance
ctx.release(); // clean up dependent objects
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:25,代码来源:InjectSPITestCase.java
示例5: getAnnotatedMember
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <X, A extends AnnotatedMember<? super X>> A getAnnotatedMember(Class<X> javaClass, String memberName,
BeanManager beanManager) {
AnnotatedType<X> type = beanManager.createAnnotatedType(javaClass);
for (AnnotatedField<? super X> field : type.getFields()) {
if (field.getJavaMember().getName().equals(memberName)) {
return (A) field;
}
}
for (AnnotatedMethod<? super X> method : type.getMethods()) {
if (method.getJavaMember().getName().equals(memberName)) {
return (A) method;
}
}
throw new IllegalArgumentException("Member " + memberName + " not found on " + javaClass);
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:17,代码来源:InjectSPITestCase.java
示例6: getConfigKey
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
String key = configProperty.name();
if (!key.trim().isEmpty()) {
return key;
}
if (ip.getAnnotated() instanceof AnnotatedMember) {
AnnotatedMember member = (AnnotatedMember) ip.getAnnotated();
AnnotatedType declaringType = member.getDeclaringType();
if (declaringType != null) {
String[] parts = declaringType.getJavaClass().getCanonicalName().split("\\.");
StringBuilder sb = new StringBuilder(parts[0]);
for (int i = 1; i < parts.length; i++) {
sb.append(".").append(parts[i]);
}
sb.append(".").append(member.getJavaMember().getName());
return sb.toString();
}
}
throw new IllegalStateException("Could not find default name for @ConfigProperty InjectionPoint " + ip);
}
示例7: getReplacement
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
public <T> AnnotatedType<T> getReplacement(AnnotatedType<T> originalType) {
boolean modified = false;
Set<AnnotatedMethod<? super T>> methods = new LinkedHashSet<>();
for (AnnotatedMethod<? super T> originalMethod : originalType.getMethods()) {
AnnotatedMethod<? super T> replacement = getReplacement(originalType, originalMethod);
if (replacement != null) {
methods.add(replacement);
modified = true;
} else {
methods.add(originalMethod);
}
}
if (modified) {
return new AnnotatedTypeWrapper<T>(originalType, methods);
}
return null;
}
示例8: isRouteHandler
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
private boolean isRouteHandler(AnnotatedType<?> annotatedType) {
if (!Reflections.isTopLevelOrStaticNestedClass(annotatedType.getJavaClass())) {
LOGGER.warn("Ignoring {0} - class annotated with @WebRoute must be top-level or static nested class", annotatedType.getJavaClass());
return false;
}
Set<Type> types = new HierarchyDiscovery(annotatedType.getBaseType()).getTypeClosure();
for (Type type : types) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
if (parameterizedType.getRawType().equals(Handler.class)) {
Type[] arguments = parameterizedType.getActualTypeArguments();
if (arguments.length == 1 && arguments[0].equals(RoutingContext.class)) {
return true;
}
}
}
}
LOGGER.warn("Ignoring {0} - class annotated with @WebRoute must implement io.vertx.core.Handler<RoutingContext>", annotatedType.getJavaClass());
return false;
}
示例9: findJobs
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
<T> void findJobs( @Observes @WithAnnotations({Cron.class}) ProcessAnnotatedType<T> pat, BeanManager beanManager )
{
// Ensure we are named otherwise job won't fire as we can't locate it
AnnotatedType<?> type = pat.getAnnotatedType();
Class<?> clazz = type.getJavaClass();
CDIUtils.addTypeAnnotation( pat, Named.class, () -> new NamedImpl( "Schedule_" + (id++) ) );
if( type.isAnnotationPresent( Cron.class ) ) {
if( Job.class.isAssignableFrom( clazz ) ) {
jobClasses.add( clazz );
}
else {
throw new UnsupportedOperationException( "@Cron on type must implement Job" );
}
}
else {
for( AnnotatedMethod<?> meth: type.getMethods() ) {
if( meth.isAnnotationPresent( Cron.class ) ) {
jobClasses.add( clazz );
}
}
}
}
示例10: addTypeAnnotation
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
/**
* Ensure we have an annotation present
* <p>
* @param <T>
* @param pat
* @param clazz
* @param s
* <p>
* @return
*/
public static <T> AnnotatedType<T> addTypeAnnotation( ProcessAnnotatedType<T> pat, Class<? extends Annotation> clazz, Supplier<Annotation> s )
{
AnnotatedType<T> t = pat.getAnnotatedType();
if( !t.isAnnotationPresent( clazz ) ) {
MutableAnnotatedType<T> mat;
if( t instanceof MutableAnnotatedType ) {
mat = (MutableAnnotatedType<T>) t;
}
else {
mat = new MutableAnnotatedType<>( t );
pat.setAnnotatedType( mat );
}
mat.add( s.get() );
return mat;
}
return t;
}
示例11: afterDeploymentValidation
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
/**
* Instantiates <em>unmanaged instances</em> of HealthCheckProcedure and
* handle manually their CDI creation lifecycle.
* Add them to the {@link Monitor}.
*/
private void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
try {
for (AnnotatedType delegate : delegates) {
Unmanaged<HealthCheck> unmanagedHealthCheck = new Unmanaged<HealthCheck>(beanManager, delegate.getJavaClass());
Unmanaged.UnmanagedInstance<HealthCheck> healthCheckInstance = unmanagedHealthCheck.newInstance();
HealthCheck healthCheck = healthCheckInstance.produce().inject().postConstruct().get();
healthChecks.add(healthCheck);
healthCheckInstances.add(healthCheckInstance);
monitor.registerHealthBean(healthCheck);
log.info(">> Added health bean impl " + healthCheck);
}
// we don't need the references anymore
delegates.clear();
} catch (Exception e) {
throw new RuntimeException("Failed to register health bean", e);
}
}
示例12: getConfigKey
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
/**
* Get the property key to use.
* In case the {@link ConfigProperty#name()} is empty we will try to determine the key name from the InjectionPoint.
*/
public static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
String key = configProperty.name();
if (key.length() > 0) {
return key;
}
if (ip.getAnnotated() instanceof AnnotatedMember) {
AnnotatedMember member = (AnnotatedMember) ip.getAnnotated();
AnnotatedType declaringType = member.getDeclaringType();
if (declaringType != null) {
String[] parts = declaringType.getJavaClass().getName().split(".");
String cn = parts[parts.length-1];
parts[parts.length-1] = Character.toLowerCase(cn.charAt(0)) + (cn.length() > 1 ? cn.substring(1) : "");
StringBuilder sb = new StringBuilder(parts[0]);
for (int i = 1; i < parts.length; i++) {
sb.append(".").append(parts[i]);
}
// now add the field name
sb.append(".").append(member.getJavaMember().getName());
return sb.toString();
}
}
throw new IllegalStateException("Could not find default name for @ConfigProperty InjectionPoint " + ip);
}
示例13: hasAnnotation
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
static boolean hasAnnotation(AnnotatedType<?> type, Class<? extends Annotation> annotation) {
if (type.isAnnotationPresent(annotation)) {
return true;
}
for (AnnotatedMethod<?> method : type.getMethods()) {
if (method.isAnnotationPresent(annotation)) {
return true;
}
}
for (AnnotatedConstructor<?> constructor : type.getConstructors()) {
if (constructor.isAnnotationPresent(annotation)) {
return true;
}
}
for (AnnotatedField<?> field : type.getFields()) {
if (field.isAnnotationPresent(annotation)) {
return true;
}
}
return false;
}
示例14: alternatives
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
/**
* Activates the alternatives declared with {@code @Beans} globally for the
* application.
* <p/>
* For every types and every methods of every types declared with
* {@link Beans#alternatives()}, the {@code Priority} annotation is added
* so that the corresponding alternatives are selected globally for the
* entire application.
*
* @see Beans
*/
private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) {
AnnotatedType<T> type = pat.getAnnotatedType();
if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) {
// Only select globally the alternatives that are declared with @Beans
return;
}
Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
for (AnnotatedMethod<? super T> method : type.getMethods()) {
if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) {
methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION)));
}
}
if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) {
pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods));
} else if (!methods.isEmpty()) {
pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods));
}
}
示例15: extractQualifiers
import javax.enterprise.inject.spi.AnnotatedType; //导入依赖的package包/类
private static Map<QualifierType, Set<Annotation>> extractQualifiers(final BeanManager bm,
final AnnotatedType<?> annotated) {
Map<QualifierType, Set<Annotation>> qualifiers = new HashMap<>();
AggregateConfiguration aggregateConfiguration = CdiUtils.findAnnotation(bm,
annotated.getAnnotations(), AggregateConfiguration.class);
if (aggregateConfiguration != null) {
qualifiers.putAll(
extractQualifiers(bm, aggregateConfiguration, annotated.getJavaClass()));
} else {
Set<Annotation> defaultQualifiers = CdiUtils.qualifiers(bm, annotated);
for (QualifierType type : QualifierType.values()) {
qualifiers.put(type, defaultQualifiers);
}
}
return normalizeQualifiers(qualifiers);
}