KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler;
29 import com.sun.enterprise.deployment.annotation.AnnotationInfo;
30 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException;
31 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult;
32 import com.sun.enterprise.deployment.annotation.context.EjbBundleContext;
33 import com.sun.enterprise.deployment.annotation.context.EjbContext;
34 import com.sun.enterprise.deployment.annotation.context.EjbsContext;
35 import com.sun.enterprise.deployment.annotation.context.ResourceContainerContext;
36 import com.sun.enterprise.deployment.annotation.context.WebBundleContext;
37 import com.sun.enterprise.deployment.annotation.context.WebComponentContext;
38 import com.sun.enterprise.deployment.annotation.context.WebComponentsContext;
39
40 /**
41  * This is an abstract class encapsulate generic behaviour of resource
42  * annotation.
43  * Concrete subclass handlers need to implement the following:
44  * public Class<? extends Annotation> getAnnotationType();
45  * protected HandlerProcessingResult processAnnotation(
46  * AnnotationInfo ainfo,
47  * ResourceContainerContext[] rcContexts)
48  * throws AnnotationProcessorException;
49  * It may also need to override the following if other annotations
50  * need to be processed prior to given annotation:
51  * public Class<? extends Annotation>[] getTypeDependencies();
52  *
53  * @author Shing Wai Chan
54  */

55 abstract class AbstractResourceHandler extends AbstractHandler {
56     /**
57      * Process Annotation with given ResourceContainerContexts.
58      * @param ainfo
59      * @param rcContexts
60      */

61     protected abstract HandlerProcessingResult processAnnotation(
62             AnnotationInfo ainfo,
63             ResourceContainerContext[] rcContexts)
64             throws AnnotationProcessorException;
65
66     /**
67      * Process a particular annotation which type is the same as the
68      * one returned by @see getAnnotationType(). All information
69      * pertinent to the annotation and its context is encapsulated
70      * in the passed AnnotationInfo instance.
71      *
72      * @param ainfo the annotation information
73      */

74     public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo)
75             throws AnnotationProcessorException {
76
77         AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
78         if (aeHandler instanceof EjbBundleContext) {
79             EjbBundleContext ejbBundleContext = (EjbBundleContext)aeHandler;
80             aeHandler = ejbBundleContext.createContextForEjb();
81             if (aeHandler == null) {
82                 aeHandler = ejbBundleContext.createContextForEjbInterceptor();
83             }
84         }
85         // WebBundleContext is a ResourceContainerContext.
86

87         if (aeHandler == null) {
88             // not an ejb, interceptor in ejbBundle
89
return getInvalidAnnotatedElementHandlerResult(
90                 ainfo.getProcessingContext().getHandler(), ainfo);
91         }
92         ResourceContainerContext[] rcContexts = null;
93         if (aeHandler instanceof EjbsContext) {
94             EjbsContext ejbsContext = (EjbsContext)aeHandler;
95             rcContexts = (ResourceContainerContext[])ejbsContext.getEjbContexts();
96         } else if (aeHandler instanceof WebComponentsContext) {
97             WebComponentsContext webCompsContext = (WebComponentsContext)aeHandler;
98             rcContexts = (ResourceContainerContext[])webCompsContext.getWebComponentContexts();
99         } else if (aeHandler instanceof ResourceContainerContext) {
100             rcContexts = new ResourceContainerContext[] {
101                     (ResourceContainerContext)aeHandler };
102         } else {
103             return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
104         }
105
106         return processAnnotation(ainfo, rcContexts);
107     }
108
109     public Class JavaDoc<? extends Annotation JavaDoc>[] getTypeDependencies() {
110         return getEjbAnnotationTypes();
111     }
112 }
113
Popular Tags