Search in sources :

Example 1 with InjectionPoint

use of javax.enterprise.inject.spi.InjectionPoint in project jersey by jersey.

the class CdiComponentProvider method processInjectionTarget.

@SuppressWarnings("unused")
private void processInjectionTarget(@Observes final ProcessInjectionTarget event) {
    final InjectionTarget it = event.getInjectionTarget();
    final Class<?> componentClass = event.getAnnotatedType().getJavaClass();
    final Set<InjectionPoint> cdiInjectionPoints = filterHk2InjectionPointsOut(it.getInjectionPoints());
    for (final InjectionPoint injectionPoint : cdiInjectionPoints) {
        final Member member = injectionPoint.getMember();
        if (member instanceof Field) {
            addInjecteeToSkip(componentClass, fieldsToSkip, (Field) member);
        } else if (member instanceof Method) {
            addInjecteeToSkip(componentClass, methodsToSkip, (Method) member);
        }
    }
    InjectionManagerInjectedCdiTarget target = null;
    if (isJerseyOrDependencyType(componentClass)) {
        target = new InjectionManagerInjectedCdiTarget(it) {

            @Override
            public Set<InjectionPoint> getInjectionPoints() {
                // CDI will not treat these classes as CDI beans (as they are not).
                return Collections.emptySet();
            }
        };
    } else if (isJaxRsComponentType(componentClass) || jaxrsInjectableTypes.contains(event.getAnnotatedType().getBaseType())) {
        target = new InjectionManagerInjectedCdiTarget(it) {

            @Override
            public Set<InjectionPoint> getInjectionPoints() {
                // Inject CDI beans into JAX-RS resources/providers/application.
                return cdiInjectionPoints;
            }
        };
    }
    if (target != null) {
        notify(target);
        //noinspection unchecked
        event.setInjectionTarget(target);
    }
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) HashSet(java.util.HashSet) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) ProcessInjectionTarget(javax.enterprise.inject.spi.ProcessInjectionTarget) Method(java.lang.reflect.Method) Member(java.lang.reflect.Member)

Example 2 with InjectionPoint

use of javax.enterprise.inject.spi.InjectionPoint in project aries by apache.

the class ReferenceExtension method processInjectionTarget.

void processInjectionTarget(@Observes @SuppressWarnings("rawtypes") ProcessInjectionPoint pip, BeanManager manager) {
    InjectionPoint injectionPoint = pip.getInjectionPoint();
    Annotated annotated = injectionPoint.getAnnotated();
    Reference reference = annotated.getAnnotation(Reference.class);
    if (reference == null) {
        return;
    }
    try {
        BeanManagerImpl beanManagerImpl = ((BeanManagerProxy) manager).delegate();
        ReferenceDependency referenceDependency = new ReferenceDependency(beanManagerImpl, reference, injectionPoint);
        _referenceDependencies.add(referenceDependency);
        if (_log.isDebugEnabled()) {
            _log.debug("CDIe - Found OSGi service reference {}", referenceDependency);
        }
    } catch (Exception e) {
        if (_log.isErrorEnabled()) {
            _log.error("CDIe - Error on reference {}", reference, e);
        }
    }
}
Also used : Annotated(javax.enterprise.inject.spi.Annotated) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Reference(org.osgi.service.cdi.annotations.Reference) BeanManagerProxy(org.jboss.weld.bean.builtin.BeanManagerProxy)

Example 3 with InjectionPoint

use of javax.enterprise.inject.spi.InjectionPoint in project aries by apache.

the class Phase_Publish method processConfigurationDependencies.

private void processConfigurationDependencies(BeanManagerImpl beanManagerImpl) {
    for (ConfigurationDependency configurationDependency : _bc.getConfigurations()) {
        InjectionPoint injectionPoint = configurationDependency.getInjectionPoint();
        ConfigurationBean bean = new ConfigurationBean(configurationDependency, beanManagerImpl, injectionPoint.getType(), injectionPoint.getQualifiers());
        beanManagerImpl.addBean(bean);
    }
}
Also used : ConfigurationBean(org.apache.aries.cdi.container.internal.bean.ConfigurationBean) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 4 with InjectionPoint

use of javax.enterprise.inject.spi.InjectionPoint in project aries by apache.

the class ConfigurationExtension method processInjectionTarget.

void processInjectionTarget(@Observes @SuppressWarnings("rawtypes") ProcessInjectionPoint pip) {
    InjectionPoint injectionPoint = pip.getInjectionPoint();
    Annotated annotated = injectionPoint.getAnnotated();
    Configuration configuration = annotated.getAnnotation(Configuration.class);
    if (configuration == null) {
        return;
    }
    Class<?> beanClass = injectionPoint.getBean().getBeanClass();
    String name = beanClass.getName();
    Named named = annotated.getAnnotation(Named.class);
    if (named != null) {
        name = named.value();
    }
    ConfigurationDependency configurationDependency = new ConfigurationDependency(_bundleContext, configuration.value(), configuration.required(), name, injectionPoint);
    _configurations.add(configurationDependency);
    if (_log.isDebugEnabled()) {
        _log.debug("CDIe - Found OSGi configuration dependency {}", configurationDependency);
    }
}
Also used : Annotated(javax.enterprise.inject.spi.Annotated) Named(javax.inject.Named) Configuration(org.osgi.service.cdi.annotations.Configuration) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 5 with InjectionPoint

use of javax.enterprise.inject.spi.InjectionPoint in project deltaspike by apache.

the class ConfigurationExtension method collectDynamicTypes.

public void collectDynamicTypes(@Observes ProcessBean<?> processBean) {
    for (final InjectionPoint ip : processBean.getBean().getInjectionPoints()) {
        final ConfigProperty annotation = ip.getAnnotated().getAnnotation(ConfigProperty.class);
        if (annotation == null || annotation.converter() == ConfigResolver.Converter.class) {
            continue;
        }
        dynamicConfigTypes.add(ip.getType());
    }
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty)

Aggregations

InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)11 ImmutableInjectionPoint (org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint)3 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 Annotated (javax.enterprise.inject.spi.Annotated)2 Decorator (javax.enterprise.inject.spi.Decorator)2 ProcessInjectionPoint (javax.enterprise.inject.spi.ProcessInjectionPoint)2 BeanBuilder (org.apache.deltaspike.core.util.bean.BeanBuilder)2 CurrentInjectionPoint (org.jboss.weld.injection.CurrentInjectionPoint)2 EmptyInjectionPoint (org.jboss.weld.injection.EmptyInjectionPoint)2 Test (org.junit.Test)2 Member (java.lang.reflect.Member)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Resource (javax.annotation.Resource)1 AnnotatedField (javax.enterprise.inject.spi.AnnotatedField)1 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)1 ProcessInjectionTarget (javax.enterprise.inject.spi.ProcessInjectionTarget)1