KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ear > deployment > api > EarDeploymentDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Florent BENOIT & Ludovic BERT
22  * --------------------------------------------------------------------------
23  * $Id: EarDeploymentDesc.java,v 1.10 2004/07/13 15:20:41 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_ear.deployment.api;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import org.objectweb.jonas_ear.deployment.xml.Application;
38 import org.objectweb.jonas_ear.deployment.xml.JonasApplication;
39 import org.objectweb.jonas_ear.deployment.xml.JonasSecurity;
40 import org.objectweb.jonas_ear.deployment.xml.Module;
41 import org.objectweb.jonas_ear.deployment.xml.SecurityRole;
42 import org.objectweb.jonas_ear.deployment.xml.SecurityRoleMapping;
43 import org.objectweb.jonas_ear.deployment.xml.Web;
44
45 import org.objectweb.jonas_lib.deployment.api.AbsDeploymentDesc;
46
47 /**
48  * This class extends the AbsDeploymentDescriptor class of JOnAS It provides a
49  * description of the specific EAR desployment descriptor
50  * @author Florent Benoit
51  * @author Ludovic Bert
52  * @author Helene Joanin
53  */

54
55 public class EarDeploymentDesc extends AbsDeploymentDesc {
56
57     /**
58      * Vector of connectorTags (Connector objects).
59      */

60     private Vector JavaDoc connectorTags = null;
61
62     /**
63      * Vector of altDD for connectors
64      */

65     private Vector JavaDoc altDDConnectors = null;
66
67     /**
68      * Vector of ejbTags (Ejb objects).
69      */

70     private Vector JavaDoc ejbTags = null;
71
72     /**
73      * Vector of altDD for EJBs
74      */

75     private Vector JavaDoc altDDEjbs = null;
76
77     /**
78      * Vector of webTags (Web objects).
79      */

80     private Vector JavaDoc webTags = null;
81
82     /**
83      * Vector of clientTags (Java objects).
84      */

85     private Vector JavaDoc clientTags = null;
86
87     /**
88      * Vector of altDD for wars
89      */

90     private Vector JavaDoc altDDWebs = null;
91
92     /**
93      * Vector of altDD for clients
94      */

95     private Vector JavaDoc altDDClients = null;
96
97     /**
98      * Vector of security roles
99      */

100     private Vector JavaDoc securityRolesNames = null;
101
102     /**
103      * Xml content of application.xml file
104      */

105     private String JavaDoc xmlContent = null;
106
107     /**
108      * Xml content of jonas-application.xml file
109      */

110     private String JavaDoc jonasXmlContent = null;
111
112     /**
113      * User to role mapping
114      */

115     private Map JavaDoc userToRoleMapping = null;
116
117     /**
118      * Construct an instance of a EarDeploymentDesc. Called by the getInstance()
119      * method.
120      * @param classLoaderForCls ClassLoader of the classes .
121      * @param application application.xml parsed file.
122      * @param jonasApplication jonas-application.xml parsed file.
123      * @throws EarDeploymentDescException if we can't build an instance.
124      */

125     public EarDeploymentDesc(ClassLoader JavaDoc classLoaderForCls, Application application, JonasApplication jonasApplication)
126             throws EarDeploymentDescException {
127
128         // test classloader
129
if (classLoaderForCls == null) {
130             throw new EarDeploymentDescException("DeploymentDesc: Classloader is null");
131         }
132
133         ejbTags = new Vector JavaDoc();
134         connectorTags = new Vector JavaDoc();
135         webTags = new Vector JavaDoc();
136         clientTags = new Vector JavaDoc();
137         altDDEjbs = new Vector JavaDoc();
138         altDDClients = new Vector JavaDoc();
139         altDDConnectors = new Vector JavaDoc();
140         altDDWebs = new Vector JavaDoc();
141         securityRolesNames = new Vector JavaDoc();
142
143         // display name
144
displayName = application.getDisplayName();
145
146         // Tags
147
for (Iterator JavaDoc i = application.getModuleList().iterator(); i.hasNext();) {
148             Module module = (Module) i.next();
149             String JavaDoc ejb = module.getEjb();
150             String JavaDoc connector = module.getConnector();
151             String JavaDoc java = module.getJava();
152             Web web = module.getWeb();
153             String JavaDoc altDD = module.getAltDd();
154             if (ejb != null) {
155                 ejbTags.add(ejb);
156                 altDDEjbs.add(altDD);
157             } else if (connector != null) {
158                 connectorTags.add(connector);
159                 altDDConnectors.add(altDD);
160             } else if (java != null) {
161                 clientTags.add(java);
162                 altDDClients.add(altDD);
163             } else if (web != null) {
164                 webTags.add(web);
165                 altDDWebs.add(altDD);
166             }
167         }
168
169         // application security role
170
for (Iterator JavaDoc i = application.getSecurityRoleList().iterator(); i.hasNext();) {
171             SecurityRole securityRole = (SecurityRole) i.next();
172             if (securityRole != null) {
173                 if (securityRole.getRoleName() != null) {
174                     securityRolesNames.add(securityRole.getRoleName());
175                 }
176             }
177         }
178
179         // user to role mapping
180
JonasSecurity jonasSecurity = jonasApplication.getJonasSecurity();
181         if (jonasSecurity != null) {
182             userToRoleMapping = new HashMap JavaDoc();
183             for (Iterator JavaDoc it = jonasSecurity.getSecurityRoleMappingList().iterator(); it.hasNext();) {
184                 SecurityRoleMapping securityRoleMapping = (SecurityRoleMapping) it.next();
185                 if (securityRoleMapping != null) {
186                     // get role name
187
String JavaDoc roleName = securityRoleMapping.getRoleName();
188                     // get principals
189
List JavaDoc principals = securityRoleMapping.getPrincipalNamesList();
190
191                     // Iterator on principals
192
for (Iterator JavaDoc itPrincipals = principals.iterator(); itPrincipals.hasNext();) {
193                         // get principal name
194
String JavaDoc principalName = (String JavaDoc) itPrincipals.next();
195                         // Existing mapping ?
196
List JavaDoc currentMapping = (List JavaDoc) userToRoleMapping.get(principalName);
197                         if (currentMapping == null) {
198                             currentMapping = new ArrayList JavaDoc();
199                             userToRoleMapping.put(principalName, currentMapping);
200                         }
201                         // add mapping
202
currentMapping.add(roleName);
203                     }
204                 }
205             }
206         }
207
208     }
209
210     /**
211      * Get the ejb tags of the application.xml file.
212      * @return the ejb tags of the application.xml file.
213      */

214     public String JavaDoc[] getEjbTags() {
215         String JavaDoc[] tmp = new String JavaDoc[ejbTags.size()];
216         ejbTags.copyInto(tmp);
217         return tmp;
218     }
219
220     /**
221      * Get the alt-dd of the ejbs of the application.xml file.
222      * @return the alt-dd of the ejbs of the application.xml file.
223      */

224     public String JavaDoc[] getAltDDEjbs() {
225         String JavaDoc[] tmp = new String JavaDoc[altDDEjbs.size()];
226         altDDEjbs.copyInto(tmp);
227         return tmp;
228     }
229
230     /**
231      * Get the client tags of the application.xml file.
232      * @return the client tags of the application.xml file.
233      */

234     public String JavaDoc[] getClientTags() {
235         String JavaDoc[] tmp = new String JavaDoc[clientTags.size()];
236         clientTags.copyInto(tmp);
237         return tmp;
238     }
239
240     /**
241      * Get the alt-dd of the clients of the application.xml file.
242      * @return the alt-dd of the clients of the application.xml file.
243      */

244     public String JavaDoc[] getAltDDClients() {
245         String JavaDoc[] tmp = new String JavaDoc[altDDClients.size()];
246         altDDClients.copyInto(tmp);
247         return tmp;
248     }
249
250     /**
251      * Get the web tags of the application.xml file.
252      * @return the web tags of the application.xml file.
253      */

254     public Web[] getWebTags() {
255         Web[] tmp = new Web[webTags.size()];
256         webTags.copyInto(tmp);
257         return tmp;
258     }
259
260     /**
261      * Get the alt-dd of the wars of the application.xml file.
262      * @return the alt-dd of the wars of the application.xml file.
263      */

264     public String JavaDoc[] getAltDDWebs() {
265         String JavaDoc[] tmp = new String JavaDoc[altDDWebs.size()];
266         altDDWebs.copyInto(tmp);
267         return tmp;
268     }
269
270     /**
271      * Get the connector tags of the application.xml file.
272      * @return the connector tags of the application.xml file.
273      */

274     public String JavaDoc[] getConnectorTags() {
275         String JavaDoc[] tmp = new String JavaDoc[connectorTags.size()];
276         connectorTags.copyInto(tmp);
277         return tmp;
278     }
279
280     /**
281      * Get the alt-dd of the connectors of the application.xml file.
282      * @return the alt-dd of the connectors of the application.xml file.
283      */

284     public String JavaDoc[] getAltDDConnectors() {
285         String JavaDoc[] tmp = new String JavaDoc[altDDConnectors.size()];
286         altDDConnectors.copyInto(tmp);
287         return tmp;
288     }
289
290     /**
291      * Get the security-role names tags
292      * @return the security roles names.
293      */

294     public String JavaDoc[] getSecurityRolesNames() {
295         String JavaDoc[] tmp = new String JavaDoc[securityRolesNames.size()];
296         securityRolesNames.copyInto(tmp);
297         return tmp;
298     }
299
300     /**
301      * Get the content of the xml file
302      * @return the content of the application xml file
303      */

304     public String JavaDoc getXmlContent() {
305         return xmlContent;
306     }
307
308     /**
309      * Get the content of the jonas-application xml file
310      * @return the content of the jonas-application xml file
311      */

312     public String JavaDoc getJonasXmlContent() {
313         return jonasXmlContent;
314     }
315
316     /**
317      * Set the content of the xml file
318      * @param xml the content of the application xml file
319      */

320     public void setXmlContent(String JavaDoc xml) {
321         xmlContent = xml;
322     }
323
324     /**
325      * Set the content of the xml file
326      * @param xml the content of the jonas-application xml file
327      */

328     public void setJonasXmlContent(String JavaDoc xml) {
329         jonasXmlContent = xml;
330     }
331
332     /**
333      * Return a String representation of the EarDeploymentDesc.
334      * @return a String representation of the EarDeploymentDesc.
335      */

336     public String JavaDoc toString() {
337
338         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
339         ret.append("\ndisplay-name=" + displayName);
340         ret.append("\nconnectors=");
341         for (Enumeration JavaDoc e = connectorTags.elements(); e.hasMoreElements();) {
342             ret.append(e.nextElement() + ",");
343         }
344         ret.append("\nejbs=");
345         for (Enumeration JavaDoc e = ejbTags.elements(); e.hasMoreElements();) {
346             ret.append(e.nextElement() + ",");
347         }
348         ret.append("\nwebs=");
349         for (Enumeration JavaDoc e = webTags.elements(); e.hasMoreElements();) {
350             ret.append(((Web) e.nextElement()).getWebUri() + ",");
351         }
352         ret.append("\njavas=");
353         for (Enumeration JavaDoc e = clientTags.elements(); e.hasMoreElements();) {
354             ret.append(e.nextElement() + ",");
355         }
356         ret.append("\nsecurity-roles-names=");
357         for (Enumeration JavaDoc e = securityRolesNames.elements(); e.hasMoreElements();) {
358             ret.append(e.nextElement() + ",");
359         }
360
361         return ret.toString();
362     }
363
364     /**
365      * @return the userToRoleMapping.
366      */

367     public Map JavaDoc getUserToRoleMapping() {
368         return userToRoleMapping;
369     }
370 }
Popular Tags