KickJava   Java API By Example, From Geeks To Geeks.

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


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.context;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import java.lang.annotation.ElementType JavaDoc;
29 import java.lang.reflect.AnnotatedElement JavaDoc;
30
31 import com.sun.enterprise.deployment.WebBundleDescriptor;
32 import com.sun.enterprise.deployment.WebComponentDescriptor;
33 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler;
34 import com.sun.enterprise.deployment.types.HandlerChainContainer;
35 import com.sun.enterprise.deployment.WebServiceEndpoint;
36 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
37
38 /**
39  * This ClientContext implementation holds a top level reference
40  * to the DOL Web BundleDescriptor which will be used to populate
41  * any information processed from the annotations.
42  *
43  * @author Shing Wai Chan
44  */

45 public class WebBundleContext extends ResourceContainerContextImpl {
46
47     public WebBundleContext(WebBundleDescriptor webBundleDescriptor) {
48         super(webBundleDescriptor);
49     }
50
51     public WebBundleDescriptor getDescriptor() {
52         return (WebBundleDescriptor)descriptor;
53     }
54
55     /**
56      * This method create a context for web component(s) by using
57      * descriptor(s) associated to given webComponet impl class.
58      * Return null if corresponding descriptor is not found.
59      */

60     public AnnotatedElementHandler createContextForWeb() {
61         AnnotatedElement JavaDoc anTypeElement =
62                 this.getProcessingContext().getProcessor(
63                 ).getLastAnnotatedElement(ElementType.TYPE);
64         WebComponentDescriptor[] webComps = null;
65         if (anTypeElement != null) {
66             String JavaDoc implClassName = ((Class JavaDoc)anTypeElement).getName();
67             webComps = getDescriptor().getWebComponentByImplName(implClassName);
68         }
69
70         AnnotatedElementHandler aeHandler = null;
71         if (webComps != null && webComps.length > 1) {
72             aeHandler = new WebComponentsContext(webComps);
73         } else if (webComps != null && webComps.length == 1) {
74             aeHandler = new WebComponentContext(webComps[0]);
75         }
76
77         if (aeHandler != null) {
78             // push a WebComponent(s)Context to stack
79
this.getProcessingContext().pushHandler(aeHandler);
80         }
81         return aeHandler;
82     }
83     
84     public HandlerChainContainer[]
85             getHandlerChainContainers(boolean serviceSideHandlerChain, Class JavaDoc declaringClass) {
86         if(serviceSideHandlerChain) {
87             List JavaDoc<WebServiceEndpoint> result = new ArrayList JavaDoc<WebServiceEndpoint>();
88             for (WebServiceEndpoint endpoint : getDescriptor().getWebServices().getEndpoints()) {
89                 if (endpoint.getWebComponentImpl().getWebComponentImplementation().equals(declaringClass.getName())) {
90                     result.add(endpoint);
91                 }
92             }
93             return(result.toArray(new HandlerChainContainer[0]));
94         } else {
95             List JavaDoc<ServiceReferenceDescriptor> result = new ArrayList JavaDoc<ServiceReferenceDescriptor>();
96             result.addAll(getDescriptor().getServiceReferenceDescriptors());
97             return(result.toArray(new HandlerChainContainer[0]));
98         }
99     }
100 }
101
Popular Tags