public void validateBeanNames(BeanManagerImpl beanManager) { SetMultimap<String, Bean<?>> namedAccessibleBeans = SetMultimap.newSetMultimap(); for (Bean<?> bean : beanManager.getAccessibleBeans()) { if (bean.getName() != null) { namedAccessibleBeans.put(bean.getName(), bean); } } List<String> accessibleNamespaces = beanManager.getAccessibleNamespaces(); for (String name : namedAccessibleBeans.keySet()) { validateBeanName(name, namedAccessibleBeans, accessibleNamespaces, beanManager); } }
/** * * @param bean * @return the set of declared producers */ @SuppressWarnings("unchecked") Set<AbstractProducerBean<?, ?, ?>> getDeclaredProducers(Bean<?> bean) { return (Set<AbstractProducerBean<?, ?, ?>>) (beanToDeclaredProducers.containsKey(bean) ? beanToDeclaredProducers.get(bean) : Collections.emptySet()); }
public void cleanup() { this.extraAnnotations.clear(); }
@Override public void validateBeanNames(final BeanManagerImpl beanManager) { final SetMultimap<String, Bean<?>> namedAccessibleBeans = SetMultimap.newConcurrentSetMultimap(); for (Bean<?> bean : beanManager.getAccessibleBeans()) { if (bean.getName() != null) { namedAccessibleBeans.put(bean.getName(), bean); } } final List<String> accessibleNamespaces = beanManager.getAccessibleNamespaces(); executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<String>(namedAccessibleBeans.keySet()) { protected void doWork(String name) { validateBeanName(name, namedAccessibleBeans, accessibleNamespaces, beanManager); } }); }
Collection<Annotation> classBindingAnnotations, Collection<Annotation> inheritedBindingAnnotations) { SetMultimap<Class<? extends Annotation>, Annotation> mergedBeanBindings = SetMultimap.newSetMultimap(); SetMultimap<Class<? extends Annotation>, Annotation> acceptedInheritedBindings = SetMultimap.newSetMultimap(); MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class); if (!annotationType.isAnnotationPresent(Repeatable.class)) { for (Annotation mergedBinding : mergedBeanBindings.get(annotationType)) { if (!metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(binding, mergedBinding, false)) { throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass())); mergedBeanBindings.put(binding.annotationType(), binding); Class<? extends Annotation> annotationType = binding.annotationType(); if (!mergedBeanBindings.containsKey(annotationType) || annotationType.isAnnotationPresent(Repeatable.class)) { mergedBeanBindings.put(annotationType, binding); acceptedInheritedBindings.put(annotationType, binding); } else { Set<Annotation> inheritedBindings = acceptedInheritedBindings.get(annotationType); for (Annotation inheritedBinding : inheritedBindings) { if (!metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(binding, inheritedBinding, false)) { throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass()));
this.delegate = annotated; if (annotated instanceof AnnotatedType<?>) { this.rawType = Reflections.<AnnotatedType<T>>cast(annotated).getJavaClass(); } else { this.rawType = Reflections.getRawType(annotated.getBaseType()); SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap = SetMultimap.newSetMultimap(); processMetaAnnotations(metaAnnotationMap, annotationMap.values(), classTransformer, false); this.metaAnnotationMap = Multimaps.unmodifiableMultimap(metaAnnotationMap);
declaredFieldsTemp.add(annotatedField); for (Annotation annotation : annotatedField.getAnnotations()) { declaredAnnotatedFields.put(annotation.annotationType(), annotatedField); fieldsTemp = Sets.union(fieldsTemp, Reflections.<Set<EnhancedAnnotatedField<?, ? super T>>>cast(superclass.getFields())); annotatedFields.put(annotation.annotationType(), weldField); if (annotatedField.getDeclaringType().getJavaClass().equals(javaClass)) { declaredAnnotatedFields.put(annotation.annotationType(), weldField); this.annotatedFields = Multimaps.unmodifiableMultimap(annotatedFields); this.declaredFields = new HashSet<EnhancedAnnotatedField<?, ? super T>>(declaredFieldsTemp); this.declaredAnnotatedFields = Multimaps.unmodifiableMultimap(declaredAnnotatedFields); EnhancedAnnotatedMethod<?, ? super T> weldMethod = EnhancedAnnotatedMethodImpl.of(method, this, classTransformer); declaredMethodsTemp.add(weldMethod); for (Annotation annotation : weldMethod.getAnnotations()) { if (weldMethod.getEnhancedParameters(annotationType).size() > 0) { this.declaredAnnotatedMethods = Multimaps.unmodifiableMultimap(declaredAnnotatedMethods); SetMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap = SetMultimap.newSetMultimap();
private void removeUnusedBeans() { String excludeTypeProperty = getServices().get(WeldConfiguration.class).getStringProperty(ConfigurationKey.UNUSED_BEANS_EXCLUDE_TYPE); String excludeAnnotationProperty = getServices().get(WeldConfiguration.class).getStringProperty(ConfigurationKey.UNUSED_BEANS_EXCLUDE_ANNOTATION); Validator validator = getServices().get(Validator.class); SetMultimap<Bean<?>, AbstractProducerBean<?, ?, ?>> beanToDeclaredProducers = SetMultimap.newSetMultimap(); SetMultimap<Bean<?>, ObserverMethod<?>> beanToDeclaredObservers = SetMultimap.newSetMultimap(); for (Bean<?> bean : enabledBeans) { if (bean instanceof AbstractProducerBean) { AbstractProducerBean<?, ?, ?> producer = (AbstractProducerBean<?, ?, ?>) bean; beanToDeclaredProducers.put(producer.getDeclaringBean(), producer); if (observerMethod instanceof ObserverMethodImpl) { ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod; beanToDeclaredObservers.put(observerMethodImpl.getDeclaringBean(), observerMethod); if (beanToDeclaredObservers.containsKey(bean)) { continue; if (beanToDeclaredProducers.containsKey(bean)) { continue; for (Bean<?> bean : beanToDeclaredProducers.keySet()) { bean = Beans.unwrap(bean); if (!unusedProducers.containsAll(beanToDeclaredProducers.get(bean))) { continue;
Map<String, Class<?>> loadedClasses = buildClassNameMap(beanManager.getEnabled().getAlternativeClasses()); Multimap<Class<?>, Bean<?>> beansByClass = SetMultimap.newSetMultimap(); for (Bean<?> bean : beanManager.getDynamicAccessibleBeans()) { if (!(bean instanceof NewBean)) { beansByClass.put(bean.getBeanClass(), bean); throw ValidatorLogger.LOG.alternativeBeanClassNotClass(definition); } else { final WeldConfiguration configuration = beanManager.getServices().get(WeldConfiguration.class); boolean allowVetoedAlternatives = configuration.getBooleanProperty(ConfigurationKey.ALLOW_VETOED_ALTERNATIVES);
ContextualStore contextualStore = beanManager.getServices().get(ContextualStore.class); bdaToManager.putAll(Container.instance(beanManager).beanDeploymentArchives()); for (Bean<?> bean : manager.getBeans()) { if (manager.isBeanEnabled(bean)) { && candidate instanceof AbstractProducerBean) { AbstractProducerBean<?, ?, ?> producerBean = (AbstractProducerBean<?, ?, ?>) candidate; beanToDeclaredProducers.put(producerBean.getDeclaringBean(), producerBean);
return Multimaps.emptyMultimap(); SetMultimap<String, BeanDeploymentArchive> problems = SetMultimap.newSetMultimap(); List<BeanDeploymentArchive> bdas = ImmutableList.of(first, second); for (String beanClass : intersection) { problems.putAll(beanClass, bdas); SetMultimap<String, BeanDeploymentArchive> beanClassOccurrences = SetMultimap.newSetMultimap(); for (BeanDeploymentArchive beanArchive : beanArchives) { for (String beanClass : beanArchive.getBeanClasses()) { beanClassOccurrences.put(beanClass, beanArchive); for (Entry<String, Collection<BeanDeploymentArchive>> entry : beanClassOccurrences.entrySet()) { if (entry.getValue().size() > 1) { problems.putAll(entry.getKey(), entry.getValue());
protected Multimap<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>> buildAnnotatedParameterMethodMultimap(Set<EnhancedAnnotatedMethod<?, ? super T>> effectiveMethods) { Multimap<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>> result = SetMultimap.newSetMultimap(); for (EnhancedAnnotatedMethod<?, ? super T> method : effectiveMethods) { for (Class<? extends Annotation> annotation : MAPPED_METHOD_PARAMETER_ANNOTATIONS) { if (!method.getEnhancedParameters(annotation).isEmpty()) { result.put(annotation, method); } } } return Multimaps.unmodifiableMultimap(result); }
protected Multimap<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>> buildAnnotatedMethodMultimap(Set<EnhancedAnnotatedMethod<?, ? super T>> effectiveMethods) { Multimap<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>> result = SetMultimap.newSetMultimap(); for (EnhancedAnnotatedMethod<?, ? super T> method : effectiveMethods) { for (Class<? extends Annotation> annotation : MAPPED_METHOD_ANNOTATIONS) { if (method.isAnnotationPresent(annotation)) { result.put(annotation, method); } } } return Multimaps.unmodifiableMultimap(result); }
@Override public void createSessionBeans(BeanDeployerEnvironment environment, SetMultimap<Class<?>, SlimAnnotatedType<?>> types, BeanManagerImpl manager) { final ClassTransformer transformer = manager.getServices().get(ClassTransformer.class); for (InternalEjbDescriptor<?> ejbDescriptor : getEjbDescriptors()) { if (environment.isVetoed(ejbDescriptor.getBeanClass()) || Beans.isVetoed(ejbDescriptor.getBeanClass())) { continue; } if (ejbDescriptor.isSingleton() || ejbDescriptor.isStateful() || ejbDescriptor.isStateless()) { Set<SlimAnnotatedType<?>> classes = types.get(ejbDescriptor.getBeanClass()); if (!classes.isEmpty()) { for (SlimAnnotatedType<?> annotatedType : classes) { createSessionBean(ejbDescriptor, annotatedType, environment, manager, transformer); } } else { createSessionBean(ejbDescriptor, environment, manager, transformer); } } } }
protected void validateBeanName(String name, SetMultimap<String, Bean<?>> namedAccessibleBeans, List<String> accessibleNamespaces, BeanManagerImpl beanManager) { Set<Bean<?>> resolvedBeans = beanManager.getBeanResolver().<Object> resolve(Beans.removeDisabledBeans(namedAccessibleBeans.get(name), beanManager)); if (resolvedBeans.size() > 1) { throw ValidatorLogger.LOG.ambiguousElName(name, resolvedBeans); } if (accessibleNamespaces.contains(name)) { throw ValidatorLogger.LOG.beanNameIsPrefix(name); } }
@Override public void createClassBeans() { final SetMultimap<Class<?>, SlimAnnotatedType<?>> otherWeldClasses = SetMultimap.newConcurrentSetMultimap(); executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<SlimAnnotatedTypeContext<?>>(getEnvironment().getAnnotatedTypes()) { @Override protected void doWork(SlimAnnotatedTypeContext<?> ctx) { createClassBean(ctx.getAnnotatedType(), otherWeldClasses); } }); // create session beans ejbSupport.createSessionBeans(getEnvironment(), otherWeldClasses, getManager()); }
protected void addAbstractClassBean(AbstractClassBean<?> bean) { if (!(bean instanceof NewBean)) { classBeanMap.get(bean.getBeanClass()).add(bean); } addAbstractBean(bean); }
public void createClassBeans() { SetMultimap<Class<?>, SlimAnnotatedType<?>> otherWeldClasses = SetMultimap.newSetMultimap(); for (SlimAnnotatedTypeContext<?> ctx : getEnvironment().getAnnotatedTypes()) { createClassBean(ctx.getAnnotatedType(), otherWeldClasses); } // create session beans ejbSupport.createSessionBeans(getEnvironment(), otherWeldClasses, getManager()); }
protected void addAbstractClassBean(AbstractClassBean<?> bean) { if (!(bean instanceof NewBean)) { classBeanMap.put(bean.getBeanClass(), bean); } addAbstractBean(bean); }
/** * Creates a new instance backed by a {@link HashMap} and {@link HashSet}. All key-value mappings are copied from the input multimap. If any * collection of values in the input multimap contains duplicate elements, these are removed in the constructed multimap. * * @param multimap */ public static <K, V> SetMultimap<K, V> newSetMultimap(Multimap<K, V> multimap) { return new SetMultimap<K, V>(HashMap::new, HashSet::new, multimap); }