Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2012, 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.injection.producer;
 
 import java.util.Set;
 
 
javax.enterprise.inject.spi.InjectionTarget implementation used for decorators.

Parameters:
<T>
Author(s):
Jozef Hartinger
 
 public class DecoratorInjectionTarget<T> extends BeanInjectionTarget<T> {
 
     private final WeldInjectionPointAttributes<?, ?> delegateInjectionPoint;
     private final Field accessibleField;
 
     public DecoratorInjectionTarget(EnhancedAnnotatedType<T> typeBean<T> beanBeanManagerImpl beanManager) {
         super(typebeanbeanManager);
         this. = Decorators.findDelegateInjectionPoint(typegetInjectionPoints());
         if ( instanceof FieldInjectionPoint<?, ?>) {
             FieldInjectionPoint<?, ?> fip = (FieldInjectionPoint<?, ?>) ;
             this. = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Field>(fip.getAnnotated().getJavaMember()));
         } else {
             this. = null;
         }
         checkAbstractMethods(type);
     }
 
     @Override
     protected Instantiator<T> initInstantiator(EnhancedAnnotatedType<T> typeBean<T> beanBeanManagerImpl beanManagerSet<InjectionPointinjectionPoints) {
         if (type.isAbstract()) {
             ConstructorInjectionPoint<T> originalConstructor = InjectionPointFactory.instance().createConstructorInjectionPoint(beantypebeanManager);
             injectionPoints.addAll(originalConstructor.getParameterInjectionPoints());
             final WeldInjectionPointAttributes<?, ?> delegateInjectionPoint = Decorators.findDelegateInjectionPoint(typeinjectionPoints);
             return new SubclassedComponentInstantiator<T>(typebeanoriginalConstructorbeanManager) {
                 @Override
                 protected Class<T> createEnhancedSubclass(EnhancedAnnotatedType<T> typeBean<?> beanBeanManagerImpl manager) {
                     return new DecoratorProxyFactory<T>(manager.getContextId(), type.getJavaClass(), delegateInjectionPointbean).getProxyClass();
                 }
             };
         } else {
             DefaultInstantiator<T> instantiator = new DefaultInstantiator<T>(typebeanbeanManager);
             injectionPoints.addAll(instantiator.getConstructorInjectionPoint().getParameterInjectionPoints());
             return instantiator;
         }
     }
 
     @Override
     protected void checkDelegateInjectionPoints() {
         // noop, delegate injection points are checked in Decorators#findDelegateInjectionPoint() called within the constructor
     }
 
     @Override
     public void inject(T instanceCreationalContext<T> ctx) {
         super.inject(instancectx);
 
         if ( != null && instance instanceof DecoratorProxy) {
 
             // this code is only applicable if the delegate is injected into a field
            // as the proxy can't intercept the delegate when setting the field
            // we need to now read the delegate from the field
            // this is only needed for fields, as constructor and method injection are handed
            // at injection time
            Object delegate;
            try {
                delegate = .get(instance);
            } catch (IllegalAccessException e) {
            }
            final ProxyMethodHandler handler = new ProxyMethodHandler(.getContextId(), new TargetBeanInstance(delegate), getBean());
            ((ProxyObjectinstance).setHandler(handler);
        }
    }
    @Override
    public void initializeAfterBeanDiscovery(EnhancedAnnotatedType<T> annotatedType) {
        // noop
    }
    @SuppressWarnings("unchecked")
    private void checkAbstractMethods(EnhancedAnnotatedType<T> type) {
        if(!type.isAbstract()) {
            return;
        }
        Set<TypedecoratedTypes = null;
        Bean<?> bean = getBean();
        if(bean != null && (bean instanceof DecoratorImpl)) {
            decoratedTypes = ((DecoratorImpl<T>)bean).getDecoratedTypes();
        }
        Decorators.checkAbstractMethods(decoratedTypes,  type);
    }
New to GrepCode? Check out our FAQ X