KickJava   Java API By Example, From Geeks To Geeks.

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


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.runtime;
25
26 import java.security.Principal JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31 import org.w3c.dom.Document JavaDoc;
32
33 import com.sun.enterprise.deployment.Application;
34 import com.sun.enterprise.deployment.Descriptor;
35 import com.sun.enterprise.deployment.EjbBundleDescriptor;
36 import com.sun.enterprise.deployment.EjbDescriptor;
37 import com.sun.enterprise.deployment.Group;
38 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper;
39 import com.sun.enterprise.deployment.node.runtime.common.SecurityRoleMappingNode;
40 import com.sun.enterprise.deployment.node.XMLElement;
41 import com.sun.enterprise.deployment.RelationshipDescriptor;
42 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
43 import com.sun.enterprise.deployment.Role;
44 import com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor;
45 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping;
46 import com.sun.enterprise.deployment.util.DOLUtils;
47 import com.sun.enterprise.deployment.xml.DTDRegistry;
48 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
49 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
50
51 /**
52  * This node handles runtime deployment descriptors for ejb bundle
53  *
54  * @author Jerome Dochez
55  * @version
56  */

57 public class EjbBundleRuntimeNode extends RuntimeBundleNode {
58     
59     EjbBundleDescriptor descriptor=null;
60     
61     /** Creates new EjbBundleRuntimeNode */
62     public EjbBundleRuntimeNode(EjbBundleDescriptor descriptor) {
63         super(descriptor);
64         this.descriptor = descriptor;
65         registerElementHandler(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING),
66                                SecurityRoleMappingNode.class);
67         registerElementHandler(new XMLElement(RuntimeTagNames.EJBS),
68                                EntrepriseBeansRuntimeNode.class);
69     }
70     
71     /** Creates new EjbBundleRuntimeNode */
72     public EjbBundleRuntimeNode() {
73         super(null);
74     }
75     
76     /**
77      * @return the DOCTYPE that should be written to the XML file
78      */

79     public String JavaDoc getDocType() {
80     return DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID;
81     }
82     
83     /**
84      * @return the SystemID of the XML file
85      */

86     public String JavaDoc getSystemID() {
87     return DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID;
88     }
89
90     /**
91      * @return NULL for all runtime nodes.
92      */

93     public List JavaDoc<String JavaDoc> getSystemIDs() {
94         return null;
95     }
96     
97     /**
98      * @return the XML tag associated with this XMLNode
99      */

100     protected XMLElement getXMLRootTag() {
101         return new XMLElement(RuntimeTagNames.S1AS_EJB_RUNTIME_TAG);
102     }
103     
104    /**
105     * register this node as a root node capable of loading entire DD files
106     *
107     * @param publicIDToDTD is a mapping between xml Public-ID to DTD
108     * @return the doctype tag name
109     */

110    public static String JavaDoc registerBundle(Map JavaDoc publicIDToDTD) {
111        publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID);
112        publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_201_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_201_DTD_SYSTEM_ID);
113        publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID);
114        publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_211_DTD_SYSTEM_ID);
115        publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID);
116        if (!restrictDTDDeclarations()) {
117            publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_210beta_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210beta_DTD_SYSTEM_ID);
118        }
119        return RuntimeTagNames.S1AS_EJB_RUNTIME_TAG;
120    }
121     
122    /**
123     * @return the descriptor instance to associate with this XMLNode
124     */

125     public Object JavaDoc getDescriptor() {
126         return descriptor;
127     }
128
129     /**
130      * Adds a new DOL descriptor instance to the descriptor instance associated with
131      * this XMLNode
132      *
133      * @param descriptor the new descriptor
134      */

135     public void addDescriptor(Object JavaDoc newDescriptor) {
136         if (newDescriptor instanceof SecurityRoleMapping) {
137             SecurityRoleMapping roleMap = (SecurityRoleMapping)newDescriptor;
138             descriptor.addSecurityRoleMapping(roleMap);
139             Application app = descriptor.getApplication();
140             if (app!=null && app.isVirtual()) {
141                 Role role = new Role(roleMap.getRoleName());
142                 SecurityRoleMapper rm = app.getRoleMapper();
143                 if (rm != null) {
144                     List JavaDoc<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames();
145                     for (int i = 0; i < principals.size(); i++) {
146                         rm.assignRole(principals.get(i).getPrincipal(), role);
147                     }
148                     List JavaDoc<String JavaDoc> groups = roleMap.getGroupNames();
149                     for (int i = 0; i < groups.size(); i++) {
150                         rm.assignRole(new Group(groups.get(i)), role);
151                     }
152                 }
153             }
154         }
155     }
156
157     /**
158      * write the descriptor class to a DOM tree and return it
159      *
160      * @param parent node for the DOM tree
161      * @param the descriptor to write
162      * @return the DOM tree top node
163      */

164     public Node JavaDoc writeDescriptor(Node JavaDoc parent, Descriptor descriptor) {
165         if (! (descriptor instanceof EjbBundleDescriptor)) {
166             throw new IllegalArgumentException JavaDoc(getClass() +
167                 " cannot handles descriptors of type " + descriptor.getClass());
168         }
169         EjbBundleDescriptor bundleDescriptor = (EjbBundleDescriptor) descriptor;
170         Node JavaDoc ejbs = super.writeDescriptor(parent, descriptor);
171
172         // security-role-mapping*
173
List JavaDoc<SecurityRoleMapping> roleMappings = bundleDescriptor.getSecurityRoleMappings();
174         for (int i = 0; i < roleMappings.size(); i++) {
175             SecurityRoleMappingNode srmn = new SecurityRoleMappingNode();
176             srmn.writeDescriptor(ejbs, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMappings.get(i));
177         }
178     
179         // entreprise-beans
180
EntrepriseBeansRuntimeNode ejbsNode = new EntrepriseBeansRuntimeNode();
181         ejbsNode.writeDescriptor(ejbs, RuntimeTagNames.EJBS, bundleDescriptor);
182         return ejbs;
183     }
184 }
185
Popular Tags