1 25 26 package org.objectweb.jonas_ejb.deployment.api; 27 28 import java.util.ArrayList ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 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 55 public class DeploymentDescEjb2 extends DeploymentDesc { 56 57 60 private RdbMappingBuilder rdbMapping = null; 61 62 65 private ArrayList ejbRelations = new ArrayList (); 66 67 77 public DeploymentDescEjb2(ClassLoader classLoader, EjbJar ejbJar, 78 JonasEjbJar jonasEjbJar, Logger l, 79 String fileName) 80 throws DeploymentDescException { 81 82 super(classLoader, ejbJar, jonasEjbJar, l, fileName); 85 86 HashMap jonasMessageDriven = new HashMap (); 88 for (Iterator i = jonasEjbJar.getJonasMessageDrivenList().iterator(); i.hasNext(); ) { 89 JonasMessageDriven jMd = (JonasMessageDriven) i.next(); 90 jonasMessageDriven.put(jMd.getEjbName(), jMd); 91 } 92 93 for (Iterator i = ejbJar.getEnterpriseBeans().getMessageDrivenList().iterator(); i.hasNext(); ) { 95 BeanDesc bd = null; 96 MessageDriven md = (MessageDriven) i.next(); 97 102 if (md.getEjbName() == null) { 103 throw new DeploymentDescException("ejb-name missing for a message driven bean"); 104 } 105 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 if (ejbJar.getRelationships() != null) { 121 122 ArrayList stdRelations = new ArrayList (); 124 125 HashMap jonasRelations = new HashMap (); 127 for (Iterator i = jonasEjbJar.getJonasEjbRelationList().iterator(); i.hasNext(); ) { 128 JonasEjbRelation jer = (JonasEjbRelation) i.next(); 129 String jerName = jer.getEjbRelationName(); 130 jonasRelations.put(jerName, jer); 134 } 135 136 for (Iterator i = ejbJar.getRelationships().getEjbRelationList().iterator(); i.hasNext();) { 138 EjbRelation er = (EjbRelation) i.next(); 139 140 EjbRelationDesc erd = new EjbRelationDesc(er, logger); 142 ejbRelations.add(erd); 143 144 stdRelations.add(erd.getName()); 146 147 JonasEjbRelation jer = (JonasEjbRelation) jonasRelations.get(erd.getName()); 149 erd.setJonasInfo(jer); 150 151 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 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 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 erd.fillMappingInfo(); 188 189 erd.fillMappingInfoWithDefault(); 192 } 193 194 for (Iterator i = jonasEjbJar.getJonasEjbRelationList().iterator(); i.hasNext(); ) { 195 JonasEjbRelation jer = (JonasEjbRelation) i.next(); 196 String 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 if (logger.getCurrentIntLevel() == BasicLevel.DEBUG) { 205 logger.log(BasicLevel.DEBUG, "DEPLOYMENT DESCRIPTOR = \n(" + this.toString() + "\n)"); 206 } 207 } 208 209 220 protected BeanDesc newEntityBeanDesc(ClassLoader 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 240 public Manager getJormManager() throws DeploymentDescException { 241 if (rdbMapping == null) { 242 rdbMapping = new RdbMappingBuilder(this, logger); 243 } 244 return rdbMapping.getJormMIManager(); 245 } 246 247 251 public Iterator getEjbRelationDescIterator() { 252 return ejbRelations.iterator(); 253 } 254 255 259 public String toString() { 260 StringBuffer ret = new StringBuffer (); 261 ret.append(super.toString()); 262 for (Iterator i = getEjbRelationDescIterator(); i.hasNext();) { 263 ret.append("\nejbRelationDesc[]=" + i.next()); 264 } 265 return ret.toString(); 266 } 267 268 } 269 | Popular Tags |