public void findInvocationHandlerBindings()

in deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanBindingExtension.java [64:126]


    public <X> void findInvocationHandlerBindings(@Observes ProcessAnnotatedType<X> pat, BeanManager beanManager)
    {
        if (!this.isActivated || this.definitionError != null)
        {
            return;
        }

        Class<X> beanClass = pat.getAnnotatedType().getJavaClass();

        // skip classes without a partial bean binding
        Class<? extends Annotation> bindingClass = extractBindingClass(pat);
        if (bindingClass == null)
        {
            return;
        }

        if (beanClass.isInterface() || Modifier.isAbstract(beanClass.getModifiers()))
        {
            pat.veto();

            PartialBeanDescriptor descriptor = descriptors.get(bindingClass);

            if (descriptor == null)
            {
                descriptor = new PartialBeanDescriptor(bindingClass, null, beanClass);
                descriptors.put(bindingClass, descriptor);
            }
            else if (!descriptor.getClasses().contains(beanClass))
            {
                descriptor.getClasses().add(beanClass);
            }
        }
        else if (InvocationHandler.class.isAssignableFrom(beanClass))
        {
            PartialBeanDescriptor descriptor = descriptors.get(bindingClass);

            if (descriptor == null)
            {
                descriptor = new PartialBeanDescriptor(bindingClass, (Class<? extends InvocationHandler>) beanClass);
                descriptors.put(bindingClass, descriptor);
            }
            else
            {
                if (descriptor.getHandler() == null)
                {
                    descriptor.setHandler((Class<? extends InvocationHandler>) beanClass);
                }
                else if (!descriptor.getHandler().equals(beanClass))
                {
                    this.definitionError = new IllegalStateException("Multiple handlers found for "
                            + bindingClass.getName() + " ("
                            + descriptor.getHandler().getName()
                            + " and " + beanClass.getName() + ")");
                }
            }
        }
        else
        {
            this.definitionError = new IllegalStateException(beanClass.getName() + " is annotated with @"
                    + bindingClass.getName() + " and therefore has to be "
                    + "an abstract class, an interface or an implementation of " + InvocationHandler.class.getName());
        }
    }