KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ejb > SecurityIdentityNode


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 package com.sun.enterprise.deployment.node.ejb;
25
26 import java.util.Map JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.xml.sax.Attributes JavaDoc;
29
30 import com.sun.enterprise.deployment.node.XMLElement;
31 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
32 import com.sun.enterprise.deployment.node.DescriptorFactory;
33 import com.sun.enterprise.deployment.node.RunAsNode;
34
35 import com.sun.enterprise.deployment.Descriptor;
36 import com.sun.enterprise.deployment.EjbDescriptor;
37 import com.sun.enterprise.deployment.xml.EjbTagNames;
38
39 /**
40  * This node handles all information relative to security-indentity tag
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public class SecurityIdentityNode extends DeploymentDescriptorNode {
46     
47     /** Creates new SecurityIdentityNode */
48     public SecurityIdentityNode() {
49         super();
50         registerElementHandler(new XMLElement(EjbTagNames.RUNAS_SPECIFIED_IDENTITY), RunAsNode.class);
51     }
52
53     /**
54      * @return the Descriptor subclass that was populated by reading
55      * the source XML file
56      */

57     public Object JavaDoc getDescriptor() {
58         return null;
59     }
60     
61     /**
62      * all sub-implementation of this class can use a dispatch table to map xml element to
63      * method name on the descriptor class for setting the element value.
64      *
65      * @return the map with the element name as a key, the setter method as a value
66      */

67     protected Map JavaDoc getDispatchTable() {
68         return null;
69     }
70
71     public void startElement(XMLElement element, Attributes JavaDoc attributes) {
72         if( EjbTagNames.USE_CALLER_IDENTITY.equals(element.getQName()) ) {
73             ((EjbDescriptor) getParentNode().getDescriptor()).
74                 setUsesCallerIdentity(true);
75         } else {
76             super.startElement(element, attributes);
77         }
78         return;
79     }
80     
81     /**
82      * receives notiification of the value for a particular tag
83      *
84      * @param element the xml element
85      * @param value it's associated value
86      */

87     public void setElementValue(XMLElement element, String JavaDoc value) {
88         if (EjbTagNames.DESCRIPTION.equals(element.getQName())) {
89             ((EjbDescriptor) getParentNode().getDescriptor()).setSecurityIdentityDescription(value);
90         } else {
91             super.setElementValue(element, value);
92         }
93     }
94     
95     /**
96      * write the descriptor class to a DOM tree and return it
97      *
98      * @param parent node in the DOM tree
99      * @param node name for the root element for this DOM tree fragment
100      * @param the descriptor to write
101      * @return the DOM tree top node
102      */

103     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbDescriptor descriptor) {
104         Node JavaDoc subNode = appendChild(parent, nodeName);
105         appendTextChild(subNode, EjbTagNames.DESCRIPTION, descriptor.getSecurityIdentityDescription());
106         if (descriptor.getUsesCallerIdentity()) {
107             Node JavaDoc useCaller = subNode.getOwnerDocument().createElement(EjbTagNames.USE_CALLER_IDENTITY);
108             subNode.appendChild(useCaller);
109         } else {
110             RunAsNode runAs = new RunAsNode();
111             runAs.writeDescriptor(subNode, EjbTagNames.RUNAS_SPECIFIED_IDENTITY, descriptor.getRunAsIdentity());
112         }
113     return subNode;
114     }
115 }
116
Popular Tags