Java Code Examples for javax.enterprise.inject.spi.AnnotatedType#getAnnotation()
The following examples show how to use
javax.enterprise.inject.spi.AnnotatedType#getAnnotation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanBuilder.java From deltaspike with Apache License 2.0 | 4 votes |
/** * <p> * Read the {@link AnnotatedType}, creating a bean from the class and it's * annotations. * </p> * <p/> * <p> * By default the bean lifecycle will wrap the result of calling * {@link BeanManager#createInjectionTarget(AnnotatedType)}. * </p> * <p/> * <p> * {@link BeanBuilder} does <em>not</em> support reading members of the class * to create producers or observer methods. * </p> * * @param type the type to read */ public BeanBuilder<T> readFromType(AnnotatedType<T> type) { this.beanClass = type.getJavaClass(); if (beanLifecycle == null) { setDefaultBeanLifecycle(type); } this.qualifiers = new HashSet<Annotation>(); this.stereotypes = new HashSet<Class<? extends Annotation>>(); this.types = new HashSet<Type>(); for (Annotation annotation : type.getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { this.qualifiers.add(annotation); } else if (beanManager.isScope(annotation.annotationType())) { this.scope = annotation.annotationType(); } else if (beanManager.isStereotype(annotation.annotationType())) { this.stereotypes.add(annotation.annotationType()); } if (annotation instanceof Named) { this.name = ((Named) annotation).value(); if (name == null || name.length() == 0) { name = createDefaultBeanName(type); } } if (annotation instanceof Alternative) { this.alternative = true; } } if (type.isAnnotationPresent(Typed.class)) { Typed typed = type.getAnnotation(Typed.class); this.types.addAll(Arrays.asList(typed.value())); } else { for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass()) { this.types.add(c); } Collections.addAll(this.types, type.getJavaClass().getInterfaces()); this.types.add(Object.class); } if (qualifiers.isEmpty()) { qualifiers.add(new DefaultLiteral()); } qualifiers.add(new AnyLiteral()); this.id = ImmutableBeanWrapper.class.getName() + ":" + Annotateds.createTypeId(type); return this; }
Example 2
Source File: LockSupplierStorage.java From deltaspike with Apache License 2.0 | 4 votes |
protected LockSupplier getLockSupplier(final InvocationContext ic) { final Method key = ic.getMethod(); LockSupplier operation = lockSuppliers.get(key); if (operation == null) { final Class declaringClass = key.getDeclaringClass(); final AnnotatedType<Object> annotatedType = beanManager.createAnnotatedType(declaringClass); final AnnotatedMethod<?> annotatedMethod = AnnotatedMethods.findMethod(annotatedType, key); Locked config = annotatedMethod.getAnnotation(Locked.class); if (config == null) { config = annotatedType.getAnnotation(Locked.class); } final Locked.LockFactory factory = config.factory() != Locked.LockFactory.class ? Locked.LockFactory.class.cast( beanManager.getReference(beanManager.resolve( beanManager.getBeans( config.factory())), Locked.LockFactory.class, null)) : this; final ReadWriteLock writeLock = factory.newLock(annotatedMethod, config.fair()); final long timeout = config.timeoutUnit().toMillis(config.timeout()); final Lock lock = config.operation() == READ ? writeLock.readLock() : writeLock.writeLock(); if (timeout > 0) { operation = new LockSupplier() { @Override public Lock get() { try { if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS)) { throw new IllegalStateException("Can't lock for " + key + " in " + timeout + "ms"); } } catch (final InterruptedException e) { Thread.interrupted(); throw new IllegalStateException("Locking interrupted", e); } return lock; } }; } else { operation = new LockSupplier() { @Override public Lock get() { lock.lock(); return lock; } }; } final LockSupplier existing = lockSuppliers.putIfAbsent(key, operation); if (existing != null) { operation = existing; } } return operation; }
Example 3
Source File: InvokerStorage.java From deltaspike with Apache License 2.0 | 4 votes |
Invoker getOrCreateInvoker(final InvocationContext ic) { final Method method = ic.getMethod(); Invoker i = providers.get(method); if (i == null) { final Class declaringClass = method.getDeclaringClass(); final AnnotatedType<Object> annotatedType = beanManager.createAnnotatedType(declaringClass); final AnnotatedMethod<?> annotatedMethod = AnnotatedMethods.findMethod(annotatedType, method); Throttled config = annotatedMethod.getAnnotation(Throttled.class); if (config == null) { config = annotatedType.getAnnotation(Throttled.class); } Throttling sharedConfig = annotatedMethod.getAnnotation(Throttling.class); if (sharedConfig == null) { sharedConfig = annotatedType.getAnnotation(Throttling.class); } final Throttling.SemaphoreFactory factory = sharedConfig != null && sharedConfig.factory() != Throttling.SemaphoreFactory.class ? Throttling.SemaphoreFactory.class.cast( beanManager.getReference(beanManager.resolve( beanManager.getBeans( sharedConfig.factory())), Throttling.SemaphoreFactory.class, null)) : this; final Semaphore semaphore = factory.newSemaphore( annotatedMethod, sharedConfig != null && !sharedConfig.name().isEmpty() ? sharedConfig.name() : declaringClass.getName(), sharedConfig != null && sharedConfig.fair(), sharedConfig != null ? sharedConfig.permits() : 1); final long timeout = config.timeoutUnit().toMillis(config.timeout()); final int weigth = config.weight(); i = new Invoker(semaphore, weigth, timeout); final Invoker existing = providers.putIfAbsent(ic.getMethod(), i); if (existing != null) { i = existing; } } return i; }
Example 4
Source File: AnnotatedTypeProcessor.java From ozark with Apache License 2.0 | 3 votes |
private <T> AnnotatedMethod<? super T> getReplacement(AnnotatedType<T> type, AnnotatedMethod<? super T> method) { boolean isResourceMethod = method.getAnnotation(GET.class) != null || method.getAnnotation(POST.class) != null || method.getAnnotation(PUT.class) != null || method.getAnnotation(HEAD.class) != null || method.getAnnotation(DELETE.class) != null; boolean hasControllerAnnotation = method.getAnnotation(Controller.class) != null || type.getAnnotation(Controller.class) != null; // added to methods to intercept calls with our validation interceptor Set<Annotation> markerAnnotations = Collections.singleton(() -> ValidationInterceptorBinding.class); // drop Hibernate Validator's marker annotations to skip the native validation Predicate<Class> annotationBlacklist = clazz -> isHibernateValidatorMarkerAnnotation(clazz); if (isResourceMethod && hasControllerAnnotation) { log.log(Level.FINE, "Found controller method: {0}#{1}", new Object[]{ type.getJavaClass().getName(), method.getJavaMember().getName() }); return new AnnotatedMethodWrapper<>(method, markerAnnotations, annotationBlacklist); } return null; }