KickJava   Java API By Example, From Geeks To Geeks.

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


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.Role;
31
32 import com.sun.enterprise.deployment.node.XMLElement;
33 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
34 import com.sun.enterprise.deployment.node.MethodNode;
35 import com.sun.enterprise.deployment.node.DescriptorFactory;
36
37 import com.sun.enterprise.deployment.MethodPermissionDescriptor;
38 import com.sun.enterprise.deployment.MethodDescriptor;
39 import com.sun.enterprise.deployment.MethodPermission;
40 import com.sun.enterprise.deployment.EjbDescriptor;
41 import com.sun.enterprise.deployment.Descriptor;
42 import com.sun.enterprise.deployment.xml.EjbTagNames;
43
44 /**
45  * This class handles all the method-permission xml tag
46  * information
47  *
48  * @author Jerome Dochez
49  * @version
50  */

51 public class MethodPermissionNode extends DeploymentDescriptorNode {
52
53     private MethodPermissionDescriptor descriptor;
54     
55     /** Creates new MethodPermissionNode */
56     public MethodPermissionNode() {
57         super();
58        registerElementHandler(new XMLElement(EjbTagNames.METHOD),
59                                                             MethodNode.class, "addMethod");
60     }
61     
62    /**
63     * @return the descriptor instance to associate with this XMLNode
64     */

65     public Object JavaDoc getDescriptor() {
66         
67        if (descriptor==null) {
68             descriptor = (MethodPermissionDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
69         }
70         return descriptor;
71     }
72     
73     /**
74      * SAX Parser API implementation, we don't really care for now.
75      */

76     public void startElement(XMLElement element, Attributes JavaDoc attributes) {
77         
78         if (EjbTagNames.UNCHECKED.equals(element.getQName())) {
79             descriptor.addMethodPermission(MethodPermission.getUncheckedMethodPermission());
80         } else
81             super.startElement(element, attributes);
82     }
83         
84     /**
85      * receives notiification of the value for a particular tag
86      *
87      * @param element the xml element
88      * @param value it's associated value
89      */

90     public void setElementValue(XMLElement element, String JavaDoc value) {
91         if (EjbTagNames.ROLE_NAME.equals(element.getQName())) {
92             Role role = new Role(value);
93             descriptor.addMethodPermission(new MethodPermission(role));
94         } else {
95             super.setElementValue(element, value);
96         }
97     }
98
99     
100     /**
101      * write the descriptor class to a DOM tree and return it
102      *
103      * @param parent node in the DOM tree
104      * @param node name for the root element of this xml fragment
105      * @param the descriptor to write
106      * @return the DOM tree top node
107      */

108     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, MethodPermissionDescriptor descriptor,
109                 EjbDescriptor ejb) {
110                     
111         Node JavaDoc subNode = super.writeDescriptor(parent, nodeName, descriptor);
112         return writeDescriptorInNode(subNode, descriptor, ejb);
113     }
114     
115     
116     /**
117      * Write the descriptor in a DOM tree which root element is provided
118      *
119      * @param subNode the root element for the DOM fragment
120      * @param descriptor the method permisison descriptor
121      * @param ejb the ejb descriptor the above method permission belongs to
122      */

123     public Node JavaDoc writeDescriptorInNode(Node JavaDoc subNode, MethodPermissionDescriptor descriptor,
124                 EjbDescriptor ejb) {
125                     
126         writeLocalizedDescriptions(subNode, descriptor);
127         
128         MethodPermission[] mps = descriptor.getMethodPermissions();
129         if (mps.length==0)
130             return null;
131         
132         if (!mps[0].isExcluded()) {
133             if (mps[0].isUnchecked()) {
134                 appendChild(subNode, EjbTagNames.UNCHECKED);
135             } else {
136                 for (int i=0;i<mps.length;i++) {
137                     appendTextChild(subNode, EjbTagNames.ROLE_NAME, mps[i].getRole().getName());
138                 }
139             }
140         }
141                 
142         MethodDescriptor[] methods = descriptor.getMethods();
143         MethodNode mn = new MethodNode();
144         for (int i=0;i<methods.length;i++) {
145             String JavaDoc ejbName = ejb.getName();
146             mn.writeDescriptor(subNode, EjbTagNames.METHOD, methods[i], ejbName);
147         }
148         return subNode;
149     }
150 }
151
Popular Tags