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.util;
 
 import java.util.List;
 import java.util.Set;
 
 
 
Helper class for javax.enterprise.inject.spi.Decorator inspections.

Author(s):
Marius Bogoevici
 
 public class Decorators {
 
     private Decorators() {
     }

    
Determines the set of org.jboss.weld.annotated.runtime.InvokableAnnotatedMethods representing decorated methods of the specified decorator. A decorated method is any method declared by a decorated type which is implemented by the decorator.

Parameters:
beanManager the bean manager
decorator the specified decorator
Returns:
the set of org.jboss.weld.annotated.runtime.InvokableAnnotatedMethods representing decorated methods of the specified decorator
 
     public static Set<InvokableAnnotatedMethod<?>> getDecoratorMethods(BeanManagerImpl beanManagerWeldDecorator<?> decorator) {
         ImmutableSet.Builder<InvokableAnnotatedMethod<?>> builder = ImmutableSet.builder();
         for (Type type : decorator.getDecoratedTypes()) {
             EnhancedAnnotatedType<?> weldClass = getWeldClassOfDecoratedType(beanManagertype);
             for (EnhancedAnnotatedMethod<?, ?> method : weldClass.getDeclaredEnhancedMethods()) {
                 if (decorator.getEnhancedAnnotated().getEnhancedMethod(method.getSignature()) != null) {
                     builder.add(InvokableAnnotatedMethod.of(method.slim()));
                 }
             }
         }
         return builder.build();
     }
 
     private static EnhancedAnnotatedType<?> getWeldClassOfDecoratedType(BeanManagerImpl beanManagerType type) {
         if (type instanceof Class<?>) {
             return beanManager.createEnhancedAnnotatedType((Class<?>) type);
         }
         if (type instanceof ParameterizedType && (((ParameterizedTypetype).getRawType() instanceof Class)) {
             return beanManager.createEnhancedAnnotatedType((Class<?>) ((ParameterizedTypetype).getRawType());
         }
         throw new IllegalStateException(..unableToProcess(type));
     }
 
    public static WeldInjectionPointAttributes<?, ?> findDelegateInjectionPoint(AnnotatedType<?> typeIterable<InjectionPointinjectionPoints) {
        WeldInjectionPointAttributes<?, ?> result = null;
        for (InjectionPoint injectionPoint : injectionPoints) {
            if (injectionPoint.isDelegate()) {
                if (result != null) {
                    throw ..tooManyDelegatesForDecorator(type);
                }
                if (injectionPoint instanceof MethodInjectionPoint<?, ?> && !injectionPoint.getAnnotated().isAnnotationPresent(Inject.class)) {
                    throw ..delegateOnNonInitializerMethod(injectionPoint);
                }
                result = InjectionPoints.getWeldInjectionPoint(injectionPoint);
            }
        }
        if (result == null) {
            throw ..noDelegateForDecorator(type);
        }
        return result;
    }
    public static <T> T getOuterDelegate(Bean<T> bean, T instanceCreationalContext<T> creationalContextClass<T> proxyClassInjectionPoint originalInjectionPointBeanManagerImpl managerList<Decorator<?>> decorators) {
        TargetBeanInstance beanInstance = new TargetBeanInstance(beaninstance);
        DecorationHelper<T> decorationHelper = new DecorationHelper<T>(beanInstancebeanproxyClassmanagermanager.getServices().get(ContextualStore.class), decorators);
        DecorationHelper.push(decorationHelper);
        try {
            final T outerDelegate = decorationHelper.getNextDelegate(originalInjectionPointcreationalContext);
            if (outerDelegate == null) {
                throw new WeldException(..proxyInstantiationFailed(bean));
            }
            return outerDelegate;
        } finally {
            DecorationHelper.pop();
        }
    }

    
Check whether the delegate type implements or extends all decorated types.

Parameters:
decorator
Throws:
org.jboss.weld.exceptions.DefinitionException If the delegate type doesn't implement or extend all decorated types
    public static void checkDelegateType(Decorator<?> decorator) {
        Set<Typetypes = new HierarchyDiscovery(decorator.getDelegateType()).getTypeClosure();
        for (Type decoratedType : decorator.getDecoratedTypes()) {
            if(!types.contains(decoratedType)) {
                throw ..delegateMustSupportEveryDecoratedType(decoratedTypedecorator);
            }
        }
    }

    
Check all abstract methods are declared by the decorated types.

Parameters:
type
beanManager
delegateType
Throws:
org.jboss.weld.exceptions.DefinitionException If any of the abstract methods is not declared by the decorated types
    public static <T> void checkAbstractMethods(Set<TypedecoratedTypesEnhancedAnnotatedType<T> typeBeanManagerImpl beanManager) {
        if(decoratedTypes == null) {
            decoratedTypes = new HashSet<Type>(type.getInterfaceClosure());
            decoratedTypes.remove(Serializable.class);
        }
        Set<MethodSignaturesignatures = new HashSet<MethodSignature>();
        for (Type decoratedType : decoratedTypes) {
            for (EnhancedAnnotatedMethod<?, ?> method : ClassTransformer.instance(beanManager).getEnhancedAnnotatedType(Reflections.getRawType(decoratedType), beanManager.getId()).getEnhancedMethods()) {
                signatures.add(method.getSignature());
            }
        }
        for (EnhancedAnnotatedMethod<?, ?> method : type.getEnhancedMethods()) {
            if (Reflections.isAbstract(((AnnotatedMethod<?>) method).getJavaMember())) {
                MethodSignature methodSignature = method.getSignature();
                if (!signatures.contains(methodSignature)) {
                    throw ..abstractMethodMustMatchDecoratedType(method.getSignature(), type);
                }
            }
        }
    }

    
Indicates whether a javax.enterprise.inject.spi.Decorator is passivation capable or not.

Returns:
    public static boolean isPassivationCapable(Decorator<?> decorator) {
        if (decorator instanceof CustomDecoratorWrapper<?>) {
            // unwrap
            decorator = Reflections.<CustomDecoratorWrapper<?>>cast(decorator).delegate();
        }
        if (decorator instanceof DecoratorImpl<?>) {
            DecoratorImpl<?> weldDecorator = (DecoratorImpl<?>) decorator;
            return weldDecorator.getEnhancedAnnotated().isSerializable();
        }
        return decorator instanceof PassivationCapable;
    }
New to GrepCode? Check out our FAQ X