KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > ServletNode


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  * ServletNode.java
26  *
27  * Created on March 7, 2002, 2:30 PM
28  */

29
30 package com.sun.enterprise.deployment.node.runtime;
31
32 import org.w3c.dom.Node JavaDoc;
33
34 import com.sun.enterprise.deployment.WebBundleDescriptor;
35 import com.sun.enterprise.deployment.WebComponentDescriptor;
36 import com.sun.enterprise.deployment.WebServicesDescriptor;
37 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
38 import com.sun.enterprise.deployment.node.XMLElement;
39 import com.sun.enterprise.deployment.node.runtime.web.WebBundleRuntimeNode;
40 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
41 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
42
43 /**
44  * This node is handling all runtime deployment descriptors
45  * relative to servlets
46  *
47  * @author Jerome Dochez
48  * @version
49  */

50 public class ServletNode extends DeploymentDescriptorNode {
51
52     private WebComponentDescriptor descriptor;
53
54     public ServletNode() {
55         registerElementHandler(new XMLElement
56             (WebServicesTagNames.WEB_SERVICE_ENDPOINT),
57                                WebServiceEndpointRuntimeNode.class);
58     }
59
60     public Object JavaDoc getDescriptor() {
61         return descriptor;
62     }
63     
64     /**
65      * receives notiification of the value for a particular tag
66      *
67      * @param element the xml element
68      * @param value it's associated value
69      */

70     public void setElementValue(XMLElement element, String JavaDoc value) {
71         if (RuntimeTagNames.SERVLET_NAME.equals(element.getQName())) {
72             Object JavaDoc parentDesc = ((WebBundleRuntimeNode) getParentNode()).getWebBundleDescriptor();
73             if (parentDesc instanceof WebBundleDescriptor) {
74                 descriptor = ((WebBundleDescriptor) parentDesc).getWebComponentByCanonicalName(value);
75             }
76         } else if (RuntimeTagNames.PRINCIPAL_NAME.equals(element.getQName())) {
77             if (descriptor!=null && descriptor.getRunAsIdentity()!=null) {
78                 descriptor.getRunAsIdentity().setPrincipal(value);
79             }
80         } else super.setElementValue(element, value);
81     }
82     
83
84     /**
85      * write the descriptor class to a DOM tree and return it
86      *
87      * @param parent node for the DOM tree
88      * @param node name
89      * @param the descriptor to write
90      * @return the DOM tree top node
91      */

92     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, WebComponentDescriptor descriptor) {
93         WebServicesDescriptor webServices =
94             descriptor.getWebBundleDescriptor().getWebServices();
95
96         // only write servlet runtime elements if there is a runas identity
97
// or the servlet is exposed as a web service
98
if ( (descriptor.getRunAsIdentity() != null) ||
99              webServices.hasEndpointsImplementedBy(descriptor) ) {
100             Node JavaDoc servletNode = appendChild(parent, nodeName);
101             appendTextChild(servletNode, RuntimeTagNames.SERVLET_NAME, descriptor.getCanonicalName());
102
103             if( descriptor.getRunAsIdentity() != null ) {
104                 appendTextChild(servletNode, RuntimeTagNames.PRINCIPAL_NAME,
105                                 descriptor.getRunAsIdentity().getPrincipal());
106             }
107
108             WebServiceEndpointRuntimeNode wsRuntime =
109                 new WebServiceEndpointRuntimeNode();
110             wsRuntime.writeWebServiceEndpointInfo(servletNode, descriptor);
111
112             return servletNode;
113         }
114         return null;
115     }
116 }
117
Popular Tags