Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2013, 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.List;
 
 
 
 
 import  edu.umd.cs.findbugs.annotations.SuppressWarnings;

If the component is not intercepted this implementation takes care of invoking its lifecycle callback methods. If the component is interception, PostConstruct / PreDestroy invocation is delegated to the intercepting proxy.

Parameters:
<T>
Author(s):
Jozef Hartinger
 
 public class DefaultLifecycleCallbackInvoker<T> implements LifecycleCallbackInvoker<T> {
 
     private static final Function<AnnotatedMethod<?>, MethodACCESSIBLE_METHOD_FUNCTION = new Function<AnnotatedMethod<?>, Method>() {
         @Override
         @SuppressWarnings("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE")
         public Method apply(AnnotatedMethod<?> method) {
             Preconditions.checkArgumentNotNull(method"method");
             return AccessController.doPrivileged(new GetAccessibleCopyOfMember<Method>(method.getJavaMember()));
         }
     };
 
     public static <T> DefaultLifecycleCallbackInvoker<T> of(EnhancedAnnotatedType<T> type) {
         return new DefaultLifecycleCallbackInvoker<T>(type);
     }
 
     private final List<MethodaccessiblePostConstructMethods;
     private final List<MethodaccessiblePreDestroyMethods;
 
         this. = initMethodList(BeanMethods.getPostConstructMethods(type));
         this. = initMethodList(BeanMethods.getPreDestroyMethods(type));
     }
 
     private List<MethodinitMethodList(List<? extends AnnotatedMethod<?>> methods) {
          return ImmutableList.copyOf(Lists.transform(methods));
     }
 
     @Override
     public void postConstruct(T instanceInstantiator<T> instantiator) {
         // this may be null for NonProducibleInjectionTarget
         if (instantiator != null && instantiator.hasInterceptorSupport()) {
             InterceptionUtils.executePostConstruct(instance);
         } else {
             invokeMethods(instance);
         }
     }
 
     @Override
     public void preDestroy(T instanceInstantiator<T> instantiator) {
         // this may be null for NonProducibleInjectionTarget
         if (instantiator != null && instantiator.hasInterceptorSupport()) {
             InterceptionUtils.executePredestroy(instance);
         } else {
             invokeMethods(instance);
         }
     }
 
     private void invokeMethods(List<Methodmethods, T instance) {
         for (Method method : methods) {
             try {
                 method.invoke(instance);
             } catch (Exception e) {
                throw ..invocationError(methodinstancee);
            }
        }
    }
    @Override
    public boolean hasPreDestroyMethods() {
        return !.isEmpty();
    }
    @Override
    public boolean hasPostConstructMethods() {
        return !.isEmpty();
    }
New to GrepCode? Check out our FAQ X