KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > handlers > PostConstructHandler


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 in
5  * 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 or
9  * 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 by
18  * 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 JavaDoc;
26 import java.lang.annotation.ElementType JavaDoc;
27 import java.lang.reflect.AnnotatedElement JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
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 handling
49      */

50     public Class JavaDoc<? extends Annotation JavaDoc> 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 JavaDoc annMethod = (Method JavaDoc)ainfo.getAnnotatedElement();
61         String JavaDoc pcMethodName = annMethod.getName();
62         String JavaDoc 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 addPostConstructDescriptor
70
rcContext.addPostConstructDescriptor(postConstructDesc);
71         }
72
73         return getDefaultProcessedResult();
74     }
75 }
76
Popular Tags