@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(); } }
public BeanDeploymentModule(String moduleId, DeploymentUnit deploymentUnit, Collection<BeanDeploymentArchiveImpl> beanDeploymentArchives) { this.beanDeploymentArchives = ImmutableSet.copyOf(beanDeploymentArchives); for (BeanDeploymentArchiveImpl bda : beanDeploymentArchives) { bda.addBeanDeploymentArchives(beanDeploymentArchives); } this.moduleDescriptor = WeldEEModuleDescriptor.of(moduleId, deploymentUnit); if (moduleDescriptor != null) { addService(EEModuleDescriptor.class, moduleDescriptor); } }
public ModuleEnablement createModuleEnablement(BeanDeployment deployment) { ClassLoader loader = new ClassLoader(deployment.getBeanManager().getServices().get(ResourceLoader.class)); List<Class<?>> globallyEnabledDecorators = getDecoratorList(null); ImmutableList.Builder<Class<?>> moduleInterceptorsBuilder = ImmutableList.<Class<?>>builder(); moduleInterceptorsBuilder.addAll(globallyEnabledInterceptors); ImmutableList.Builder<Class<?>> moduleDecoratorsBuilder = ImmutableList.<Class<?>>builder(); moduleDecoratorsBuilder.addAll(globallyEnabledDecorators); deployment)); alternativeClasses = beansXml.getEnabledAlternativeClasses().stream().map(loader).collect(ImmutableSet.collector()); alternativeStereotypes = cast(beansXml.getEnabledAlternativeStereotypes().stream().map(loader).collect(ImmutableSet.collector())); } else { alternativeClasses = Collections.emptySet();
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; }
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);
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)))); }
@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)); } }
public ModuleEnablement createModuleEnablement(BeanDeployment deployment) { ClassLoader loader = new ClassLoader(deployment.getBeanManager().getServices().get(ResourceLoader.class)); List<Class<?>> globallyEnabledDecorators = getDecoratorList(null); ImmutableList.Builder<Class<?>> moduleInterceptorsBuilder = ImmutableList.<Class<?>>builder(); moduleInterceptorsBuilder.addAll(globallyEnabledInterceptors); ImmutableList.Builder<Class<?>> moduleDecoratorsBuilder = ImmutableList.<Class<?>>builder(); moduleDecoratorsBuilder.addAll(globallyEnabledDecorators); deployment)); alternativeClasses = ImmutableSet.copyOf(Iterables.transform(beansXml.getEnabledAlternativeClasses(), loader)); alternativeStereotypes = cast(ImmutableSet.copyOf(Iterables.transform(beansXml.getEnabledAlternativeStereotypes(), loader))); } else { alternativeClasses = Collections.emptySet();
/** * 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(); }
/** * 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; }
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(); } }
/** * 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); } } }
/** * 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 @SuppressWarnings("unchecked") public <T extends Annotation> Set<T> getInterceptorBindingsByType(Class<T> annotationType) { Preconditions.checkArgumentNotNull(annotationType, "annotationType"); return interceptorBindings.stream() .filter((annotation) -> annotation.annotationType().equals(annotationType)) .map(annotation -> (T) annotation) .collect(ImmutableSet.collector()); }
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(); }
protected Set<Class<? extends Annotation>> initRequiredTypeAnnotations(EnhancedAnnotatedMethod<T, ? super X> observer) { EnhancedAnnotatedParameter<?, ? super X> eventParameter = getEventParameter(observer); WithAnnotations annotation = eventParameter.getAnnotation(WithAnnotations.class); if (annotation != null) { return ImmutableSet.<Class<? extends Annotation>>of(annotation.value()); } return Collections.emptySet(); }
private static Set<Class<?>> transformToClasses(Collection<BusinessInterfaceDescriptor<?>> interfaceDescriptors) { if (interfaceDescriptors == null) { return Collections.emptySet(); } return interfaceDescriptors.stream().map(d -> d.getInterface()).collect(ImmutableSet.collector()); }