1 /*2 * The contents of this file are subject to the terms 3 * of the Common Development and Distribution License 4 * (the License). You may not use this file except in5 * compliance with the License.6 * 7 * You can obtain a copy of the license at 8 * https://glassfish.dev.java.net/public/CDDLv1.0.html or9 * glassfish/bootstrap/legal/CDDLv1.0.txt.10 * See the License for the specific language governing 11 * permissions and limitations under the License.12 * 13 * When distributing Covered Code, include this CDDL 14 * Header Notice in each file and include the License file 15 * at glassfish/bootstrap/legal/CDDLv1.0.txt. 16 * If applicable, add the following below the CDDL Header, 17 * with the fields enclosed by brackets [] replaced by18 * you own identifying information: 19 * "Portions Copyrighted [year] [name of copyright owner]"20 * 21 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.22 */23 package com.sun.enterprise.deployment.annotation.handlers;24 25 import java.lang.annotation.Annotation ;26 import java.lang.annotation.ElementType ;27 import java.lang.reflect.AnnotatedElement ;28 import java.lang.reflect.Method ;29 30 import javax.annotation.PostConstruct;31 32 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;33 import com.sun.enterprise.deployment.annotation.AnnotationInfo;34 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException;35 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult;36 import com.sun.enterprise.deployment.annotation.context.ResourceContainerContext;37 38 /**39 * This handler is responsible for handling javax.annotation.PostConstruct 40 *41 */42 public class PostConstructHandler extends AbstractResourceHandler {43 44 public PostConstructHandler() {45 }46 47 /**48 * @return the annoation type this annotation handler is handling49 */50 public Class <? extends Annotation > getAnnotationType() {51 return PostConstruct.class;52 } 53 54 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo,55 ResourceContainerContext[] rcContexts)56 throws AnnotationProcessorException {57 58 PostConstruct postConstructAn =59 (PostConstruct)ainfo.getAnnotation();60 Method annMethod = (Method )ainfo.getAnnotatedElement();61 String pcMethodName = annMethod.getName();62 String pcClassName = annMethod.getDeclaringClass().getName();63 64 for (ResourceContainerContext rcContext : rcContexts) {65 LifecycleCallbackDescriptor postConstructDesc =66 new LifecycleCallbackDescriptor();67 postConstructDesc.setLifecycleCallbackClass(pcClassName);68 postConstructDesc.setLifecycleCallbackMethod(pcMethodName);69 // override by xml is handled in addPostConstructDescriptor70 rcContext.addPostConstructDescriptor(postConstructDesc);71 }72 73 return getDefaultProcessedResult();74 }75 }76