Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2013, 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.bean.builtin.ee;
import static org.jboss.weld.util.reflection.Reflections.cast;
A resource producer field that is static (not injected).

Parameters:
<X>
<T>
Author(s):
Jozef Hartinger
public class StaticEEResourceProducerField<X, T> extends EEResourceProducerField<X, T> {
    public static <X, T> StaticEEResourceProducerField<X, T> of(BeanAttributes<T> attributes,
            EnhancedAnnotatedField<T, ? super X> fieldAbstractClassBean<X> declaringBean,
            DisposalMethod<X, ?> disposalMethodBeanManagerImpl managerServiceRegistry services) {
        return new StaticEEResourceProducerField<X, T>(attributesfielddeclaringBeandisposalMethodmanagerservices);
    }
    private final ResourceInjection<T> resourceInjection;
    private final Field accessibleField;
    private final InjectionContextImpl<X> injectionContext// injection context is shared since it does not use instance state
    protected StaticEEResourceProducerField(BeanAttributes<T> attributesEnhancedAnnotatedField<T, ? super X> field,
            AbstractClassBean<X> declaringBeanDisposalMethod<X, ?> disposalMethodBeanManagerImpl manager,
            ServiceRegistry services) {
        super(attributesfielddeclaringBeandisposalMethodmanagerservices);
        this. = getResourceInjection(fielddeclaringBeanmanager);
        this. = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Field>(field.getJavaMember()));
        this. = new InjectionContextImpl<X>(managerdeclaringBean.getInjectionTarget(), declaringBean.getAnnotated(), null) {
            @Override
            public void proceed() {
            }
        };
    }
    protected ResourceInjection<T> getResourceInjection(EnhancedAnnotatedField<T, ? super X> field,
            AbstractClassBean<X> declaringBeanBeanManagerImpl manager) {
        FieldInjectionPoint<T, X> injectionPoint = cast(InjectionPointFactory.silentInstance().createFieldInjectionPoint(fielddeclaringBeandeclaringBean.getBeanClass(), manager));
        return ResourceInjectionFactory.instance().getStaticProducerFieldResourceInjection(injectionPoint);
    }
    @Override
    public T create(CreationalContext<T> creationalContext) {
        if ( != null) {
            return .getResourceReference(creationalContext);
        } else {
            .run();
            try {
                return Reflections.cast(.get(null));
            } catch (IllegalAccessException e) {
                throw new WeldException(e);
            }
        }
    }
New to GrepCode? Check out our FAQ X