KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > context > EjbContext


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
24 /*
25  * EjbContext.java
26  *
27  * Created on January 16, 2005, 5:53 PM
28  */

29
30 package com.sun.enterprise.deployment.annotation.context;
31
32 import java.lang.annotation.ElementType JavaDoc;
33 import java.lang.reflect.AnnotatedElement JavaDoc;
34 import java.lang.reflect.Method JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.List JavaDoc;
37
38 import com.sun.enterprise.deployment.EjbDescriptor;
39 import com.sun.enterprise.deployment.MethodDescriptor;
40 import com.sun.enterprise.deployment.WebServiceEndpoint;
41 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
42 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler;
43 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException;
44 import com.sun.enterprise.deployment.annotation.AnnotationInfo;
45 import com.sun.enterprise.deployment.annotation.ProcessingContext;
46 import com.sun.enterprise.deployment.annotation.handlers.PostProcessor;
47 import com.sun.enterprise.deployment.annotation.impl.ComponentDefinition;
48 import com.sun.enterprise.deployment.types.ServiceReferenceContainer;
49 import com.sun.enterprise.deployment.types.HandlerChainContainer;
50 import com.sun.enterprise.util.TypeUtil;
51
52 /**
53  *
54  * @author dochez
55  */

56 public class EjbContext extends ResourceContainerContextImpl {
57     private WebServiceEndpoint endpoint;
58     private Method JavaDoc[] methods;
59     private boolean inherited;
60     private ArrayList JavaDoc<PostProcessInfo> postProcessInfos =
61             new ArrayList JavaDoc<PostProcessInfo>();
62
63     public EjbContext(EjbDescriptor currentEjb, Class JavaDoc ejbClass) {
64         super(currentEjb);
65         componentClassName = currentEjb.getEjbClassName();
66         ComponentDefinition cdef = new ComponentDefinition(ejbClass);
67         methods = cdef.getMethods();
68         Class JavaDoc superClass = ejbClass.getSuperclass();
69         inherited = (superClass != null && !Object JavaDoc.class.equals(superClass));
70     }
71
72     public EjbDescriptor getDescriptor() {
73         return (EjbDescriptor)descriptor;
74     }
75
76     public void setDescriptor(EjbDescriptor currentEjb) {
77         descriptor = currentEjb;
78     }
79
80     public void setEndpoint(WebServiceEndpoint endpoint) {
81         this.endpoint = endpoint;
82     }
83     
84     public WebServiceEndpoint getEndpoint() {
85         return endpoint;
86     }
87
88     public void endElement(ElementType JavaDoc type, AnnotatedElement JavaDoc element)
89             throws AnnotationProcessorException {
90         
91         if (ElementType.TYPE.equals(type)) {
92             for (PostProcessInfo ppInfo : postProcessInfos) {
93                  ppInfo.postProcessor.postProcessAnnotation(
94                          ppInfo.ainfo, this);
95             }
96
97             // done with processing this class, let's pop this context
98
getProcessingContext().popHandler();
99         }
100     }
101
102     public Class JavaDoc getDeclaringClass(MethodDescriptor md) {
103         Method JavaDoc method = md.getMethod(getDescriptor());
104         Class JavaDoc declaringClass = null;
105         for (Method JavaDoc m : methods) {
106             if (TypeUtil.sameMethodSignature(m, method)) {
107                 declaringClass = m.getDeclaringClass();
108             }
109         }
110         return declaringClass;
111     }
112
113     public boolean isInherited() {
114         return inherited;
115     }
116
117     public void addPostProcessInfo(AnnotationInfo ainfo, PostProcessor postProcessor) {
118         PostProcessInfo ppInfo = new PostProcessInfo();
119         ppInfo.ainfo = ainfo;
120         ppInfo.postProcessor = postProcessor;
121         postProcessInfos.add(ppInfo);
122     }
123
124     private class PostProcessInfo {
125         public AnnotationInfo ainfo;
126         public PostProcessor postProcessor;
127     }
128     
129     public ServiceReferenceContainer[] getServiceRefContainers(String JavaDoc implName) {
130         return getDescriptor().getEjbBundleDescriptor().getEjbByClassName(implName);
131     }
132
133     public HandlerChainContainer[]
134             getHandlerChainContainers(boolean serviceSideHandlerChain, Class JavaDoc declaringClass) {
135         if(serviceSideHandlerChain) {
136             EjbDescriptor[] ejbs = getDescriptor().getEjbBundleDescriptor().getEjbByClassName(declaringClass.getName());
137             List JavaDoc<WebServiceEndpoint> result = new ArrayList JavaDoc<WebServiceEndpoint>();
138             for (EjbDescriptor ejb : ejbs) {
139                 result.addAll(getDescriptor().getEjbBundleDescriptor().getWebServices().getEndpointsImplementedBy(ejb));
140             }
141             return(result.toArray(new HandlerChainContainer[0]));
142         } else {
143             List JavaDoc<ServiceReferenceDescriptor> result = new ArrayList JavaDoc<ServiceReferenceDescriptor>();
144             result.addAll(getDescriptor().getEjbBundleDescriptor().getServiceReferenceDescriptors());
145             return(result.toArray(new HandlerChainContainer[0]));
146         }
147     }
148 }
149
Popular Tags