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 java.util.Set;
 
 
An enterprise bean representation

Parameters:
<T> The type (class) of the bean
Author(s):
Pete Muir
Ales Justin
 
 
 public class SessionBean<T> extends AbstractClassBean<T> {
     // The EJB descriptor
     private final InternalEjbDescriptor<T> ejbDescriptor;
 
     private Instantiator<T> proxyInstantiator;

    
Creates a simple, annotation defined Enterprise Web Bean using the annotations specified on type

Parameters:
<T> The type
beanManager the current manager
type the AnnotatedType to use
Returns:
An Enterprise Web Bean
 
     public static <T> SessionBean<T> of(BeanAttributes<T> attributesInternalEjbDescriptor<T> ejbDescriptorBeanManagerImpl beanManagerEnhancedAnnotatedType<T> type) {
         return new SessionBean<T>(attributestypeejbDescriptornew StringBeanIdentifier(BeanIdentifiers.forSessionBean(typeejbDescriptor)), beanManager);
     }

    
Constructor

Parameters:
type The type of the bean
manager The Bean manager
 
     protected SessionBean(BeanAttributes<T> attributesEnhancedAnnotatedType<T> typeInternalEjbDescriptor<T> ejbDescriptorBeanIdentifier identifierBeanManagerImpl manager) {
         super(attributestypeidentifiermanager);
         this. = ejbDescriptor;
         setProducer(.getLocalInjectionTargetFactory(type).createInjectionTarget(typethisfalse));
     }

    
Initializes the bean and its metadata
 
     @Override
     public void internalInitialize(BeanDeployerEnvironment environment) {
         super.internalInitialize(environment);
         checkEJBTypeAllowed();
         checkConflictingRoles();
        checkObserverMethods();
        checkScopeAllowed();
    }

    
Validates for non-conflicting roles
    protected void checkConflictingRoles() {
        if (getType().isAnnotationPresent(Interceptor.class)) {
            throw ..ejbCannotBeInterceptor(getType());
        }
        if (getType().isAnnotationPresent(Decorator.class)) {
            throw ..ejbCannotBeDecorator(getType());
        }
    }

    
Check that the scope type is allowed by the stereotypes on the bean and the bean type
    protected void checkScopeAllowed() {
        if (.isStateless() && !isDependent()) {
        }
        if (.isSingleton() && !(isDependent() || getScope().equals(ApplicationScoped.class))) {
            throw ..scopeNotAllowedOnSingletonBean(getScope(), getType());
        }
    }
    @Override
    protected void specialize() {
        Set<? extends AbstractBean<?, ?>> specializedBeans = getSpecializedBeans();
        if (specializedBeans.isEmpty()) {
        }
        for (AbstractBean<?, ?> specializedBean : specializedBeans) {
            if (!(specializedBean instanceof SessionBean<?>)) {
                throw ..specializingEnterpriseBeanMustExtendAnEnterpriseBean(this);
            }
        }
    }

    
Creates an instance of the bean

Returns:
The instance
    @Override
    public T create(final CreationalContext<T> creationalContext) {
        return .newInstance(creationalContext);
    }
    @Override
    public void destroy(T instanceCreationalContext<T> creationalContext) {
        if (instance == null) {
            throw ..cannotDestroyNullBean(this);
        }
        if (!(instance instanceof EnterpriseBeanInstance)) {
            throw ..cannotDestroyEnterpriseBeanNotCreated(instance);
        }
        EnterpriseBeanInstance enterpriseBeanInstance = (EnterpriseBeanInstanceinstance;
        enterpriseBeanInstance.destroy(.thiscreationalContext);
        creationalContext.release();
    }

    
Validates the bean type
    private void checkEJBTypeAllowed() {
        if (.isMessageDriven()) {
            throw ..messageDrivenBeansCannotBeManaged(this);
        }
    }
    @Override
    protected void checkType() {
        if (!isDependent() && getEnhancedAnnotated().isGeneric()) {
            throw ..genericSessionBeanMustBeDependent(this);
        }
        boolean passivating = .getServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isPassivating();
        if (passivating && !isPassivationCapableBean()) {
            throw ..passivatingBeanNeedsSerializableImpl(this);
        }
    }
        return ;
    }
    public boolean isClientCanCallRemoveMethods() {
        return getEjbDescriptor().isStateful() && isDependent();
    }

    
If there are any observer methods, they must be static or business methods.
    protected void checkObserverMethods() {
        Collection<EnhancedAnnotatedMethod<?, ? super T>> observerMethods = BeanMethods.getObserverMethods(this.getEnhancedAnnotated());
        if (!observerMethods.isEmpty()) {
            Set<MethodSignaturebusinessMethodSignatures = getBusinessMethodSignatures();
            for (EnhancedAnnotatedMethod<?, ? super T> observerMethod : observerMethods) {
                if (!observerMethod.isStatic() && !businessMethodSignatures.contains(observerMethod.getSignature())) {
                    throw ..observerMethodMustBeStaticOrBusiness(observerMethodgetEnhancedAnnotated());
                }
            }
        }
    }
        Set<MethodSignaturebusinessMethodSignatures = new HashSet<MethodSignature>();
        for (BusinessInterfaceDescriptor<?> businessInterfaceDescriptor : .getLocalBusinessInterfaces()) {
            for (Method m : businessInterfaceDescriptor.getInterface().getMethods()) {
                businessMethodSignatures.add(new MethodSignatureImpl(m));
            }
        }
        for (BusinessInterfaceDescriptor<?> businessInterfaceDescriptor : .getRemoteBusinessInterfaces()) {
            for (Method m : businessInterfaceDescriptor.getInterface().getMethods()) {
                businessMethodSignatures.add(new MethodSignatureImpl(m));
            }
        }
        return Collections.unmodifiableSet(businessMethodSignatures);
    }
        try {
            SessionBeanInjectionPoint.registerContextualInstance(getEjbDescriptor());
            return .getServices().get(EjbServices.class).resolveEjb(getEjbDescriptor().delegate());
        } finally {
            SessionBeanInjectionPoint.unregisterContextualInstance(getEjbDescriptor());
        }
    }
    @Override
    protected boolean isInterceptionCandidate() {
        return true;
    }
    @Override
    public String toString() {
        return "Session bean [" + getBeanClass() + " with qualifiers [" + Formats.formatAnnotations(getQualifiers()) + "]; local interfaces are [" + Formats.formatBusinessInterfaceDescriptors(getEjbDescriptor().getLocalBusinessInterfaces()) + "]";
    }
    // ejb's are always proxiable
    @Override
    public boolean isProxyable() {
        return true;
    }
    @Override
    public boolean isPassivationCapableBean() {
        return .isPassivationCapable();
    }
    @Override
    public boolean isPassivationCapableDependency() {
    }
    @Override
    public void initializeAfterBeanDiscovery() {
        super.initializeAfterBeanDiscovery();
        registerInterceptors();
    }
    protected void registerInterceptors() {
        if (model != null) {
        }
    }
New to GrepCode? Check out our FAQ X