Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.proxy;
 
 import java.util.List;
 
 

Author(s):
Marius Bogoevici
Ales Justin
 
 public class DecorationHelper<T> {
     private static ThreadLocal<Stack<DecorationHelper<?>>> helperStackHolder = new ThreadLocal<Stack<DecorationHelper<?>>>() {
         @Override
         protected Stack<DecorationHelper<?>> initialValue() {
             return new Stack<DecorationHelper<?>>();
         }
     };
 
     private final Class<T> proxyClassForDecorator;
 
     private final TargetBeanInstance targetBeanInstance;
 
     private T originalInstance;
 
     private T previousDelegate;
 
     private int counter;
 
     private BeanManagerImpl beanManager;
     private final ContextualStore contextualStore;
     private final Bean<?> bean;
 
     List<Decorator<?>> decorators;
 
     public DecorationHelper(TargetBeanInstance originalInstanceBean<?> beanClass<T> proxyClassForDecoratorBeanManagerImpl beanManagerContextualStore contextualStoreList<Decorator<?>> decorators) {
         this. = Reflections.<T>cast(originalInstance.getInstance());
         this. = originalInstance;
         this. = beanManager;
         this. = contextualStore;
         this. = new LinkedList<Decorator<?>>(decorators);
         this. = proxyClassForDecorator;
         this. = bean;
          = 0;
     }
 
     public static void push(DecorationHelper<?> helper) {
         .get().push(helper);
     }
 
     public static DecorationHelper<?> peek() {
         return .get().peek();
     }
 
     public static void pop() {
         final Stack<DecorationHelper<?>> stack = .get();
         stack.pop();
         if (stack.isEmpty()) {
             .remove();
         }
     }
 
     public T getNextDelegate(InjectionPoint injectionPointCreationalContext<?> creationalContext) {
         if ( == .size()) {
              = ;
             return ;
         } else {
             T proxy = createProxy(injectionPointcreationalContext);
             = proxy;
            return proxy;
        }
    }
    private T createProxy(InjectionPoint injectionPointCreationalContext<?> creationalContext) {
        try {
            T proxy = AccessController.doPrivileged(NewInstanceAction.of());
            TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance();
            Decorator<Objectdecorator = Reflections.cast(.get(++));
            DecoratorProxyMethodHandler methodHandler = createMethodHandler(injectionPointcreationalContextdecorator);
            newTargetBeanInstance.setInterceptorsHandler(methodHandler);
            ProxyFactory.setBeanInstance(.getContextId(), proxynewTargetBeanInstance);
            return proxy;
        } catch (PrivilegedActionException e) {
            if (e.getCause() instanceof InstantiationException) {
                throw new WeldException(..proxyInstantiationFailed(this), e.getCause());
            } else if (e.getCause() instanceof IllegalAccessException) {
                throw new WeldException(..proxyInstantiationBeanAccessFailed(this), e.getCause());
            } else {
                throw new WeldException(e.getCause());
            }
        }
    }
    public DecoratorProxyMethodHandler createMethodHandler(InjectionPoint injectionPointCreationalContext<?> creationalContextDecorator<Objectdecorator) {
        Object decoratorInstance = .getInjectableReference(injectionPointdecoratorcreationalContext);
        assert  != null : "previousDelegate should have been set when calling beanManager.getReference(), but it wasn't!";
        SerializableContextualInstanceImpl<Decorator<Object>, ObjectserializableContextualInstance = new SerializableContextualInstanceImpl<Decorator<Object>, Object>(decoratordecoratorInstancenull);
        return new DecoratorProxyMethodHandler(serializableContextualInstance);
    }
New to GrepCode? Check out our FAQ X