KickJava   Java API By Example, From Geeks To Geeks.

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


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  * EjbBundleContext.java
26  *
27  * Created on January 12, 2005, 10:20 AM
28  */

29
30 package com.sun.enterprise.deployment.annotation.context;
31
32 import java.util.List JavaDoc;
33 import java.util.ArrayList JavaDoc;
34
35 import java.lang.annotation.ElementType JavaDoc;
36
37 import com.sun.enterprise.deployment.EjbBundleDescriptor;
38 import com.sun.enterprise.deployment.EjbDescriptor;
39 import com.sun.enterprise.deployment.EjbInterceptor;
40 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler;
41 import com.sun.enterprise.deployment.types.ServiceReferenceContainer;
42 import com.sun.enterprise.deployment.types.HandlerChainContainer;
43 import com.sun.enterprise.deployment.WebServiceEndpoint;
44 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
45
46 /**
47  * This ClientContext implementation holds a top level reference
48  * to the DOL EJB BundleDescriptor which will be used to populate
49  * any information processed from the annotations.
50  *
51  * @author Jerome Dochez
52  */

53 public class EjbBundleContext extends ResourceContainerContextImpl {
54     
55     /** Creates a new instance of EjbBundleContext */
56     public EjbBundleContext(EjbBundleDescriptor descriptor) {
57         super(descriptor);
58     }
59     
60     public EjbBundleDescriptor getDescriptor() {
61         return (EjbBundleDescriptor)descriptor;
62     }
63
64     /**
65      * This methods create a context for Ejb(s) by using descriptor(s)
66      * associated to given ejbClassName.
67      * Return null if corresponding descriptor is not found.
68      */

69     public AnnotatedElementHandler createContextForEjb() {
70         Class JavaDoc ejbClass = (Class JavaDoc)this.getProcessingContext().getProcessor(
71                 ).getLastAnnotatedElement(ElementType.TYPE);
72         EjbDescriptor[] ejbDescs = null;
73         String JavaDoc ejbClassName = null;
74         if (ejbClass != null) {
75             ejbClassName = ejbClass.getName();
76             ejbDescs = this.getDescriptor().getEjbByClassName(ejbClassName);
77         }
78
79         AnnotatedElementHandler aeHandler = null;
80         if (ejbDescs != null && ejbDescs.length > 1) {
81             aeHandler = new EjbsContext(ejbDescs, ejbClass);
82         } else if (ejbDescs != null && ejbDescs.length == 1) {
83             aeHandler = new EjbContext(ejbDescs[0], ejbClass);
84         }
85
86         if (aeHandler != null) {
87             // push a EjbContext to stack
88
this.getProcessingContext().pushHandler(aeHandler);
89         }
90         return aeHandler;
91     }
92             
93     public HandlerChainContainer[]
94             getHandlerChainContainers(boolean serviceSideHandlerChain, Class JavaDoc declaringClass) {
95         if(serviceSideHandlerChain) {
96             EjbDescriptor[] ejbs = getDescriptor().getEjbByClassName(declaringClass.getName());
97             List JavaDoc<WebServiceEndpoint> result = new ArrayList JavaDoc<WebServiceEndpoint>();
98             for (EjbDescriptor ejb : ejbs) {
99                 result.addAll(getDescriptor().getWebServices().getEndpointsImplementedBy(ejb));
100             }
101             return(result.toArray(new HandlerChainContainer[0]));
102         } else {
103             List JavaDoc<ServiceReferenceDescriptor> result = new ArrayList JavaDoc<ServiceReferenceDescriptor>();
104             result.addAll(getDescriptor().getServiceReferenceDescriptors());
105             return(result.toArray(new HandlerChainContainer[0]));
106         }
107     }
108     
109     public ServiceReferenceContainer[] getServiceRefContainers() {
110         ServiceReferenceContainer[] container =
111                 new ServiceReferenceContainer[getDescriptor().getEjbs().size()];
112         ServiceReferenceContainer[] ret =
113                 (ServiceReferenceContainer[])getDescriptor().getEjbs().toArray(container);
114         return ret;
115     }
116     
117     /**
118      * This methods create a context for EjbInterceptor associated to
119      * given className.
120      * Return null if corresponding descriptor is not found.
121      */

122     public AnnotatedElementHandler createContextForEjbInterceptor() {
123         Class JavaDoc interceptorClass =
124                 (Class JavaDoc)this.getProcessingContext().getProcessor(
125                 ).getLastAnnotatedElement(ElementType.TYPE);
126         EjbInterceptor ejbInterceptor =
127                 this.getDescriptor().getInterceptorByClassName(
128                 interceptorClass.getName());
129         
130         AnnotatedElementHandler aeHandler = null;
131         if (ejbInterceptor != null) {
132             aeHandler = new EjbInterceptorContext(ejbInterceptor);
133             // push a EjbInterceptorContext to stack
134
this.getProcessingContext().pushHandler(aeHandler);
135         }
136         return aeHandler;
137     }
138 }
139
Popular Tags