Search in sources :

Example 1 with ForwardingInjectionPoint

use of org.jboss.weld.injection.ForwardingInjectionPoint in project core by weld.

the class ModifyingExtension method overrideFieldInjectionPoint.

public void overrideFieldInjectionPoint(@Observes ProcessInjectionPoint<InjectingBean, Dog> event) {
    final InjectionPoint delegate = event.getInjectionPoint();
    event.setInjectionPoint(new ForwardingInjectionPoint() {

        @Override
        protected InjectionPoint delegate() {
            return delegate;
        }

        @Override
        public boolean isTransient() {
            return true;
        }

        @Override
        public Type getType() {
            return Hound.class;
        }

        @Override
        public Set<Annotation> getQualifiers() {
            return Collections.<Annotation>singleton(Fast.Literal.INSTANCE);
        }
    });
}
Also used : Type(java.lang.reflect.Type) Set(java.util.Set) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint)

Example 2 with ForwardingInjectionPoint

use of org.jboss.weld.injection.ForwardingInjectionPoint in project core by weld.

the class ModifyingExtension method overrideFieldInjectionPointToTriggerNewBeanCreation.

public void overrideFieldInjectionPointToTriggerNewBeanCreation(@Observes ProcessInjectionPoint<InjectingBean, Cat> event) {
    final InjectionPoint delegate = event.getInjectionPoint();
    event.setInjectionPoint(new ForwardingInjectionPoint() {

        @Override
        protected InjectionPoint delegate() {
            return delegate;
        }

        @Override
        public Set<Annotation> getQualifiers() {
            return Collections.<Annotation>singleton(New.Literal.INSTANCE);
        }
    });
}
Also used : Set(java.util.Set) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint)

Example 3 with ForwardingInjectionPoint

use of org.jboss.weld.injection.ForwardingInjectionPoint in project core by weld.

the class GlueDecoratorExtension method registerDecorator.

void registerDecorator(@Observes AfterBeanDiscovery event, BeanManager manager) {
    AnnotatedType<GlueDecorator> annotatedType = manager.createAnnotatedType(GlueDecorator.class);
    final BeanAttributes<GlueDecorator> attributes = manager.createBeanAttributes(annotatedType);
    final InjectionPoint delegateInjectionPoint = manager.createInjectionPoint(annotatedType.getConstructors().iterator().next().getParameters().get(0));
    Decorator<GlueDecorator> decorator = new DecoratorImpl<GlueDecorator>() {

        @Override
        public Type getDelegateType() {
            return Glue.class;
        }

        @Override
        public Set<Annotation> getDelegateQualifiers() {
            return Collections.<Annotation>singleton(Any.Literal.INSTANCE);
        }

        @Override
        public Set<Type> getDecoratedTypes() {
            return Collections.emptySet();
        }

        @Override
        public Class<?> getBeanClass() {
            return GlueDecorator.class;
        }

        @Override
        public Set<InjectionPoint> getInjectionPoints() {
            final Decorator<GlueDecorator> decorator = this;
            InjectionPoint wrappedInjectionPoint = new ForwardingInjectionPoint() {

                @Override
                public Bean<?> getBean() {
                    return decorator;
                }

                @Override
                protected InjectionPoint delegate() {
                    return delegateInjectionPoint;
                }
            };
            return Collections.singleton(wrappedInjectionPoint);
        }

        @Override
        public GlueDecorator create(CreationalContext<GlueDecorator> creationalContext) {
            return new GlueDecorator(null);
        }

        @Override
        public void destroy(GlueDecorator instance, CreationalContext<GlueDecorator> creationalContext) {
            creationalContext.release();
        }

        @Override
        protected BeanAttributes<GlueDecorator> attributes() {
            return attributes;
        }
    };
    event.addBean(decorator);
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Type(java.lang.reflect.Type) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint) Annotation(java.lang.annotation.Annotation)

Example 4 with ForwardingInjectionPoint

use of org.jboss.weld.injection.ForwardingInjectionPoint in project core by weld.

the class ModifyingExtension method overrideDelegateInjectionPoint.

public void overrideDelegateInjectionPoint(@Observes ProcessInjectionPoint<AnimalDecorator, Object> event) {
    final InjectionPoint delegate = event.getInjectionPoint();
    event.setInjectionPoint(new ForwardingInjectionPoint() {

        @Override
        protected InjectionPoint delegate() {
            return delegate;
        }

        @Override
        public boolean isDelegate() {
            return true;
        }

        @Override
        public Type getType() {
            return Animal.class;
        }
    });
}
Also used : Type(java.lang.reflect.Type) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ForwardingInjectionPoint(org.jboss.weld.injection.ForwardingInjectionPoint)

Aggregations

InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)4 ForwardingInjectionPoint (org.jboss.weld.injection.ForwardingInjectionPoint)4 Type (java.lang.reflect.Type)3 ProcessInjectionPoint (javax.enterprise.inject.spi.ProcessInjectionPoint)3 Set (java.util.Set)2 Annotation (java.lang.annotation.Annotation)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1