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.bean.BeanIdentifiers.forManagedBean;
 
 import java.util.Set;
 
 
Represents a simple bean

Parameters:
<T> The type (class) of the bean
Author(s):
Pete Muir
Marius Bogoevici
Ales Justin
Marko Luksa
 
 public class ManagedBean<T> extends AbstractClassBean<T> {
 
     private final boolean proxiable;
 
     private boolean passivationCapableBean;
     private boolean passivationCapableDependency;

    
Creates a simple, annotation defined Web Bean

Parameters:
<T> The type
clazz The class
beanManager the current manager
Returns:
A Web Bean
 
     public static <T> ManagedBean<T> of(BeanAttributes<T> attributesEnhancedAnnotatedType<T> clazzBeanManagerImpl beanManager) {
         return new ManagedBean<T>(attributesclazzcreateId(attributesclazz), beanManager);
     }
 
     private static BeanIdentifier createId(BeanAttributes<?> attributesEnhancedAnnotatedType<?> clazz) {
         if (Dependent.class.equals(attributes.getScope()) || ApplicationScoped.class.equals(attributes.getScope())) {
             return new ManagedBeanIdentifier(clazz.slim().getIdentifier());
         } else {
             return new StringBeanIdentifier(forManagedBean(clazz));
         }
     }

    
Constructor

Parameters:
type The type of the bean
beanManager The Bean manager
 
     protected ManagedBean(BeanAttributes<T> attributesEnhancedAnnotatedType<T> typeBeanIdentifier identifierBeanManagerImpl beanManager) {
         super(attributestypeidentifierbeanManager);
         this. = Proxies.isTypesProxyable(getTypes(), beanManager.getServices());
     }
 
     @Override
     public void internalInitialize(BeanDeployerEnvironment environment) {
         super.internalInitialize(environment);
         initPassivationCapable();
     }
 
    private void initPassivationCapable() {
    }
    @Override
    public void initializeAfterBeanDiscovery() {
            this. = false;
        }
            this. = false;
        }
        super.initializeAfterBeanDiscovery();
    }
    private boolean allDecoratorsArePassivationCapable() {
        return getFirstNonPassivationCapableDecorator() == null;
    }
        for (Decorator<?> decorator : getDecorators()) {
            if (!Decorators.isPassivationCapable(decorator)) {
                return decorator;
            }
        }
        return null;
    }
    private boolean allInterceptorsArePassivationCapable() {
        return getFirstNonPassivationCapableInterceptor() == null;
    }
        for (InterceptorClassMetadata<?> interceptorMetadata : getBeanManager().getInterceptorModelRegistry().get(getAnnotated()).getAllInterceptors()) {
            if (!Reflections.isSerializable(interceptorMetadata.getJavaClass())) {
                return interceptorMetadata;
            }
        }
        return null;
    }

    
Creates an instance of the bean

Returns:
The instance
    @Override
    public T create(CreationalContext<T> creationalContext) {
        T instance = getProducer().produce(creationalContext);
        getProducer().inject(instancecreationalContext);
        if (.isContextActive(RequestScoped.class)) {
            getProducer().postConstruct(instance);
        } else {
            /*
             * CDI-219
             * The request scope is active during @PostConstruct callback of any bean.
             */
            RequestContext context = getUnboundRequestContext();
            try {
                context.activate();
                getProducer().postConstruct(instance);
            } finally {
                context.invalidate();
                context.deactivate();
            }
        }
        return instance;
    }

    
Destroys an instance of the bean

Parameters:
instance The instance
    @Override
    public void destroy(T instanceCreationalContext<T> creationalContext) {
        try {
            getProducer().preDestroy(instance);
            // WELD-1010 hack?
            if (creationalContext instanceof CreationalContextImpl) {
                ((CreationalContextImpl<T>) creationalContext).release(thisinstance);
            } else {
                creationalContext.release();
            }
        } catch (Exception e) {
            ..errorDestroying(instancethis);
            ..catchingDebug(e);
        }
    }

    
Validates the type
    @Override
    protected void checkType() {
        if (!isDependent() && getEnhancedAnnotated().isParameterizedType()) {
            throw ..beanMustBeDependent();
        }
        boolean passivating = .isPassivatingScope(getScope());
        if (passivating && !isPassivationCapableBean()) {
            if (!getEnhancedAnnotated().isSerializable()) {
                throw ..passivatingBeanNeedsSerializableImpl(this);
            } else if (hasDecorators() && !allDecoratorsArePassivationCapable()) {
            } else if (hasInterceptors() && !allInterceptorsArePassivationCapable()) {
            }
        }
    }
    @Override
    protected void checkBeanImplementation() {
        super.checkBeanImplementation();
        if (isNormalScoped()) {
            for (EnhancedAnnotatedField<?, ?> field : getEnhancedAnnotated().getEnhancedFields()) {
                if (field.isPublic() && !field.isStatic()) {
                    throw ..publicFieldOnNormalScopedBeanNotAllowed(field);
                }
            }
        }
    }
    @Override
    protected void specialize() {
        Set<? extends AbstractBean<?, ?>> specializedBeans = getSpecializedBeans();
        if (specializedBeans.isEmpty()) {
            throw ..specializingBeanMustExtendABean(this);
        }
        for (AbstractBean<?, ?> specializedBean : specializedBeans) {
            if (!(specializedBean instanceof ManagedBean<?>)) {
                throw ..specializingManagedBeanCanExtendOnlyManagedBeans(thisspecializedBean);
            }
        }
    }
    @Override
    protected boolean isInterceptionCandidate() {
        return !((this instanceof InterceptorImpl<?>) || (this instanceof DecoratorImpl<?>));
    }
    @Override
    public String toString() {
        return "Managed Bean [" + getBeanClass().toString() + "] with qualifiers [" + Formats.formatAnnotations(getQualifiers()) + "]";
    }
    @Override
    public boolean isProxyable() {
        return ;
    }
    @Override
    public boolean isPassivationCapableBean() {
        return ;
    }
    @Override
    public boolean isPassivationCapableDependency() {
        return ;
    }
        final Bean<?> bean = .resolve(.getBeans(RequestContext.class.));
        final CreationalContext<?> ctx = .createCreationalContext(bean);
        return (RequestContext.getReference(beanRequestContext.classctx);
    }
New to GrepCode? Check out our FAQ X