Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2008, 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;
 
 
 

Author(s):
pmuir
 
 public class EEResourceProducerField<X, T> extends ProducerField<X, T> {
 
     private static class EEResourceCallable<T> extends AbstractEECallable<T> {
 
         private static final long serialVersionUID = 6287931036073200963L;
 
         private final BeanIdentifier beanId;
         private transient T instance;
         private final CreationalContext<T> creationalContext;
 
         private EEResourceCallable(BeanManagerImpl beanManagerProducerField<?, T> producerFieldCreationalContext<T> creationalContext, T instance) {
             super(beanManager);
             this. = producerField.getIdentifier();
             this. = creationalContext;
             this. = instance;
         }
 
         public T call() throws Exception {
             if ( == null) {
                 Contextual<T> contextual = getBeanManager().getServices().get(ContextualStore.class).<Contextual<T>, T>getContextual();
                 if (contextual instanceof EEResourceProducerField<?, ?>) {
                     this. = Reflections.<EEResourceProducerField<?, T>>cast(contextual).createUnderlying();
                 } else {
                     throw ..beanNotEeResourceProducer(contextual);
                 }
             }
             return ;
         }
 
         @Override
         public String toString() {
             return  == null ? "null" : .toString();
         }
 
     }

    
Creates an EE resource producer field

Parameters:
field The underlying method abstraction
declaringBean The declaring bean abstraction
manager the current manager
Returns:
A producer field
 
     public static <X, T> EEResourceProducerField<X, T> of(BeanAttributes<T> attributesEnhancedAnnotatedField<T, ? super X> fieldAbstractClassBean<X> declaringBeanDisposalMethod<X, ?> disposalMethodBeanManagerImpl managerServiceRegistry services) {
         return new EEResourceProducerField<X, T>(attributesfielddeclaringBeandisposalMethodmanagerservices);
     }
 
     private ProxyFactory<T> proxyFactory;
 
     private final Class<T> rawType;
 
    protected EEResourceProducerField(BeanAttributes<T> attributesEnhancedAnnotatedField<T, ? super X> fieldAbstractClassBean<X> declaringBeanDisposalMethod<X, ?> disposalMethodBeanManagerImpl managerServiceRegistry services) {
        super(attributesfielddeclaringBeandisposalMethodmanagerservices);
        this. = field.getJavaClass();
    }
    @Override
    public void internalInitialize(BeanDeployerEnvironment environment) {
        super.internalInitialize(environment);
        checkEEResource();
         = new ProxyFactory<T>(getBeanManager().getContextId(), getType(), getTypes(), this);
    }
    protected void checkEEResource() {
        if (!getScope().equals(Dependent.class)) {
            throw ..nonDependentResourceProducerField(this);
        }
        if (getName() != null) {
            throw ..namedResourceProducerField(this);
        }
        EJBApiAbstraction ejbApiAbstraction = .getServices().get(EJBApiAbstraction.class);
        PersistenceApiAbstraction persistenceApiAbstraction = .getServices().get(PersistenceApiAbstraction.class);
        WSApiAbstraction wsApiAbstraction = .getServices().get(WSApiAbstraction.class);
        if (!(getAnnotated().isAnnotationPresent(ejbApiAbstraction.RESOURCE_ANNOTATION_CLASS)
                || getAnnotated().isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_CONTEXT_ANNOTATION_CLASS)
                || getAnnotated().isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_UNIT_ANNOTATION_CLASS)
                || getAnnotated().isAnnotationPresent(ejbApiAbstraction.EJB_ANNOTATION_CLASS)
                || getAnnotated().isAnnotationPresent(wsApiAbstraction.WEB_SERVICE_REF_ANNOTATION_CLASS))) {
            throw ..invalidResourceProducerField(getAnnotated());
        }
    }
    @Override
    public T create(CreationalContext<T> creationalContext) {
        final T beanInstance = getProducer().produce(creationalContext);
        if (Reflections.isFinal() || Serializable.class.isAssignableFrom(beanInstance.getClass())) {
            return checkReturnValue(beanInstance);
        } else {
            BeanInstance proxyBeanInstance = new EnterpriseTargetBeanInstance(getTypes(), new CallableMethodHandler(new EEResourceCallable<T>(getBeanManager(),
                    thiscreationalContextbeanInstance)));
            return checkReturnValue(.create(proxyBeanInstance));
        }
    }

    
Access to the underlying producer field, performs return value check.
    private T createUnderlying(CreationalContext<T> creationalContext) {
        return super.create(creationalContext);
    }
    @Override
    public boolean isPassivationCapableBean() {
        return true;
    }
    @Override
    public String toString() {
        return "Resource " + super.toString();
    }
New to GrepCode? Check out our FAQ X