Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, 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.attributes;
 
 import java.util.Set;
 
 
Creates javax.enterprise.inject.spi.BeanAttributes based on BeanAttributes provided by an extension. This class handles creating a safe copy as well as basic validation of provided javax.enterprise.inject.spi.BeanAttributes.

Author(s):
Jozef Hartinger
Marko Luksa
 
 
     private ExternalBeanAttributesFactory() {
     }

    

Parameters:
source source javax.enterprise.inject.spi.BeanAttributes.
Returns:
a safe copy of source javax.enterprise.inject.spi.BeanAttributes.
 
     public static <T> BeanAttributes<T> of(BeanAttributes<T> sourceBeanManager manager) {
         validateBeanAttributes(sourcemanager);
         BeanAttributes<T> attributes = new ImmutableBeanAttributes<T>(defensiveCopy(source.getStereotypes()), source.isAlternative(), source.getName(),
                 defensiveCopy(source.getQualifiers()), defensiveCopy(source.getTypes()), source.getScope());
         return attributes;
     }
 
     private static <T> Set<T> defensiveCopy(Set<T> set) {
         return new HashSet<T>(set);
     }

    
 
     public static void validateBeanAttributes(BeanAttributes<?> attributesBeanManager manager) {
         validateStereotypes(attributesmanager);
         validateQualifiers(attributesmanager);
         validateTypes(attributesmanager);
         validateScope(attributesmanager);
     }
 
     public static void validateStereotypes(BeanAttributes<?> attributesBeanManager manager) {
         if(attributes.getStereotypes() == null) {
             throw ..stereotypesNull(attributes);
         }
         for (Class<? extends Annotationannotation : attributes.getStereotypes()) {
             if (!manager.isStereotype(annotation)) {
                 throw ..notAStereotype(annotationattributes);
             }
         }
     }
 
     public static void validateQualifiers(BeanAttributes<?> attributesBeanManager manager) {
         Set<Annotationqualifiers = attributes.getQualifiers();
         Bindings.validateQualifiers(qualifiersmanagerattributes"BeanAttributes.getQualifiers");
     }
 
     public static void validateTypes(BeanAttributes<?> attributesBeanManager manager) {
         if(attributes.getTypes() == null) {
             throw ..typesNull(attributes);
         }
         if (attributes.getTypes().isEmpty()) {
             throw ..typesEmpty(attributes);
         }
         for (Type type : attributes.getTypes()) {
             validateBeanType(typeattributes);
         }
    }
    private static void validateBeanType(Type typeBeanAttributes<?> attributes) {
        checkBeanTypeNotATypeVariable(typetypeattributes);
        checkBeanTypeForWildcardsAndTypeVariables(typetypeattributes);
    }
    private static void checkBeanTypeNotATypeVariable(Type beanTypeType typeBeanAttributes<?> attributes) {
        if (type instanceof TypeVariable<?>) {
            throw ..typeVariableIsNotAValidBeanType(beanTypeattributes);
        } else if (type instanceof GenericArrayType) {
            GenericArrayType arrayType = (GenericArrayTypetype;
            checkBeanTypeNotATypeVariable(beanTypearrayType.getGenericComponentType(), attributes);
        }
    }
    private static void checkBeanTypeForWildcardsAndTypeVariables(Type beanTypeType typeBeanAttributes<?> attributes) {
        if (type instanceof TypeVariable<?>) {
            if (!attributes.getScope().equals(Dependent.class)) {
                throw ..beanWithParameterizedTypeContainingTypeVariablesMustBeDependentScoped(beanTypeattributes);
            }
        } else if (type instanceof WildcardType) {
            throw ..parameterizedTypeContainingWildcardParameterIsNotAValidBeanType(beanTypeattributes);
        } else if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedTypetype;
            for (Type typeArgument : parameterizedType.getActualTypeArguments()) {
                checkBeanTypeForWildcardsAndTypeVariables(beanTypetypeArgumentattributes);
            }
        } else if (type instanceof GenericArrayType) {
            GenericArrayType arrayType = (GenericArrayTypetype;
            checkBeanTypeForWildcardsAndTypeVariables(beanTypearrayType.getGenericComponentType(), attributes);
        }
    }
    public static void validateScope(BeanAttributes<?> attributesBeanManager manager) {
        if(attributes.getScope() == null) {
            throw ..scopeNull(attributes);
        }
        if (!manager.isScope(attributes.getScope())) {
            throw ..notAScope(attributes.getScope(), attributes);
        }
    }
New to GrepCode? Check out our FAQ X