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;
 
 import static org.jboss.weld.util.reflection.Reflections.cast;
 
 import java.util.Set;
 
 
 
The implicit producer bean

Parameters:
<X>
<T>
<S>
Author(s):
Gavin King
David Allen
Jozef Hartinger
 
 public abstract class AbstractProducerBean<X, T, S extends Memberextends AbstractBean<T, S> {
 
     private final AbstractClassBean<X> declaringBean;
 
     // Passivation flags
     private boolean passivationCapableBean;
     private boolean passivationCapableDependency;

    
Constructor

Parameters:
declaringBean The declaring bean
beanManager The Bean manager
 
     public AbstractProducerBean(BeanAttributes<T> attributesBeanIdentifier identifierAbstractClassBean<X> declaringBeanBeanManagerImpl beanManagerServiceRegistry services) {
         super(attributesidentifierbeanManager);
         this. = declaringBean;
     }
 
     @Override
     // Overridden to provide the class of the bean that declares the producer
     // method/field
     public Class<?> getBeanClass() {
         return getDeclaringBean().getBeanClass();
     }

    
Initializes the type
 
     protected void initType() {
         try {
             this. = getEnhancedAnnotated().getJavaClass();
         } catch (ClassCastException e) {
             Type type = Beans.getDeclaredBeanType(getClass());
             throw ..producerCastError(getEnhancedAnnotated().getJavaClass(), (type == null ? " unknown " : type), e);
         }
     }

    
Initializes the bean and its metadata
 
     @Override
     public void internalInitialize(BeanDeployerEnvironment environment) {
         getDeclaringBean().initialize(environment);
         super.internalInitialize(environment);
        initPassivationCapable();
    }
    private void initPassivationCapable() {
        if (isNormalScoped()) {
            this. = true;
        } else if (getScope().equals(Dependent.class) && ) {
            this. = true;
        } else {
            this. = false;
        }
    }
    @Override
    public boolean isPassivationCapableBean() {
        return ;
    }
    @Override
    public boolean isPassivationCapableDependency() {
        return ;
    }
    @Override
        return getProducer().getInjectionPoints();
    }

    
Validates the return value

Parameters:
instance The instance to validate
    protected T checkReturnValue(T instance) {
        if (instance == null && !isDependent()) {
            throw ..nullNotAllowedFromProducer(getProducer());
        }
        if (instance == null) {
            InjectionPoint injectionPoint = .getServices().get(CurrentInjectionPoint.class).peek();
            if (injectionPoint != null) {
                Class<?> injectionPointRawType = Reflections.getRawType(injectionPoint.getType());
                if (injectionPointRawType.isPrimitive()) {
                    return cast(Defaults.defaultValue(injectionPointRawType));
                }
            }
        }
        if (instance != null) {
            if (!(instance instanceof Serializable)) {
                boolean passivating = .isPassivatingScope(getScope());
                if (passivating) {
                    throw ..nonSerializableProductError(getProducer());
                }
                InjectionPoint injectionPoint = .getServices().get(CurrentInjectionPoint.class).peek();
                if (injectionPoint != null && injectionPoint.getBean() != null) {
                    if (Beans.isPassivatingScope(injectionPoint.getBean(), )) {
                        if (injectionPoint.getMember() instanceof Field && !injectionPoint.isTransient()) {
                            throw ..nonSerializableFieldInjectionError(thisinjectionPoint);
                        }
                    }
                }
            }
        }
        return instance;
    }
    @Override
    protected void checkType() {
            throw ..passivatingBeanNeedsSerializableImpl(this);
        }
    }
    protected boolean isTypeSerializable(final Object instance) {
        return instance instanceof Serializable;
    }

    
Creates an instance of the bean

Returns:
The instance
    public T create(final CreationalContext<T> creationalContext) {
        T instance = getProducer().produce(creationalContext);
        instance = checkReturnValue(instance);
        return instance;
    }
    public void destroy(T instanceCreationalContext<T> creationalContext) {
        try {
            getProducer().dispose(instance);
        } catch (Exception e) {
            ..errorDestroying(instancethis);
            ..catchingDebug(e);
        } finally {
            if (getDeclaringBean().isDependent()) {
                creationalContext.release();
            }
        }
    }

    
Returns the declaring bean

Returns:
The bean representation
    public AbstractClassBean<X> getDeclaringBean() {
        return ;
    }
    @Override
    public abstract AnnotatedMember<? super X> getAnnotated();
    @Override
    public abstract EnhancedAnnotatedMember<T, ?, S> getEnhancedAnnotated();
New to GrepCode? Check out our FAQ X