All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.weld.util.InterceptorBindingSet Maven / Gradle / Ivy

There is a newer version: 3.0.0.Alpha1
Show newest version
package org.jboss.weld.util;

import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.metadata.cache.InterceptorBindingModel;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;

import java.lang.annotation.Annotation;
import java.util.AbstractSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author Marko Luksa
 */
public class InterceptorBindingSet extends AbstractSet {

    private BeanManagerImpl beanManager;
    private Set set = new HashSet();

    public InterceptorBindingSet(BeanManagerImpl beanManager) {
        this.beanManager = beanManager;
    }

    @Override
    public boolean add(Annotation annotation) {
        if (contains(annotation)) {
            return false;
        }
        return set.add(annotation);
    }

    @Override
    public Iterator iterator() {
        return set.iterator();
    }

    @Override
    public int size() {
        return set.size();
    }


    public boolean contains(Object o) {
        if (o instanceof Annotation) {
            Annotation annotation = (Annotation) o;

            MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class);
            InterceptorBindingModel interceptorBindingModel = metaAnnotationStore.getInterceptorBindingModel(annotation.annotationType());

            for (Annotation containedAnnotation : set) {
                if (interceptorBindingModel.isEqual(annotation, containedAnnotation)) {
                    return true;
                }
            }
            return false;
        } else {
            return super.contains(o);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy