@Override public Set<String> apply(DotName name) { ClassInfo annotationClassInfo = index.getClassByName(name); ImmutableSet.Builder<String> builder = ImmutableSet.builder(); if (annotationClassInfo != null) { for (DotName annotationName : annotationClassInfo.annotations().keySet()) { builder.add(annotationName.toString()); } } else { try { Class<?> annotationClass = moduleClassLoader.loadClass(name.toString()); for (Annotation annotation : annotationClass.getDeclaredAnnotations()) { builder.add(annotation.annotationType().getName()); } } catch (ClassNotFoundException e) { WeldLogger.DEPLOYMENT_LOGGER.unableToLoadAnnotation(name.toString()); } } return builder.build(); } }
@Override public void processMethod(EnhancedAnnotatedMethod<?, ? super T> method) { if (method.isAnnotationPresent(Inject.class)) { if (method.getAnnotation(Produces.class) != null) { throw UtilLogger.LOG.initializerCannotBeProducer(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } else if (method.getEnhancedParameters(Disposes.class).size() > 0) { throw UtilLogger.LOG.initializerCannotBeDisposalMethod(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } else if (method.getEnhancedParameters(Observes.class).size() > 0) { throw EventLogger.LOG.invalidInitializer(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } else if (method.isGeneric()) { throw UtilLogger.LOG.initializerMethodIsGeneric(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } if (!method.isStatic()) { currentLevel.add(InjectionPointFactory.instance().createMethodInjectionPoint(MethodInjectionPointType.INITIALIZER, method, declaringBean, type.getJavaClass(), null, manager)); } } }
this.declaringBean = declaringBean; this.observerMethod = initMethodInjectionPoint(observer, declaringBean, manager); EnhancedAnnotatedParameter<?, ? super X> eventParameter = observer.getEnhancedParameters(Observes.class).get(0); this.eventType = new HierarchyDiscovery(declaringBean.getBeanClass()).resolveType(eventParameter.getBaseType()); this.id = createId(observer, declaringBean); this.bindings = manager.getServices().get(SharedObjectCache.class) .getSharedSet(observer.getEnhancedParameters(Observes.class).get(0).getMetaAnnotations(Qualifier.class)); Observes observesAnnotation = observer.getEnhancedParameters(Observes.class).get(0).getAnnotation(Observes.class); this.reception = observesAnnotation.notifyObserver(); transactionPhase = ObserverFactory.getTransactionalPhase(observer); ImmutableSet.Builder<WeldInjectionPointAttributes<?, ?>> injectionPoints = ImmutableSet.builder(); for (ParameterInjectionPoint<?, ?> injectionPoint : observerMethod.getParameterInjectionPoints()) { if (injectionPoint instanceof SpecialParameterInjectionPoint) { continue; injectionPoints.add(injectionPoint); this.injectionPoints = injectionPoints.build(); this.isStatic = observer.isStatic(); this.eventMetadataRequired = initMetadataRequired(this.injectionPoints);
protected Collection<ContextHolder<? extends Context>> createContexts(ServiceRegistry services) { List<ContextHolder<? extends Context>> contexts = new ArrayList<ContextHolder<? extends Context>>(); BeanIdentifierIndex beanIdentifierIndex = services.get(BeanIdentifierIndex.class); /* * Register a full set of bound and unbound contexts. Although we may not use all of * these (e.g. if we are running in a servlet environment) they may be * useful for an application. */ Set<Annotation> boundQualifires = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(BoundLiteral.INSTANCE).build(); Set<Annotation> unboundQualifiers = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(UnboundLiteral.INSTANCE).build(); contexts.add(new ContextHolder<ApplicationContext>(new ApplicationContextImpl(contextId), ApplicationContext.class, unboundQualifiers)); contexts.add(new ContextHolder<SingletonContext>(new SingletonContextImpl(contextId), SingletonContext.class, unboundQualifiers)); contexts.add(new ContextHolder<BoundSessionContext>(new BoundSessionContextImpl(contextId, beanIdentifierIndex), BoundSessionContext.class, boundQualifires)); contexts.add(new ContextHolder<BoundConversationContext>(new BoundConversationContextImpl(contextId, services), BoundConversationContext.class, boundQualifires)); contexts.add(new ContextHolder<BoundRequestContext>(new BoundRequestContextImpl(contextId), BoundRequestContext.class, boundQualifires)); contexts.add(new ContextHolder<RequestContext>(new RequestContextImpl(contextId), RequestContext.class, unboundQualifiers)); contexts.add(new ContextHolder<DependentContext>(new DependentContextImpl(services.get(ContextualStore.class)), DependentContext.class, unboundQualifiers)); services.get(WeldModules.class).postContextRegistration(contextId, services, contexts); /* * Register the contexts with the bean manager and add the beans to the * deployment manager so that they are easily accessible (contexts are app * scoped) */ for (ContextHolder<? extends Context> context : contexts) { deploymentManager.addContext(context.getContext()); deploymentManager.addBean(ContextBean.of(context, deploymentManager)); } return contexts; }
public List<Set<FieldInjectionPoint<?, ?>>> getFieldInjectionPoints(Bean<?> declaringBean, EnhancedAnnotatedType<?> type, BeanManagerImpl manager) { List<Set<FieldInjectionPoint<?, ?>>> injectableFieldsList = new ArrayList<Set<FieldInjectionPoint<?, ?>>>(); if (type.slim() instanceof UnbackedAnnotatedType<?>) { // external AnnotatedTypes require special treatment Collection<EnhancedAnnotatedField<?, ?>> allFields = type.getEnhancedFields(Inject.class); for (Class<?> clazz = type.getJavaClass(); clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) { ImmutableSet.Builder<FieldInjectionPoint<?, ?>> fields = ImmutableSet.builder(); for (EnhancedAnnotatedField<?, ?> field : allFields) { if (!field.isStatic() && field.getJavaMember().getDeclaringClass().equals(clazz)) { addFieldInjectionPoint(field, fields, declaringBean, type.getJavaClass(), manager); } } injectableFieldsList.add(0, fields.build()); } } else { for (EnhancedAnnotatedType<?> t = type; t != null && !t.getJavaClass().equals(Object.class); t = t .getEnhancedSuperclass()) { ImmutableSet.Builder<FieldInjectionPoint<?, ?>> fields = ImmutableSet.builder(); for (EnhancedAnnotatedField<?, ?> annotatedField : t.getDeclaredEnhancedFields(Inject.class)) { if (!annotatedField.isStatic()) { addFieldInjectionPoint(annotatedField, fields, declaringBean, t.getJavaClass(), manager); } } injectableFieldsList.add(0, fields.build()); } } return ImmutableList.copyOf(injectableFieldsList); }
public AbstractCDI() { ImmutableSet.Builder<String> names = ImmutableSet.builder(); for (Class<?> clazz = getClass(); clazz != CDI.class; clazz = clazz.getSuperclass()) { names.add(clazz.getName()); } names.add(Unmanaged.class.getName()); this.knownClassNames = names.build(); this.instanceCache = ComputingCacheBuilder.newBuilder() .<BeanManagerImpl, WeldInstance<T>> build((b) -> cast(b.getInstance(b.createCreationalContext(null)))); }
/** * Determines the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator. A decorated method * is any method declared by a decorated type which is implemented by the decorator. * * @param beanManager the bean manager * @param decorator the specified decorator * @return the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator */ public static Set<InvokableAnnotatedMethod<?>> getDecoratorMethods(BeanManagerImpl beanManager, WeldDecorator<?> decorator) { ImmutableSet.Builder<InvokableAnnotatedMethod<?>> builder = ImmutableSet.builder(); for (Type type : decorator.getDecoratedTypes()) { EnhancedAnnotatedType<?> weldClass = getEnhancedAnnotatedTypeOfDecoratedType(beanManager, type); for (EnhancedAnnotatedMethod<?, ?> method : weldClass.getDeclaredEnhancedMethods()) { if (decorator.getEnhancedAnnotated().getEnhancedMethod(method.getSignature()) != null) { builder.add(InvokableAnnotatedMethod.of(method.slim())); } } } return builder.build(); }
protected <T> Set<ResourceInjection<?>> createResourceInjections(Iterable<EnhancedAnnotatedField<?, ? super T>> fields, Iterable<EnhancedAnnotatedMethod<?, ? super T>> methods, Bean<?> declaringBean, Class<?> declaringClass, BeanManagerImpl manager) { ImmutableSet.Builder<ResourceInjection<?>> resourceInjections = ImmutableSet.builder(); S injectionServices = getInjectionServices(manager); C processorContext = getProcessorContext(manager); for (EnhancedAnnotatedField<?, ? super T> field : fields) { if (accept(field, processorContext)) { resourceInjections.add(createFieldResourceInjection( InjectionPointFactory.silentInstance().createFieldInjectionPoint(field, declaringBean, declaringClass, manager), injectionServices, processorContext)); } } for (EnhancedAnnotatedMethod<?, ?> method : methods) { if (method.getParameters().size() != 1) { throw UtilLogger.LOG.resourceSetterInjectionNotAJavabean(method); } if (accept(method, processorContext)) { EnhancedAnnotatedParameter<?, ?> parameter = method.getEnhancedParameters().get(0); resourceInjections.add(createSetterResourceInjection( InjectionPointFactory.silentInstance().createParameterInjectionPoint(parameter, declaringBean, declaringClass, manager), injectionServices, processorContext)); } } return resourceInjections.build(); }
ImmutableSet.Builder<ResourceInjection<?>> resourceInjections = ImmutableSet.builder(); for (EnhancedAnnotatedField<?, ?> field : type.getDeclaredEnhancedFields(marker)) { if (accept(field, apiAbstraction)) { resourceInjections.add(createFieldResourceInjection(InjectionPointFactory.silentInstance() .createFieldInjectionPoint(field, declaringBean, type.getJavaClass(), manager), injectionServices, apiAbstraction)); for (EnhancedAnnotatedMethod<?, ?> method : type.getDeclaredEnhancedMethods(marker)) { if (method.getParameters().size() != 1) { throw UtilLogger.LOG.resourceSetterInjectionNotAJavabean(method); resourceInjections.add(createSetterResourceInjection( InjectionPointFactory.silentInstance().createParameterInjectionPoint( method.getEnhancedParameters().get(0), declaringBean, type.getJavaClass(), manager), injectionServices, apiAbstraction)); return resourceInjections.build();
@Override public void postContextRegistration(PostContextRegistrationContext ctx) { final BeanIdentifierIndex index = ctx.getServices().get(BeanIdentifierIndex.class); final String contextId = ctx.getContextId(); if (Reflections.isClassLoadable(ServletApiAbstraction.SERVLET_CONTEXT_CLASS_NAME, WeldClassLoaderResourceLoader.INSTANCE)) { // Register the Http contexts if not in Set<Annotation> httpQualifiers = ImmutableSet.<Annotation> builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(HttpLiteral.INSTANCE).build(); ctx.addContext(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, index), HttpSessionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, index), HttpSessionDestructionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, ctx.getServices()), HttpConversationContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers)); } }
ImmutableSet.Builder<Metadata<Extension>> extensionsBuilder = ImmutableSet.builder(); extensionsBuilder.addAll(bootstrap.loadExtensions(WeldResourceLoader.getClassLoader())); if (isDevModeEnabled) { extensionsBuilder.add(new MetadataImpl<Extension>(DevelopmentMode.getProbeExtension(resourceLoader), "N/A")); final Iterable<Metadata<Extension>> extensions = extensionsBuilder.build(); final TypeDiscoveryConfiguration typeDiscoveryConfiguration = bootstrap.startExtensions(extensions); final EEModuleDescriptor eeModule = new EEModuleDescriptorImpl(context.getContextPath(), ModuleType.WEB); archive.getServices().add(EEModuleDescriptor.class, eeModule); deployment.getServices().add(ClassFileServices.class, strategy.getClassFileServices());
/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }
@SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Iterable<? extends T> iterable) { Preconditions.checkNotNull(iterable); if (iterable instanceof AbstractImmutableSet<?>) { return (Set<T>) iterable; } if (!iterable.iterator().hasNext()) { return Collections.emptySet(); } return ImmutableSet.<T> builder().addAll(iterable).build(); }
public Collection<Class<? extends Annotation>> getRequiredScopeAnnotations() { if (requiredScopeTypeAnnotations == null) { // this init may be performed more than once - which is OK ImmutableSet.Builder<Class<? extends Annotation>> builder = ImmutableSet.builder(); for (Class<? extends Annotation> annotation : requiredTypeAnnotations) { if (beanManager.isScope(annotation)) { builder.add(annotation); } } this.requiredScopeTypeAnnotations = builder.build(); } return requiredScopeTypeAnnotations; }
/** * Illegal bean types are ignored except for array and primitive types and unless {@link Typed} is used. * * @return the set of bean types from an annotated element */ public static Set<Type> getTypes(EnhancedAnnotated<?, ?> annotated) { // array and primitive types require special treatment if (annotated.getJavaClass().isArray() || annotated.getJavaClass().isPrimitive()) { return ImmutableSet.<Type>builder().addAll(annotated.getBaseType(), Object.class).build(); } else { if (annotated.isAnnotationPresent(Typed.class)) { return ImmutableSet.<Type>builder().addAll(getTypedTypes(Reflections.buildTypeMap(annotated.getTypeClosure()), annotated.getJavaClass(), annotated.getAnnotation(Typed.class))).build(); } else { if (annotated.getJavaClass().isInterface()) { return getLegalBeanTypes(annotated.getTypeClosure(), annotated, Object.class); } return getLegalBeanTypes(annotated.getTypeClosure(), annotated); } } }
protected void initNonBindingMembers(EnhancedAnnotation<T> annotatedAnnotation) { Set<EnhancedAnnotatedMethod<?, ?>> enhancedMethods = annotatedAnnotation.getMembers(Nonbinding.class); if (enhancedMethods.isEmpty()) { this.nonBindingMembers = Collections.emptySet(); } else { ImmutableSet.Builder<AnnotatedMethod<?>> nonBindingMembers = ImmutableSet.builder(); for (EnhancedAnnotatedMethod<?, ?> method : enhancedMethods) { nonBindingMembers.add(method.slim()); } this.nonBindingMembers = nonBindingMembers.build(); } }
/** * Produces a factory for a specific bean implementation. * * @param proxiedBeanType the actual enterprise bean */ EnterpriseProxyFactory(Class<T> proxiedBeanType, SessionBeanImpl<T> bean) { super(bean.getBeanManager().getContextId(), proxiedBeanType, ImmutableSet.<Type> builder().addAll(bean.getTypes()) .addAll(bean.getEjbDescriptor().getRemoteBusinessInterfacesAsClasses()).build(), bean); }
@Override public Object apply(RequestedTypeHolder input) { ImmutableSet.Builder<Type> types = ImmutableSet.builder(); for (Type type : input.bean.getTypes()) { if (Reflections.getRawType(type).isInterface()) { types.add(type); return createClientProxy(input.bean, types.add(beanType).build()); return createClientProxy(input.bean, types.add(input.requestedType).build()); Class<?> requestedRawType = Reflections.getRawType(input.requestedType); for (Type type : input.bean.getTypes()) { if (requestedRawType.isAssignableFrom(Reflections.getRawType(type)) && Proxies.isTypeProxyable(type, services())) { return createClientProxy(input.bean, types.add(type).build());
private void addFieldInjectionPoint(EnhancedAnnotatedField<?, ?> annotatedField, ImmutableSet.Builder<FieldInjectionPoint<?, ?>> injectableFields, Bean<?> declaringBean, Class<?> declaringComponentClass, BeanManagerImpl manager) { if (annotatedField.isFinal()) { throw UtilLogger.LOG.qualifierOnFinalField(annotatedField); } injectableFields.add(createFieldInjectionPoint(annotatedField, declaringBean, declaringComponentClass, manager)); }
@Override public void processMethod(EnhancedAnnotatedMethod<?, ? super T> method) { if (method.isAnnotationPresent(Inject.class)) { if (method.getAnnotation(Produces.class) != null) { throw UtilLogger.LOG.initializerCannotBeProducer(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } else if (method.getEnhancedParameters(Disposes.class).size() > 0) { throw UtilLogger.LOG.initializerCannotBeDisposalMethod(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } else if (method.getEnhancedParameters(Observes.class).size() > 0) { throw EventLogger.LOG.invalidInitializer(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } else if (method.isGeneric()) { throw UtilLogger.LOG.initializerMethodIsGeneric(method, Formats.formatAsStackTraceElement(method.getJavaMember())); } if (!method.isStatic()) { currentLevel.add(InjectionPointFactory.instance().createMethodInjectionPoint(MethodInjectionPointType.INITIALIZER, method, declaringBean, type.getJavaClass(), null, manager)); } } }