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 abstract bean representation common for all beans

Parameters:
<T> the type of bean
<S> the Class<?> of the bean type
Author(s):
Pete Muir
Ales Justin
Jozef Hartinger
 
 public abstract class AbstractBean<T, S> extends RIBean<T> {
 
     protected Class<T> type;
 
     private boolean preInitialized;
     private boolean proxyRequired;
 
     private Producer<T> producer;

    
Constructor

Parameters:
beanManager The Bean manager
 
     public AbstractBean(BeanAttributes<T> attributesBeanIdentifier identifierBeanManagerImpl beanManager) {
         super(attributesidentifierbeanManager);
     }

    
Initializes specialization. This method is called before javax.enterprise.inject.spi.ProcessBeanAttributes is fired and also after the event if the javax.enterprise.inject.spi.BeanAttributes have been altered.
 
     @Override
     public void preInitialize() {
         synchronized (this) {
             if (isSpecializing() && !) {
                  = true;
                 preSpecialize();
                 specialize();
                 checkSpecialization();
                 postSpecialize();
             }
         }
     }

    
Initializes the bean and its metadata
 
     @Override
     public void internalInitialize(BeanDeployerEnvironment environment) {
         preInitialize();
         ..creatingBean(getType());
         if (getScope() != null) {
              = isNormalScoped();
         } else {
              = false;
         }
         ..qualifiersUsed(getQualifiers(), this);
         ..usingName(getName(), this);
        ..usingScope(getScope(), this);
    }
    @Override
    public void initializeAfterBeanDiscovery() {
        checkType();
    }
    protected abstract void checkType();

    
Validates specialization if this bean specializes another bean.
    public void checkSpecialization() {
        if (isSpecializing()) {
            boolean isNameDefined = getAnnotated().isAnnotationPresent(Named.class);
            String previousSpecializedBeanName = null;
            for (AbstractBean<?, ?> specializedBean : getSpecializedBeans()) {
                String name = specializedBean.getName();
                if (previousSpecializedBeanName != null && name != null && !previousSpecializedBeanName.equals(specializedBean.getName())) {
                    // there may be multiple beans specialized by this bean - make sure they all share the same name
                    throw ..beansWithDifferentBeanNamesCannotBeSpecialized(previousSpecializedBeanNamespecializedBean.getName(), this);
                }
                previousSpecializedBeanName = name;
                if (isNameDefined && name != null) {
                    throw ..nameNotAllowedOnSpecialization(getAnnotated());
                }
                // When a specializing bean extends the raw type of a generic superclass, types of the generic superclass are
                // added into types of the specializing bean because of assignability rules. However, ParameterizedTypes among
                // these types are NOT types of the specializing bean (that's the way java works)
                boolean rawInsteadOfGeneric = (this instanceof AbstractClassBean<?>
                        && specializedBean.getBeanClass().getTypeParameters().length > 0
                        && !(((AbstractClassBean<?>) this).getBeanClass().getGenericSuperclass() instanceof ParameterizedType));
                for (Type specializedType : specializedBean.getTypes()) {
                    if (rawInsteadOfGeneric && specializedType instanceof ParameterizedType) {
                        throw ..specializingBeanMissingSpecializedType(thisspecializedTypespecializedBean);
                    }
                    boolean contains = getTypes().contains(specializedType);
                    if (!contains) {
                        for (Type specializingType : getTypes()) {
                            // In case 'type' is a ParameterizedType, two bean types equivalent in the CDI sense may not be
                            // equal in the java sense. Therefore we have to use our own equality util.
                            if (TypeEqualitySpecializationUtils.areTheSame(specializingTypespecializedType)) {
                                contains = true;
                                break;
                            }
                        }
                    }
                    if (!contains) {
                        throw ..specializingBeanMissingSpecializedType(thisspecializedTypespecializedBean);
                    }
                }
            }
        }
    }
    protected void postSpecialize() {
        // override qualifiers
        Set<Annotationqualifiers = new HashSet<Annotation>();
        qualifiers.addAll(attributes().getQualifiers());
        // override name
        String name = attributes().getName();
        for (AbstractBean<?, ?> specializedBean : getSpecializedBeans()) {
            qualifiers.addAll(specializedBean.getQualifiers());
            if (specializedBean.getName() != null) {
                name = specializedBean.getName();
            }
        }
        setAttributes(new ImmutableBeanAttributes<T>(qualifiersnameattributes()));
    }
    protected void preSpecialize() {
    }
    protected void specialize() {
    }

    
Returns the annotated item the bean represents

Returns:
The annotated item
    public abstract Annotated getAnnotated();

    
Returns the weld-enhanced annotated item the bean represents. The item is only available during bootstrap. The method throws java.lang.IllegalStateException at runtime.

Returns:
The annotated item
Throws:
java.lang.IllegalStateException when invoked at runtime
    public abstract EnhancedAnnotated<T, S> getEnhancedAnnotated();
    protected Set<? extends AbstractBean<?, ?>> getSpecializedBeans() {
    }

    
Gets the type of the bean

Returns:
The type
    @Override
    public Class<T> getType() {
        return ;
    }
    @Override
    public boolean isDependent() {
        return Dependent.class.equals(getScope());
    }
    public boolean isSpecializing() {
        return getAnnotated().isAnnotationPresent(Specializes.class);
    }
    @Override
    public boolean isProxyRequired() {
        return ;
    }
    public Producer<T> getProducer() {
        return ;
    }

    
Set a Producer for this bean. This operation is *not* threadsafe, and should not be called outside bootstrap.
    public void setProducer(Producer<T> producer) {
        this. = producer;
    }
New to GrepCode? Check out our FAQ X