KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > api > DeploymentDesc


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 021ejbJarDD11-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: DeploymentDesc.java,v 1.39 2004/09/17 09:44:19 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.deployment.api;
28
29 import java.util.HashMap JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.LinkedList JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
36 import org.objectweb.jonas_ejb.deployment.xml.EjbJar;
37 import org.objectweb.jonas_ejb.deployment.xml.Entity;
38 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbJar;
39 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
40 import org.objectweb.jonas_ejb.deployment.xml.JonasRunAsMapping;
41 import org.objectweb.jonas_ejb.deployment.xml.JonasSession;
42 import org.objectweb.jonas_ejb.deployment.xml.MethodPermission;
43 import org.objectweb.jonas_ejb.deployment.xml.Session;
44
45 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
46 import org.objectweb.jonas_lib.deployment.api.DescriptionGroupDesc;
47 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
48 import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestination;
49 import org.objectweb.jonas_lib.deployment.xml.MessageDestination;
50
51 import org.objectweb.util.monolog.api.Logger;
52
53 /**
54  * Class to hold meta-information related to the deployment of an ejb-jar
55  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
56  * @author Helene Joanin
57  * @author Philippe Durieux
58  * @author Markus Karg (Novell port)
59  * @author Philippe Coq
60  */

61 public abstract class DeploymentDesc extends DescriptionGroupDesc {
62
63     /**
64      * Logger
65      */

66     protected Logger logger;
67
68
69     /**
70      * Ejb spec version
71      */

72     protected String JavaDoc specVersion = null;
73
74     /**
75      * Set of enterprise beans deployment descriptors
76      */

77     protected HashMap JavaDoc beanDesc = new HashMap JavaDoc();
78
79     /**
80      * Assembly descriptor
81      */

82     protected AssemblyDescriptor asd = null;
83
84     /**
85      * Deployment desc's file name (jar or directory)
86      */

87     protected String JavaDoc fileName = null;
88
89     /**
90      * Deployment desc's file name (jar or directory)
91      */

92     protected String JavaDoc ejbClientJar = null;
93
94     /**
95      * List of MethodPermissions
96      */

97     private List JavaDoc methodPermissionsDescList = null;
98
99     /**
100      * ExcludeList in Assembly descriptor
101      */

102     private ExcludeListDesc excludeListDesc = null;
103
104     /**
105      * List of JonasMessageDestinations
106      */

107     protected JLinkedList jonasMDList = null;
108
109     /**
110      * Xml content of the standard deployement descriptor file
111      */

112     private String JavaDoc xmlContent = "";
113
114     /**
115      * Xml content of the JOnAS deployement descriptor file
116      */

117     private String JavaDoc jonasXmlContent = "";
118
119     /**
120      * Mapping for runAs principals
121      * Principal name --> list of roles (array)
122      */

123     private Map JavaDoc runAsMapping = null;
124
125     /**
126      * Build the Meta-Information from the XML data binding trees
127      * containing the EJB and JOnAS deployment descriptors.
128      * @param classLoader The Class Loader to be used
129      * @param ejbJar The EjbJar information, from standard deployment descriptor.
130      * @param jonasEjbJar The JonasEjbJar information, from JOnAS specific deployment descriptor.
131      * @param l The logger to be used for tracing
132      * @param fileName deployment desc's jar or directory name
133      * @throws DeploymentDescException Cannot deploy bean
134      */

135     public DeploymentDesc(ClassLoader JavaDoc classLoader,
136                                 EjbJar ejbJar,
137                                 JonasEjbJar jonasEjbJar,
138                                 Logger l,
139                                 String JavaDoc fileName)
140         throws DeploymentDescException {
141
142
143         logger = l;
144
145         // set jarFileName
146
this.fileName = fileName;
147
148         // test classloader
149
if (classLoader == null) {
150             throw new DeploymentDescException("DeploymentDesc: Classloader is null");
151         }
152
153         // test the validity of the ejbJar (EnterpriseBeans must be present)
154
if (ejbJar.getEnterpriseBeans() == null) {
155             throw new DeploymentDescException("invalid standard deployment descriptor (<enterprise-beans> element missing)");
156         }
157         // spec-version
158
specVersion = ejbJar.getVersion();
159
160         // ejb-client-jar
161
ejbClientJar = ejbJar.getEjbClientJar();
162
163         // assembly descriptor
164
asd = ejbJar.getAssemblyDescriptor();
165
166         // Run-as mapping
167
runAsMapping = new HashMap JavaDoc();
168         for (Iterator JavaDoc i = jonasEjbJar.getJonasRunAsMappingList().iterator(); i.hasNext();) {
169             // Get Mapping
170
JonasRunAsMapping jonasRunAsMapping = (JonasRunAsMapping) i.next();
171             String JavaDoc principalName = jonasRunAsMapping.getPrincipalName();
172             // Get existing roles if any
173
String JavaDoc[] existingRunAsRoleMapping = (String JavaDoc[]) runAsMapping.get(principalName);
174             String JavaDoc[] newMappingRoles = null;
175             int r = 0;
176             if (existingRunAsRoleMapping == null) {
177                 newMappingRoles = new String JavaDoc[jonasRunAsMapping.getRoleNamesList().size()];
178             } else {
179                 newMappingRoles = new String JavaDoc[jonasRunAsMapping.getRoleNamesList().size() + existingRunAsRoleMapping.length];
180                 // Now add existing roles
181
System.arraycopy(existingRunAsRoleMapping, 0, newMappingRoles, 0, existingRunAsRoleMapping.length);
182                 r = existingRunAsRoleMapping.length;
183             }
184             Iterator JavaDoc itR = jonasRunAsMapping.getRoleNamesList().iterator();
185             while (itR.hasNext()) {
186                 newMappingRoles[r] = (String JavaDoc) itR.next();
187                 r++;
188             }
189             runAsMapping.put(principalName, newMappingRoles);
190
191         }
192
193         // Use by PermissionManager for translating xml into EJBMethodPermission
194
methodPermissionsDescList = new LinkedList JavaDoc();
195         // Create EJBMEthodPermissions for each method-permission
196
if (asd != null) {
197             for (Iterator JavaDoc i = asd.getMethodPermissionList().iterator(); i.hasNext();) {
198                 MethodPermission methodPermission = (MethodPermission) i.next();
199                 methodPermissionsDescList.add(new MethodPermissionDesc(methodPermission));
200             }
201         }
202
203         // Use by PermissionManager for translating xml into EJBMethodPermission
204
if (asd != null && asd.getExcludeList() != null) {
205             excludeListDesc = new ExcludeListDesc(asd.getExcludeList());
206         }
207
208         // jonas-message-destination
209
jonasMDList = jonasEjbJar.getJonasMessageDestinationList();
210
211         // HashMap of jonas-session
212
HashMap JavaDoc jonasSession = new HashMap JavaDoc();
213         for (Iterator JavaDoc i = jonasEjbJar.getJonasSessionList().iterator(); i.hasNext();) {
214             JonasSession jSes = (JonasSession) i.next();
215             jonasSession.put(jSes.getEjbName(), jSes);
216         }
217
218         // session beans
219
for (Iterator JavaDoc i = ejbJar.getEnterpriseBeans().getSessionList().iterator(); i.hasNext();) {
220             BeanDesc bd = null;
221             Session ses = (Session) i.next();
222             // find corresponding jonas session
223
JonasSession jSes = (JonasSession) jonasSession.get(ses.getEjbName());
224             if (jSes == null) {
225                 // Build a default jonas-session if not exist
226
jSes = new JonasSession();
227                 jSes.setEjbName(ses.getEjbName());
228             }
229             if (ses.getSessionType().equals("Stateful")) {
230                 // stateful
231
bd = new SessionStatefulDesc(classLoader, ses, asd, jSes, jonasMDList, fileName);
232             } else if (ses.getSessionType().equals("Stateless")) {
233                 // stateless
234
bd = new SessionStatelessDesc(classLoader, ses, asd, jSes, jonasMDList, fileName);
235             } else {
236                 throw new DeploymentDescException("invalid session-type content for bean " + ses.getEjbName());
237             }
238             bd.setDeploymentDesc(this);
239             bd.check();
240             beanDesc.put(bd.getEjbName(), bd);
241         }
242
243         // HashMap of jonas-entity
244
HashMap JavaDoc jonasEntity = new HashMap JavaDoc();
245         for (Iterator JavaDoc i = jonasEjbJar.getJonasEntityList().iterator(); i.hasNext();) {
246             JonasEntity jEnt = (JonasEntity) i.next();
247             jonasEntity.put(jEnt.getEjbName(), jEnt);
248         }
249         // entity beans
250
for (Iterator JavaDoc i = ejbJar.getEnterpriseBeans().getEntityList().iterator(); i.hasNext();) {
251             BeanDesc bd = null;
252             Entity ent = (Entity) i.next();
253             // find corresponding jonas entity
254
JonasEntity jEnt = (JonasEntity) jonasEntity.get(ent.getEjbName());
255             if (jEnt == null) {
256                 throw new DeploymentDescException("jonas-entity missing for bean " + ent.getEjbName());
257             }
258             if (ent.getPersistenceType().equals("Bean")) {
259                 // bean managed
260
bd = new EntityBmpDesc(classLoader, ent, asd, jEnt, jonasMDList, fileName);
261             } else if (ent.getPersistenceType().equals("Container")) {
262                 // container managed (always jdbc)
263
bd = newEntityBeanDesc(classLoader, ent, asd, jEnt, jonasMDList);
264             } else {
265                 throw new DeploymentDescException("Invalid persistence-type content for bean " + ent.getEjbName());
266             }
267             bd.setDeploymentDesc(this);
268             bd.check();
269             beanDesc.put(bd.getEjbName(), bd);
270         }
271     }
272
273     /**
274      * Get an Iterator on the Bean Desc list
275      * @return Iterator on BeanDesc
276      */

277     public Iterator JavaDoc getBeanDescIterator() {
278         return beanDesc.values().iterator();
279     }
280
281     /**
282      * Get descriptors for all beans contained in jar file
283      * @return Array of bean's descriptors
284      */

285     public BeanDesc[] getBeanDesc() {
286         BeanDesc[] ret = new BeanDesc[beanDesc.size()];
287         int j = 0;
288         for (Iterator JavaDoc i = beanDesc.values().iterator(); i.hasNext(); j++) {
289             ret[j] = (BeanDesc) i.next();
290         }
291         return ret;
292     }
293
294     /**
295      * Gets the Mapping for run-as principal
296      * @param principalName name of the run-as principal
297      * @return array of roles
298      */

299     public String JavaDoc[] getRolesForRunAsPrincipal(String JavaDoc principalName) {
300         return (String JavaDoc[]) runAsMapping.get(principalName);
301     }
302
303     /**
304      * Get bean descriptor given its name
305      * @param ejbName the name of the bean in the Deployment Descriptor
306      * @return bean descriptor given its name
307      */

308     public BeanDesc getBeanDesc(String JavaDoc ejbName) {
309         return (BeanDesc) beanDesc.get(ejbName);
310     }
311
312     /**
313      * Get bean descriptor given its abstract schema name
314      * @param asn Abstract Schema Name
315      * @return null if it doesn't exist.
316      */

317     public EntityCmp2Desc asn2BeanDesc(String JavaDoc asn) {
318         for (Iterator JavaDoc i = beanDesc.values().iterator(); i.hasNext();) {
319             BeanDesc bd = (BeanDesc) i.next();
320             if (bd instanceof EntityCmp2Desc) {
321                 if (asn.equals(((EntityCmp2Desc) bd).getAbstractSchemaName())) {
322                     return ((EntityCmp2Desc) bd);
323                 }
324             }
325         }
326         return null;
327     }
328
329
330     /**
331      * Get the list of the methodPermissionDesc objects which represent
332      * method-permission elements in assembly-descriptor
333      * @return the list of methodPermissionDesc objects
334      */

335     public List JavaDoc getMethodPermissionsDescList() {
336         return methodPermissionsDescList;
337     }
338
339     /**
340      * Get the exclude list of the assembly descriptor
341      * @return the exclude list of the assembly descriptor
342      */

343     public ExcludeListDesc getExcludeListDesc() {
344         return excludeListDesc;
345     }
346
347
348     /**
349      * Get bean descriptor given its interface local name
350      * @param itfLocalName local interface name
351      * @return null if it doesn't exist.
352      */

353     public BeanDesc getBeanDescWithLocalInterface(String JavaDoc itfLocalName) {
354         for (Iterator JavaDoc i = beanDesc.values().iterator(); i.hasNext();) {
355             BeanDesc bd = (BeanDesc) i.next();
356             if (bd.getLocalClass() != null) {
357                 if (itfLocalName.equals(bd.getLocalClass().getName())) {
358                     return bd;
359                 }
360             }
361         }
362         return null;
363     }
364
365     /**
366      * Find the JOnAS message destination for the given name
367      * @param mdLink the name of the message destination link in the Deployment Descriptor
368      * @return boolean if link was found
369      */

370     public boolean getMessageDestination(String JavaDoc mdLink) {
371         MessageDestination md = null;
372         if (asd != null && asd.getMessageDestinationList() != null) {
373             for (Iterator JavaDoc i = asd.getMessageDestinationList().iterator(); i.hasNext();) {
374                 md = (MessageDestination) i.next();
375                 if (md.getMessageDestinationName().equals(mdLink)) {
376                     return true;
377                 }
378             }
379         }
380         return false;
381     }
382
383     /**
384      * Get the JOnAS message destination for the given name
385      * @param mdLink the name of the message destination link in the Deployment Descriptor
386      * @return the jonas message destination given the name
387      */

388     public JonasMessageDestination getJonasMessageDestination(String JavaDoc mdLink) {
389         JonasMessageDestination jmd = null;
390         if (jonasMDList != null) {
391             for (Iterator JavaDoc i = jonasMDList.iterator(); i.hasNext();) {
392                 jmd = (JonasMessageDestination) i.next();
393                 if (jmd.getMessageDestinationName().equals(mdLink)) {
394                     return jmd;
395                 }
396             }
397         }
398         return null;
399     }
400
401     /**
402      * In case of beans with old CMP1 persistance, we need to instanciate the old class,
403      * as if we were in an old Deployment Descriptor.
404      * Default is CMP2.x for entity beans with a EJB2.0 DD.
405      *
406      * @param cl The ClassLoader to be used
407      * @param ent Entity MetaInformation from XML files
408      * @param asd AssemblyDescriptor MetaInformation from XML files
409      * @param j JonasEntity MetaInformation from XML files
410      * @param jMDRList MessageDrivenRef list
411      *
412      * @return The Entity Bean Descriptor, for the good CMP version.
413      *
414      * @throws DeploymentDescException Cannot build Entity Descriptor
415      */

416     protected abstract BeanDesc newEntityBeanDesc(ClassLoader JavaDoc cl, Entity ent,
417                                                   AssemblyDescriptor asd, JonasEntity j, JLinkedList jMDRList)
418         throws DeploymentDescException;
419
420     /**
421      * Get the display name
422      * @return the Display name string, from the deployment descriptor.
423      */

424     public String JavaDoc getDisplayName() {
425         return displayName;
426     }
427
428     /**
429      * Get the ejb-client-jar name
430      * @return the ejb-client-jar string, from the deployment descriptor (may be null).
431      */

432     public String JavaDoc getEjbClientJar() {
433         return ejbClientJar;
434     }
435
436
437     /**
438      * get the current logger
439      * @return the Logger
440      */

441     public Logger getLogger() {
442         return logger;
443     }
444
445     /**
446      * set the current logger
447      * @param logger the Logger
448      */

449     public void setLogger(Logger logger) {
450         this.logger = logger;
451     }
452
453     /**
454      * Return the content of the web.xml file
455      * @return the content of the web.xml file
456      */

457     public String JavaDoc getXmlContent() {
458         return xmlContent;
459     }
460
461     /**
462      * Return the content of the jonas-web.xml file
463      * @return the content of the jonas-web.xml file
464      */

465     public String JavaDoc getJOnASXmlContent() {
466         return jonasXmlContent;
467     }
468
469     /**
470      * String representation of the object for test purpose
471      * @return String representation of this object
472      */

473     public String JavaDoc toString() {
474         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
475         ret.append("\ngetDisplayName()=" + getDisplayName());
476         ret.append("\ngetEjbClientJar()=" + getEjbClientJar());
477         BeanDesc[] b = getBeanDesc();
478         for (int i = 0; i < b.length; i++) {
479             ret.append("\ngetBeanDesc(" + i + ")=" + b[i].getClass().getName());
480             ret.append(b[i].toString());
481         }
482         return ret.toString();
483     }
484
485     /**
486      * @param xmlContent XML Content
487      */

488     public void setXmlContent(String JavaDoc xmlContent) {
489         this.xmlContent = xmlContent;
490     }
491
492     /**
493      * @param jonasXmlContent XML Content
494      */

495     public void setJOnASXmlContent(String JavaDoc jonasXmlContent) {
496         this.jonasXmlContent = jonasXmlContent;
497     }
498
499 }
500
Popular Tags