KickJava   Java API By Example, From Geeks To Geeks.

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


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  * --------------------------------------------------------------------------
22  * $Id: DeploymentDescEjb2.java,v 1.7 2004/09/17 09:44:19 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.deployment.api;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
32 import org.objectweb.jonas_ejb.deployment.xml.EjbJar;
33 import org.objectweb.jonas_ejb.deployment.xml.EjbRelation;
34 import org.objectweb.jonas_ejb.deployment.xml.Entity;
35 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbJar;
36 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbRelation;
37 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
38 import org.objectweb.jonas_ejb.deployment.xml.JonasMessageDriven;
39 import org.objectweb.jonas_ejb.deployment.xml.MessageDriven;
40 import org.objectweb.jonas_ejb.lib.RdbMappingBuilder;
41 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
42 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
43 import org.objectweb.jorm.metainfo.api.Manager;
44 import org.objectweb.util.monolog.api.Logger;
45 import org.objectweb.util.monolog.api.BasicLevel;
46
47 /**
48  * Class to hold meta-information related to the deployment of an ejb-jar
49  * This subclass is for specification EJB 2.x, i.e. CMP2 persistance and MDB.
50  * It is also responsible for loading the Jorm Meta Information.
51  * @author S.Chassande-Barrioz : Initial developer
52  * @author Christophe Ney [cney@batisseurs.com]
53  * @author Philippe Durieux (new Jorm mapping)
54  */

55 public class DeploymentDescEjb2 extends DeploymentDesc {
56
57     /**
58      * The JORM meta-information manager
59      */

60     private RdbMappingBuilder rdbMapping = null;
61
62     /**
63      * List of relations (EjbRelationDesc) defined in this Descriptor
64      */

65     private ArrayList JavaDoc ejbRelations = new ArrayList JavaDoc();
66
67     /**
68      * Build the Meta-Information from the XML data binding trees
69      * containing the EJB and JOnAS deployment descriptors.
70      * @param classLoader The Class Loader to be used
71      * @param ejbJar The EjbJar information, from standard deployment descriptor.
72      * @param jonasEjbJar The JonasEjbJar information, from JOnAS specific deployment descriptor.
73      * @param l The logger to be used for tracing
74      * @param FileName deployment desc's jar or directory name
75      * @throws DeploymentDescException Error when building the Deployment Descriptor
76      */

77     public DeploymentDescEjb2(ClassLoader JavaDoc classLoader, EjbJar ejbJar,
78                               JonasEjbJar jonasEjbJar, Logger l,
79                               String JavaDoc fileName)
80         throws DeploymentDescException {
81
82         // Session and Entity bean descriptors are built here.
83
// This part is common with EJB1.1 spec (no CMP2, no MDB)
84
super(classLoader, ejbJar, jonasEjbJar, l, fileName);
85
86         // HashMap of jonas-message-driven
87
HashMap JavaDoc jonasMessageDriven = new HashMap JavaDoc();
88         for (Iterator JavaDoc i = jonasEjbJar.getJonasMessageDrivenList().iterator(); i.hasNext(); ) {
89             JonasMessageDriven jMd = (JonasMessageDriven) i.next();
90             jonasMessageDriven.put(jMd.getEjbName(), jMd);
91         }
92
93         // message-driven beans
94
for (Iterator JavaDoc i = ejbJar.getEnterpriseBeans().getMessageDrivenList().iterator(); i.hasNext(); ) {
95             BeanDesc bd = null;
96             MessageDriven md = (MessageDriven) i.next();
97             /*
98              * The Standard DTD allows a message-driven-bean without ejb-name
99              * Problem to associate infos to this bean (trans-attribute, jonas-specific infos)
100              * So the ejb-name must be specify and we check this
101              */

102             if (md.getEjbName() == null) {
103                 throw new DeploymentDescException("ejb-name missing for a message driven bean");
104             }
105             // find corresponding jonas message-driven
106
JonasMessageDriven jMd = (JonasMessageDriven) jonasMessageDriven.get(md.getEjbName());
107             if (jMd == null) {
108                 throw new DeploymentDescException("jonas-message-driven-bean missing for bean " + md.getEjbName());
109             }
110
111             bd = new MessageDrivenDesc(classLoader, md, asd, jMd,
112                     jonasEjbJar.getJonasMessageDestinationList(), fileName);
113             
114             bd.setDeploymentDesc(this);
115             bd.check();
116             beanDesc.put(bd.getEjbName(), bd);
117         }
118
119         // Relations on Entity beans CMP2
120
if (ejbJar.getRelationships() != null) {
121
122             // ArrayList of standard-relation names (Strings)
123
ArrayList JavaDoc stdRelations = new ArrayList JavaDoc();
124
125             // HashMap of jonas-relation
126
HashMap JavaDoc jonasRelations = new HashMap JavaDoc();
127             for (Iterator JavaDoc i = jonasEjbJar.getJonasEjbRelationList().iterator(); i.hasNext(); ) {
128                 JonasEjbRelation jer = (JonasEjbRelation) i.next();
129                 String JavaDoc jerName = jer.getEjbRelationName();
130                 //if (!stdRelations.contains(jerName)) {
131
// throw new DeploymentDescException("ejb-relation missing in ejb-jar.xml for the relation " + jerName);
132
//}
133
jonasRelations.put(jerName, jer);
134             }
135
136             // ejb-relation
137
for (Iterator JavaDoc i = ejbJar.getRelationships().getEjbRelationList().iterator(); i.hasNext();) {
138                 EjbRelation er = (EjbRelation) i.next();
139
140                 // build the descriptors for the relation.
141
EjbRelationDesc erd = new EjbRelationDesc(er, logger);
142                 ejbRelations.add(erd);
143
144                 // Keep a list of relation names.
145
stdRelations.add(erd.getName());
146
147                 // find corresponding jonas relation (may not exist)
148
JonasEjbRelation jer = (JonasEjbRelation) jonasRelations.get(erd.getName());
149                 erd.setJonasInfo(jer);
150
151                 // makes the links between entity beans and relationship roles
152
EjbRelationshipRoleDesc rsd1 = erd.getRelationshipRole1();
153                 EjbRelationshipRoleDesc rsd2 = erd.getRelationshipRole2();
154                 EntityCmp2Desc ed1 = (EntityCmp2Desc) beanDesc.get(rsd1.getSourceBeanName());
155                 EntityCmp2Desc ed2 = (EntityCmp2Desc) beanDesc.get(rsd2.getSourceBeanName());
156                 // Check the sources beans names are correct
157
if ((ed1 == null) || (ed2 == null)) {
158                     throw new DeploymentDescException("Invalid ejb-name for a relation-ship-role-source for the relation '"
159                                                       + erd.getName()
160                                                       + "' ('"
161                                                       + rsd1.getSourceBeanName()
162                                                       + "' or '"
163                                                       + rsd2.getSourceBeanName()
164                                                       + "' invalid)");
165                 }
166                 // Check if the source beans have local interfaces
167
if ((ed1.getLocalHomeClass() == null) || (ed1.getLocalClass() == null)) {
168                     throw new DeploymentDescException("The entity bean '" + ed1.getEjbName()
169                                                       + "' involved in the relationship '"
170                                                       + erd.getName()
171                                                       + "' must have local interfaces");
172                 }
173                 if ((ed2.getLocalHomeClass() == null) || (ed2.getLocalClass() == null)) {
174                     throw new DeploymentDescException("The entity bean '" + ed2.getEjbName()
175                                                       + "' involved in the relationship '"
176                                                       + erd.getName()
177                                                       + "' must have local interfaces");
178                 }
179                 ed1.addEjbRelationshipRoleDesc(rsd1);
180                 ed2.addEjbRelationshipRoleDesc(rsd2);
181                 rsd1.setTargetBean(ed2);
182                 rsd1.setSourceBean(ed1);
183                 rsd2.setTargetBean(ed1);
184                 rsd2.setSourceBean(ed2);
185
186                 // Fill the mapping information with the values defined in jonas DD
187
erd.fillMappingInfo();
188
189                 // Fill the mapping information for the relation with default values
190
// if some mapping information is missing
191
erd.fillMappingInfoWithDefault();
192             }
193
194             for (Iterator JavaDoc i = jonasEjbJar.getJonasEjbRelationList().iterator(); i.hasNext(); ) {
195                 JonasEjbRelation jer = (JonasEjbRelation) i.next();
196                 String JavaDoc jerName = jer.getEjbRelationName();
197                 if (!stdRelations.contains(jerName)) {
198                     throw new DeploymentDescException("ejb-relation missing in ejb-jar.xml for the relation " + jerName);
199                 }
200             }
201         }
202
203         // Trace
204
if (logger.getCurrentIntLevel() == BasicLevel.DEBUG) {
205             logger.log(BasicLevel.DEBUG, "DEPLOYMENT DESCRIPTOR = \n(" + this.toString() + "\n)");
206         }
207     }
208
209     /**
210      * In case of beans with old CMP1 persistance, we need to instanciate the old class,
211      * as if we were in an old Deployment Descriptor.
212      * Default is CMP2.x for entity beans with a EJB2.0 DD.
213      * @param classLoader The ClassLoader to be used
214      * @param ent Entity MetaInformation from XML files
215      * @param asd AssemblyDescriptor MetaInformation from XML files
216      * @param jEnt JonasEntity MetaInformation from XML files
217      * @return The Entity Bean Descriptor, for the good CMP version.
218      * @throws DeploymentDescException Cannot build Entity Descriptor
219      */

220     protected BeanDesc newEntityBeanDesc(ClassLoader JavaDoc classLoader,
221                                          Entity ent,
222                                          AssemblyDescriptor asd,
223                                          JonasEntity jEnt,
224                                          JLinkedList jMDRList)
225         throws DeploymentDescException {
226
227         if (ent.getCmpVersion() == null || ent.getCmpVersion().equals("2.x")) {
228             return new EntityJdbcCmp2Desc(classLoader, ent, asd, jEnt, this, jMDRList, fileName);
229         } else {
230             return new EntityJdbcCmp1Desc(classLoader, ent, asd, jEnt, jMDRList, fileName);
231         }
232     }
233
234     /**
235      * get the JORM Manager
236      * At first call, loads all the meta information for entity beans CMP2
237      * @return The Jorm Manager
238      * @throws DeploymentDescException Cannot build Jorm Meta Information
239      */

240     public Manager getJormManager() throws DeploymentDescException {
241         if (rdbMapping == null) {
242             rdbMapping = new RdbMappingBuilder(this, logger);
243         }
244         return rdbMapping.getJormMIManager();
245     }
246
247     /**
248      * Get iterator of meta-info for all defined relations
249      * @return an iterator of EjbRelationDesc
250      */

251     public Iterator JavaDoc getEjbRelationDescIterator() {
252         return ejbRelations.iterator();
253     }
254
255     /**
256      * String representation of the object for test purpose
257      * @return String representation of this object
258      */

259     public String JavaDoc toString() {
260         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
261         ret.append(super.toString());
262         for (Iterator JavaDoc i = getEjbRelationDescIterator(); i.hasNext();) {
263             ret.append("\nejbRelationDesc[]=" + i.next());
264         }
265         return ret.toString();
266     }
267
268 }
269
Popular Tags