Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.injection;
 
 import static org.jboss.weld.util.collections.WeldCollections.immutableGuavaList;
 import static org.jboss.weld.util.collections.WeldCollections.immutableGuavaSet;
 import static org.jboss.weld.util.collections.WeldCollections.immutableList;
 
 import java.util.List;
 import java.util.Set;
 
 
Factory class that producer javax.enterprise.inject.spi.InjectionPoint instances for fields, parameters, methods and constructors. The javax.enterprise.inject.spi.ProcessInjectionPoint event is fired for each created injection point unless the silentInstance() is used.

Author(s):
Jozef Hartinger
 
 public class InjectionPointFactory {
 
     private InjectionPointFactory() {
     }
 
     private static final InjectionPointFactory INSTANCE = new InjectionPointFactory();
     private static final InjectionPointFactory SILENT_INSTANCE = new InjectionPointFactory() {
 
         @Override
         protected <T, X> FieldInjectionPointAttributes<T, X> processInjectionPoint(
                 FieldInjectionPointAttributes<T, X> injectionPointAttributesClass<?> declaringComponentClass,
                 BeanManagerImpl manager) {
             // NOOP
             return injectionPointAttributes;
         }
 
         @Override
         protected <T, X> ParameterInjectionPointAttributes<T, X> processInjectionPoint(
                 ParameterInjectionPointAttributes<T, X> injectionPointAttributesClass<?> declaringComponentClass,
                 BeanManagerImpl manager) {
             // NOOP
             return injectionPointAttributes;
         }
     };

    
Returns the default InjectionPointFactory singleton.

Returns:
the default InjectionPointFactory singleton
 
     public static InjectionPointFactory instance() {
         return ;
     }

    
Returns an InjectionPointFactory instance that never produces a javax.enterprise.inject.spi.ProcessInjectionPoint event. This is used for creating observer method injection points of extensions and proxy classes.

Returns:
an InjectionPointFactory instance
 
    public static InjectionPointFactory silentInstance() {
        return ;
    }

    
Notifies CDI extension of a given javax.enterprise.inject.spi.InjectionPoint.
    protected <T, X> FieldInjectionPointAttributes<T, X> processInjectionPoint(
            FieldInjectionPointAttributes<T, X> injectionPointAttributesClass<?> declaringComponentClass,
            BeanManagerImpl manager) {
        return manager.getContainerLifecycleEvents().fireProcessInjectionPoint(injectionPointAttributes,
                declaringComponentClassmanager);
    }

    
Notifies CDI extension of a given javax.enterprise.inject.spi.InjectionPoint.
    protected <T, X> ParameterInjectionPointAttributes<T, X> processInjectionPoint(
            ParameterInjectionPointAttributes<T, X> injectionPointAttributesClass<?> declaringComponentClass,
            BeanManagerImpl manager) {
        return manager.getContainerLifecycleEvents().fireProcessInjectionPoint(injectionPointAttributes,
                declaringComponentClassmanager);
    }
    /*
     * Creation of basic InjectionPoints
     */

    
Creates a new FieldInjectionPoint and fires the javax.enterprise.inject.spi.ProcessInjectionPoint event.

Parameters:
field
declaringBean
declaringComponentClass used for resolution of type variables of the injection point type
manager
Returns:
    public <T, X> FieldInjectionPoint<T, X> createFieldInjectionPoint(EnhancedAnnotatedField<T, X> field,
            Bean<?> declaringBeanClass<?> declaringComponentClassBeanManagerImpl manager) {
        FieldInjectionPointAttributes<T, X> attributes = InferringFieldInjectionPointAttributes.of(fielddeclaringBean,
            declaringComponentClassmanager);
        attributes = processInjectionPoint(attributesdeclaringComponentClassmanager);
        return new FieldInjectionPoint<T, X>(attributes);
    }

    
Creates a new ParameterInjectionPoint and fires the javax.enterprise.inject.spi.ProcessInjectionPoint event.

Parameters:
parameter
declaringBean
declaringComponentClass used for resolution of type variables of the injection point type
manager
Returns:
    public <T, X> ParameterInjectionPoint<T, X> createParameterInjectionPoint(EnhancedAnnotatedParameter<T, X> parameter,
            Bean<?> declaringBeanClass<?> declaringComponentClassBeanManagerImpl manager) {
        ParameterInjectionPointAttributes<T, X> attributes = InferringParameterInjectionPointAttributes.of(parameter,
            declaringBeandeclaringComponentClassmanager);
        attributes = processInjectionPoint(attributesdeclaringComponentClassmanager);
        return new ParameterInjectionPointImpl<T, X>(attributes);
    }
    /*
     * Creation of callable InjectionPoints
     */
    public <T> ConstructorInjectionPoint<T> createConstructorInjectionPoint(Bean<T> declaringBean,
            EnhancedAnnotatedType<T> typeBeanManagerImpl manager) {
        EnhancedAnnotatedConstructor<T> constructor = Beans.getBeanConstructorStrict(type);
        return createConstructorInjectionPoint(declaringBeantype.getJavaClass(), constructormanager);
    }
    public <T> ConstructorInjectionPoint<T> createConstructorInjectionPoint(Bean<T> declaringBean,
            Class<?> declaringComponentClassEnhancedAnnotatedConstructor<T> constructorBeanManagerImpl manager) {
        return new ConstructorInjectionPoint<T>(constructordeclaringBeandeclaringComponentClassthismanager);
    }
    public <T, X> MethodInjectionPoint<T, X> createMethodInjectionPoint(EnhancedAnnotatedMethod<T, X> enhancedMethod,
            Bean<?> declaringBeanClass<?> declaringComponentClassClass<? extends AnnotationspecialParameterMarkerBeanManagerImpl manager) {
        if (enhancedMethod.isStatic()) {
            return new StaticMethodInjectionPoint<T, X>(enhancedMethoddeclaringBeandeclaringComponentClassspecialParameterMarkerthismanager);
        } else {
            return new VirtualMethodInjectionPoint<T, X>(enhancedMethoddeclaringBeandeclaringComponentClassspecialParameterMarkerthismanager);
        }
    }
    /*
     * Utility methods for field InjectionPoints
     */
    public List<Set<FieldInjectionPoint<?, ?>>> getFieldInjectionPoints(Bean<?> declaringBeanEnhancedAnnotatedType<?> type,
            BeanManagerImpl manager) {
        List<Set<FieldInjectionPoint<?, ?>>> injectableFieldsList = new ArrayList<Set<FieldInjectionPoint<?, ?>>>();
        if (type.slim() instanceof UnbackedAnnotatedType<?>) {
            // external AnnotatedTypes require special treatment
            Collection<EnhancedAnnotatedField<?, ?>> allFields = type.getEnhancedFields(Inject.class);
            for (Class<?> clazz = type.getJavaClass(); clazz != null && clazz != Object.classclazz = clazz.getSuperclass()) {
                ArraySet<FieldInjectionPoint<?, ?>> fields = new ArraySet<FieldInjectionPoint<?, ?>>();
                for (EnhancedAnnotatedField<?, ?> field : allFields) {
                    if (!field.isStatic() && field.getJavaMember().getDeclaringClass().equals(clazz)) {
                        addFieldInjectionPoint(fieldfieldsdeclaringBeantype.getJavaClass(), manager);
                    }
                }
                injectableFieldsList.add(0, immutableGuavaSet(fields));
            }
        } else {
            for (EnhancedAnnotatedType<?> t = typet != null && !t.getJavaClass().equals(Object.class); t = t
                    .getEnhancedSuperclass()) {
                ArraySet<FieldInjectionPoint<?, ?>> fields = new ArraySet<FieldInjectionPoint<?, ?>>();
                for (EnhancedAnnotatedField<?, ?> annotatedField : t.getDeclaredEnhancedFields(Inject.class)) {
                    if (!annotatedField.isStatic()) {
                        addFieldInjectionPoint(annotatedFieldfieldsdeclaringBeant.getJavaClass(), manager);
                    }
                }
                injectableFieldsList.add(0, immutableGuavaSet(fields));
            }
        }
        return immutableGuavaList(injectableFieldsList);
    }
    private void addFieldInjectionPoint(EnhancedAnnotatedField<?, ?> annotatedField,
            Set<FieldInjectionPoint<?, ?>> injectableFieldsBean<?> declaringBeanClass<?> declaringComponentClass,
            BeanManagerImpl manager) {
        if (annotatedField.isFinal()) {
            throw ..qualifierOnFinalField(annotatedField);
        }
        injectableFields.add(createFieldInjectionPoint(annotatedFielddeclaringBeandeclaringComponentClassmanager));
    }
    /*
     * Utility methods for parameter InjectionPoints
     */
    public <X> List<ParameterInjectionPoint<?, X>> getParameterInjectionPoints(EnhancedAnnotatedCallable<?, X, ?> callable,
            Bean<?> declaringBeanClass<?> declaringComponentClassBeanManagerImpl managerboolean observerOrDisposer) {
        List<ParameterInjectionPoint<?, X>> parameters = new ArrayList<ParameterInjectionPoint<?, X>>();
        /*
         * bean that the injection point belongs to this is null for observer and disposer methods
         */
        Bean<?> bean = null;
        if (!observerOrDisposer) {
            bean = declaringBean;
        }
        for (EnhancedAnnotatedParameter<?, X> parameter : callable.getEnhancedParameters()) {
            if (isSpecialParameter(parameter)) {
                parameters.add(SpecialParameterInjectionPoint.of(parameterbeandeclaringBean.getBeanClass(), manager));
            } else {
                parameters.add(createParameterInjectionPoint(parameterbeandeclaringComponentClassmanager));
            }
        }
        return immutableList(parameters);
    }
    private boolean isSpecialParameter(EnhancedAnnotatedParameter<?, ?> parameter) {
        return parameter.isAnnotationPresent(Disposes.class) || parameter.isAnnotationPresent(Observes.class);
    }
New to GrepCode? Check out our FAQ X