DeploymentDescEjb2.java

00001 
00026 package org.objectweb.jonas_ejb.deployment.api;
00027 
00028 import java.util.ArrayList;
00029 import java.util.HashMap;
00030 import java.util.Iterator;
00031 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
00032 import org.objectweb.jonas_ejb.deployment.xml.EjbJar;
00033 import org.objectweb.jonas_ejb.deployment.xml.EjbRelation;
00034 import org.objectweb.jonas_ejb.deployment.xml.Entity;
00035 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbJar;
00036 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbRelation;
00037 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
00038 import org.objectweb.jonas_ejb.deployment.xml.JonasMessageDriven;
00039 import org.objectweb.jonas_ejb.deployment.xml.MessageDriven;
00040 import org.objectweb.jonas_ejb.lib.RdbMappingBuilder;
00041 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00042 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
00043 import org.objectweb.jorm.metainfo.api.Manager;
00044 import org.objectweb.util.monolog.api.Logger;
00045 import org.objectweb.util.monolog.api.BasicLevel;
00046 
00055 public class DeploymentDescEjb2 extends DeploymentDesc {
00056 
00060     private RdbMappingBuilder rdbMapping = null;
00061 
00065     private ArrayList ejbRelations = new ArrayList();
00066 
00077     public DeploymentDescEjb2(ClassLoader classLoader, EjbJar ejbJar,
00078                               JonasEjbJar jonasEjbJar, Logger l,
00079                               String fileName)
00080         throws DeploymentDescException {
00081 
00082         // Session and Entity bean descriptors are built here.
00083         // This part is common with EJB1.1 spec (no CMP2, no MDB)
00084         super(classLoader, ejbJar, jonasEjbJar, l, fileName);
00085 
00086         // HashMap of jonas-message-driven
00087         HashMap jonasMessageDriven = new HashMap();
00088         for (Iterator i = jonasEjbJar.getJonasMessageDrivenList().iterator(); i.hasNext(); ) {
00089             JonasMessageDriven jMd = (JonasMessageDriven) i.next();
00090             jonasMessageDriven.put(jMd.getEjbName(), jMd);
00091         }
00092 
00093         // message-driven beans
00094         for (Iterator i = ejbJar.getEnterpriseBeans().getMessageDrivenList().iterator(); i.hasNext(); ) {
00095             BeanDesc bd = null;
00096             MessageDriven md = (MessageDriven) i.next();
00097             /*
00098              * The Standard DTD allows a message-driven-bean without ejb-name
00099              * Problem to associate infos to this bean (trans-attribute, jonas-specific infos)
00100              * So the ejb-name must be specify and we check this
00101              */
00102             if (md.getEjbName() == null) {
00103                 throw new DeploymentDescException("ejb-name missing for a message driven bean");
00104             }
00105             // find corresponding jonas message-driven
00106             JonasMessageDriven jMd = (JonasMessageDriven) jonasMessageDriven.get(md.getEjbName());
00107             if (jMd == null) {
00108                 throw new DeploymentDescException("jonas-message-driven-bean missing for bean " + md.getEjbName());
00109             }
00110 
00111             bd = new MessageDrivenDesc(classLoader, md, asd, jMd,
00112                     jonasEjbJar.getJonasMessageDestinationList(), fileName);
00113             
00114             bd.setDeploymentDesc(this);
00115             bd.check();
00116             beanDesc.put(bd.getEjbName(), bd);
00117         }
00118 
00119         // Relations on Entity beans CMP2
00120         if (ejbJar.getRelationships() != null) {
00121 
00122             // ArrayList of standard-relation names (Strings)
00123             ArrayList stdRelations = new ArrayList();
00124 
00125             // HashMap of jonas-relation
00126             HashMap jonasRelations = new HashMap();
00127             for (Iterator i = jonasEjbJar.getJonasEjbRelationList().iterator(); i.hasNext(); ) {
00128                 JonasEjbRelation jer = (JonasEjbRelation) i.next();
00129                 String jerName = jer.getEjbRelationName();
00130                 //if (!stdRelations.contains(jerName)) {
00131                 //    throw new DeploymentDescException("ejb-relation missing in ejb-jar.xml for the relation " + jerName);
00132                 //}
00133                 jonasRelations.put(jerName, jer);
00134             }
00135 
00136             // ejb-relation
00137             for (Iterator i = ejbJar.getRelationships().getEjbRelationList().iterator(); i.hasNext();) {
00138                 EjbRelation er = (EjbRelation) i.next();
00139 
00140                 // build the descriptors for the relation.
00141                 EjbRelationDesc erd = new EjbRelationDesc(er, logger);
00142                 ejbRelations.add(erd);
00143 
00144                 // Keep a list of relation names.
00145                 stdRelations.add(erd.getName());
00146 
00147                 // find corresponding jonas relation (may not exist)
00148                 JonasEjbRelation jer = (JonasEjbRelation) jonasRelations.get(erd.getName());
00149                 erd.setJonasInfo(jer);
00150 
00151                 // makes the links between entity beans and relationship roles
00152                 EjbRelationshipRoleDesc rsd1 = erd.getRelationshipRole1();
00153                 EjbRelationshipRoleDesc rsd2 = erd.getRelationshipRole2();
00154                 EntityCmp2Desc ed1 = (EntityCmp2Desc) beanDesc.get(rsd1.getSourceBeanName());
00155                 EntityCmp2Desc ed2 = (EntityCmp2Desc) beanDesc.get(rsd2.getSourceBeanName());
00156                 // Check the sources beans names are correct
00157                 if ((ed1 == null) || (ed2 == null)) {
00158                     throw new DeploymentDescException("Invalid ejb-name for a relation-ship-role-source for the relation '"
00159                                                       + erd.getName()
00160                                                       + "' ('"
00161                                                       + rsd1.getSourceBeanName()
00162                                                       + "' or '"
00163                                                       + rsd2.getSourceBeanName()
00164                                                       + "' invalid)");
00165                 }
00166                 // Check if the source beans have local interfaces
00167                 if ((ed1.getLocalHomeClass() == null) || (ed1.getLocalClass() == null)) {
00168                     throw new DeploymentDescException("The entity bean '" + ed1.getEjbName()
00169                                                       + "' involved in the relationship '"
00170                                                       + erd.getName()
00171                                                       + "' must have local interfaces");
00172                 }
00173                 if ((ed2.getLocalHomeClass() == null) || (ed2.getLocalClass() == null)) {
00174                     throw new DeploymentDescException("The entity bean '" + ed2.getEjbName()
00175                                                       + "' involved in the relationship '"
00176                                                       + erd.getName()
00177                                                       + "' must have local interfaces");
00178                 }
00179                 ed1.addEjbRelationshipRoleDesc(rsd1);
00180                 ed2.addEjbRelationshipRoleDesc(rsd2);
00181                 rsd1.setTargetBean(ed2);
00182                 rsd1.setSourceBean(ed1);
00183                 rsd2.setTargetBean(ed1);
00184                 rsd2.setSourceBean(ed2);
00185 
00186                 // Fill the mapping information with the values defined in jonas DD
00187                 erd.fillMappingInfo();
00188 
00189                 // Fill the mapping information for the relation with default values
00190                 // if some mapping information is missing
00191                 erd.fillMappingInfoWithDefault();
00192             }
00193 
00194             for (Iterator i = jonasEjbJar.getJonasEjbRelationList().iterator(); i.hasNext(); ) {
00195                 JonasEjbRelation jer = (JonasEjbRelation) i.next();
00196                 String jerName = jer.getEjbRelationName();
00197                 if (!stdRelations.contains(jerName)) {
00198                     throw new DeploymentDescException("ejb-relation missing in ejb-jar.xml for the relation " + jerName);
00199                 }
00200             }
00201         }
00202 
00203         // Trace
00204         if (logger.getCurrentIntLevel() == BasicLevel.DEBUG) {
00205             logger.log(BasicLevel.DEBUG, "DEPLOYMENT DESCRIPTOR = \n(" + this.toString() + "\n)");
00206         }
00207     }
00208 
00220     protected BeanDesc newEntityBeanDesc(ClassLoader classLoader,
00221                                          Entity ent,
00222                                          AssemblyDescriptor asd,
00223                                          JonasEntity jEnt,
00224                                          JLinkedList jMDRList)
00225         throws DeploymentDescException {
00226 
00227         if (ent.getCmpVersion() == null || ent.getCmpVersion().equals("2.x")) {
00228             return new EntityJdbcCmp2Desc(classLoader, ent, asd, jEnt, this, jMDRList, fileName);
00229         } else {
00230             return new EntityJdbcCmp1Desc(classLoader, ent, asd, jEnt, jMDRList, fileName);
00231         }
00232     }
00233 
00240     public Manager getJormManager() throws DeploymentDescException {
00241         if (rdbMapping == null) {
00242             rdbMapping = new RdbMappingBuilder(this, logger);
00243         }
00244         return rdbMapping.getJormMIManager();
00245     }
00246 
00251     public Iterator getEjbRelationDescIterator() {
00252         return ejbRelations.iterator();
00253     }
00254 
00259     public String toString() {
00260         StringBuffer ret = new StringBuffer();
00261         ret.append(super.toString());
00262         for (Iterator i = getEjbRelationDescIterator(); i.hasNext();) {
00263             ret.append("\nejbRelationDesc[]=" + i.next());
00264         }
00265         return ret.toString();
00266     }
00267 
00268 }

Generated on Tue Feb 15 15:05:44 2005 for JOnAS by  doxygen 1.3.9.1