Search in sources :

Example 6 with InjectionPoint

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

the class BeanBuilderTest method assertNonNullInjectionPointsFromBeanBuilder.

@Test
public void assertNonNullInjectionPointsFromBeanBuilder() {
    final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
    final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
    final Bean<?> newInjectionBean = beanBuilder.readFromType(at).create();
    for (final InjectionPoint ip : newInjectionBean.getInjectionPoints()) {
        Assert.assertNotNull(ip);
    }
}
Also used : BeanBuilder(org.apache.deltaspike.core.util.bean.BeanBuilder) ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Test(org.junit.Test)

Example 7 with InjectionPoint

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

the class ResourceInjectionUtilities method getResourceName.

public static String getResourceName(InjectionPoint injectionPoint) {
    Resource resource = getResourceAnnotated(injectionPoint).getAnnotation(Resource.class);
    String mappedName = resource.mappedName();
    if (!mappedName.equals("")) {
        return mappedName;
    }
    String name = resource.name();
    if (!name.equals("")) {
        //see if this is a prefixed name
        //and if so just return it
        int firstSlash = name.indexOf("/");
        int colon = name.indexOf(":");
        if (colon != -1) {
            if (firstSlash == -1 || colon < firstSlash) {
                return name;
            }
        }
        return RESOURCE_LOOKUP_PREFIX + "/" + name;
    }
    String propertyName;
    if (injectionPoint.getMember() instanceof Field) {
        propertyName = injectionPoint.getMember().getName();
    } else if (injectionPoint.getMember() instanceof Method) {
        propertyName = getPropertyName((Method) injectionPoint.getMember());
        if (propertyName == null) {
            throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) injectionPoint.getMember());
        }
    } else {
        throw WeldLogger.ROOT_LOGGER.cannotInject(injectionPoint);
    }
    String className = injectionPoint.getMember().getDeclaringClass().getName();
    return RESOURCE_LOOKUP_PREFIX + "/" + className + "/" + propertyName;
}
Also used : Field(java.lang.reflect.Field) Resource(javax.annotation.Resource) Method(java.lang.reflect.Method) ParameterInjectionPoint(org.jboss.weld.injection.ParameterInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 8 with InjectionPoint

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

the class ConfigurationBean method create0.

protected <T> T create0(CreationalContext<T> creationalContext) {
    Map<String, Object> map = new AbstractMap<String, Object>() {

        @Override
        public Set<java.util.Map.Entry<String, Object>> entrySet() {
            return _configurationDependency.getConfiguration().entrySet();
        }
    };
    T instance = cast(Conversions.c().convert(map).to(_configurationDependency.getBeanClass()));
    InjectionPoint ip = getInjectionPoint(_currentInjectionPoint);
    if (ip == null) {
        return instance;
    }
    List<Decorator<?>> decorators = getDecorators(ip);
    if (decorators.isEmpty()) {
        return instance;
    }
    return Decorators.getOuterDelegate(cast(this), instance, creationalContext, cast(getBeanClass()), ip, _beanManagerImpl, decorators);
}
Also used : AbstractMap(java.util.AbstractMap) Decorator(javax.enterprise.inject.spi.Decorator) CurrentInjectionPoint(org.jboss.weld.injection.CurrentInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) EmptyInjectionPoint(org.jboss.weld.injection.EmptyInjectionPoint)

Example 9 with InjectionPoint

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

the class ReferenceBean method create0.

protected <T> T create0(CreationalContext<T> creationalContext) {
    T instance = cast(getServiceImpl());
    InjectionPoint ip = getInjectionPoint(_currentInjectionPoint);
    if (ip == null) {
        return instance;
    }
    List<Decorator<?>> decorators = getDecorators(ip);
    if (decorators.isEmpty()) {
        return instance;
    }
    return Decorators.getOuterDelegate(cast(this), instance, creationalContext, cast(getBeanClass()), ip, _beanManagerImpl, decorators);
}
Also used : Decorator(javax.enterprise.inject.spi.Decorator) CurrentInjectionPoint(org.jboss.weld.injection.CurrentInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) EmptyInjectionPoint(org.jboss.weld.injection.EmptyInjectionPoint)

Example 10 with InjectionPoint

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

the class BeanBuilderTest method assertNonNullInjectionPointsWhenOverriding.

@Test
public void assertNonNullInjectionPointsWhenOverriding() {
    final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
    final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
    beanBuilder.readFromType(at);
    // It's not easy to actually create these in the state we need, so we have to get the InjectionPonits,
    // create new ones with the correct info, null out the bean, set them as the new injection points
    // then move on.
    final Set<InjectionPoint> origInjectionPoints = beanBuilder.getInjectionPoints();
    beanBuilder.injectionPoints(beanBuilder.getInjectionPoints());
    final Set<InjectionPoint> newInjectionPoints = new HashSet<InjectionPoint>();
    for (InjectionPoint ip : origInjectionPoints) {
        newInjectionPoints.add(new ImmutableInjectionPoint((AnnotatedField) ip.getAnnotated(), ip.getQualifiers(), null, ip.isTransient(), ip.isDelegate()));
    }
    beanBuilder.injectionPoints(newInjectionPoints);
    final Bean<?> newInjectionBean = beanBuilder.create();
    for (final InjectionPoint ip : newInjectionBean.getInjectionPoints()) {
        Assert.assertNotNull(ip);
    }
}
Also used : BeanBuilder(org.apache.deltaspike.core.util.bean.BeanBuilder) ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) AnnotatedField(javax.enterprise.inject.spi.AnnotatedField) ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

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