1 25 26 27 package org.objectweb.jonas_ejb.deployment.api; 28 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.LinkedList ; 32 import java.util.List ; 33 import java.util.Map ; 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 61 public abstract class DeploymentDesc extends DescriptionGroupDesc { 62 63 66 protected Logger logger; 67 68 69 72 protected String specVersion = null; 73 74 77 protected HashMap beanDesc = new HashMap (); 78 79 82 protected AssemblyDescriptor asd = null; 83 84 87 protected String fileName = null; 88 89 92 protected String ejbClientJar = null; 93 94 97 private List methodPermissionsDescList = null; 98 99 102 private ExcludeListDesc excludeListDesc = null; 103 104 107 protected JLinkedList jonasMDList = null; 108 109 112 private String xmlContent = ""; 113 114 117 private String jonasXmlContent = ""; 118 119 123 private Map runAsMapping = null; 124 125 135 public DeploymentDesc(ClassLoader classLoader, 136 EjbJar ejbJar, 137 JonasEjbJar jonasEjbJar, 138 Logger l, 139 String fileName) 140 throws DeploymentDescException { 141 142 143 logger = l; 144 145 this.fileName = fileName; 147 148 if (classLoader == null) { 150 throw new DeploymentDescException("DeploymentDesc: Classloader is null"); 151 } 152 153 if (ejbJar.getEnterpriseBeans() == null) { 155 throw new DeploymentDescException("invalid standard deployment descriptor (<enterprise-beans> element missing)"); 156 } 157 specVersion = ejbJar.getVersion(); 159 160 ejbClientJar = ejbJar.getEjbClientJar(); 162 163 asd = ejbJar.getAssemblyDescriptor(); 165 166 runAsMapping = new HashMap (); 168 for (Iterator i = jonasEjbJar.getJonasRunAsMappingList().iterator(); i.hasNext();) { 169 JonasRunAsMapping jonasRunAsMapping = (JonasRunAsMapping) i.next(); 171 String principalName = jonasRunAsMapping.getPrincipalName(); 172 String [] existingRunAsRoleMapping = (String []) runAsMapping.get(principalName); 174 String [] newMappingRoles = null; 175 int r = 0; 176 if (existingRunAsRoleMapping == null) { 177 newMappingRoles = new String [jonasRunAsMapping.getRoleNamesList().size()]; 178 } else { 179 newMappingRoles = new String [jonasRunAsMapping.getRoleNamesList().size() + existingRunAsRoleMapping.length]; 180 System.arraycopy(existingRunAsRoleMapping, 0, newMappingRoles, 0, existingRunAsRoleMapping.length); 182 r = existingRunAsRoleMapping.length; 183 } 184 Iterator itR = jonasRunAsMapping.getRoleNamesList().iterator(); 185 while (itR.hasNext()) { 186 newMappingRoles[r] = (String ) itR.next(); 187 r++; 188 } 189 runAsMapping.put(principalName, newMappingRoles); 190 191 } 192 193 methodPermissionsDescList = new LinkedList (); 195 if (asd != null) { 197 for (Iterator i = asd.getMethodPermissionList().iterator(); i.hasNext();) { 198 MethodPermission methodPermission = (MethodPermission) i.next(); 199 methodPermissionsDescList.add(new MethodPermissionDesc(methodPermission)); 200 } 201 } 202 203 if (asd != null && asd.getExcludeList() != null) { 205 excludeListDesc = new ExcludeListDesc(asd.getExcludeList()); 206 } 207 208 jonasMDList = jonasEjbJar.getJonasMessageDestinationList(); 210 211 HashMap jonasSession = new HashMap (); 213 for (Iterator i = jonasEjbJar.getJonasSessionList().iterator(); i.hasNext();) { 214 JonasSession jSes = (JonasSession) i.next(); 215 jonasSession.put(jSes.getEjbName(), jSes); 216 } 217 218 for (Iterator i = ejbJar.getEnterpriseBeans().getSessionList().iterator(); i.hasNext();) { 220 BeanDesc bd = null; 221 Session ses = (Session) i.next(); 222 JonasSession jSes = (JonasSession) jonasSession.get(ses.getEjbName()); 224 if (jSes == null) { 225 jSes = new JonasSession(); 227 jSes.setEjbName(ses.getEjbName()); 228 } 229 if (ses.getSessionType().equals("Stateful")) { 230 bd = new SessionStatefulDesc(classLoader, ses, asd, jSes, jonasMDList, fileName); 232 } else if (ses.getSessionType().equals("Stateless")) { 233 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 jonasEntity = new HashMap (); 245 for (Iterator i = jonasEjbJar.getJonasEntityList().iterator(); i.hasNext();) { 246 JonasEntity jEnt = (JonasEntity) i.next(); 247 jonasEntity.put(jEnt.getEjbName(), jEnt); 248 } 249 for (Iterator i = ejbJar.getEnterpriseBeans().getEntityList().iterator(); i.hasNext();) { 251 BeanDesc bd = null; 252 Entity ent = (Entity) i.next(); 253 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 bd = new EntityBmpDesc(classLoader, ent, asd, jEnt, jonasMDList, fileName); 261 } else if (ent.getPersistenceType().equals("Container")) { 262 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 277 public Iterator getBeanDescIterator() { 278 return beanDesc.values().iterator(); 279 } 280 281 285 public BeanDesc[] getBeanDesc() { 286 BeanDesc[] ret = new BeanDesc[beanDesc.size()]; 287 int j = 0; 288 for (Iterator i = beanDesc.values().iterator(); i.hasNext(); j++) { 289 ret[j] = (BeanDesc) i.next(); 290 } 291 return ret; 292 } 293 294 299 public String [] getRolesForRunAsPrincipal(String principalName) { 300 return (String []) runAsMapping.get(principalName); 301 } 302 303 308 public BeanDesc getBeanDesc(String ejbName) { 309 return (BeanDesc) beanDesc.get(ejbName); 310 } 311 312 317 public EntityCmp2Desc asn2BeanDesc(String asn) { 318 for (Iterator 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 335 public List getMethodPermissionsDescList() { 336 return methodPermissionsDescList; 337 } 338 339 343 public ExcludeListDesc getExcludeListDesc() { 344 return excludeListDesc; 345 } 346 347 348 353 public BeanDesc getBeanDescWithLocalInterface(String itfLocalName) { 354 for (Iterator 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 370 public boolean getMessageDestination(String mdLink) { 371 MessageDestination md = null; 372 if (asd != null && asd.getMessageDestinationList() != null) { 373 for (Iterator 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 388 public JonasMessageDestination getJonasMessageDestination(String mdLink) { 389 JonasMessageDestination jmd = null; 390 if (jonasMDList != null) { 391 for (Iterator 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 416 protected abstract BeanDesc newEntityBeanDesc(ClassLoader cl, Entity ent, 417 AssemblyDescriptor asd, JonasEntity j, JLinkedList jMDRList) 418 throws DeploymentDescException; 419 420 424 public String getDisplayName() { 425 return displayName; 426 } 427 428 432 public String getEjbClientJar() { 433 return ejbClientJar; 434 } 435 436 437 441 public Logger getLogger() { 442 return logger; 443 } 444 445 449 public void setLogger(Logger logger) { 450 this.logger = logger; 451 } 452 453 457 public String getXmlContent() { 458 return xmlContent; 459 } 460 461 465 public String getJOnASXmlContent() { 466 return jonasXmlContent; 467 } 468 469 473 public String toString() { 474 StringBuffer ret = new StringBuffer (); 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 488 public void setXmlContent(String xmlContent) { 489 this.xmlContent = xmlContent; 490 } 491 492 495 public void setJOnASXmlContent(String jonasXmlContent) { 496 this.jonasXmlContent = jonasXmlContent; 497 } 498 499 } 500 | Popular Tags |