1 26 27 package org.objectweb.jonas_lib.deployment.api; 28 29 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 import java.util.Set ; 35 import java.util.Vector ; 36 37 import org.objectweb.jonas_lib.deployment.xml.EjbLocalRef; 38 import org.objectweb.jonas_lib.deployment.xml.EjbRef; 39 import org.objectweb.jonas_lib.deployment.xml.EnvEntry; 40 import org.objectweb.jonas_lib.deployment.xml.JndiEnvRefsGroupXml; 41 import org.objectweb.jonas_lib.deployment.xml.JonasEjbRef; 42 import org.objectweb.jonas_lib.deployment.xml.JonasJndiEnvRefsGroupXml; 43 import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestinationRef; 44 import org.objectweb.jonas_lib.deployment.xml.JonasResource; 45 import org.objectweb.jonas_lib.deployment.xml.JonasResourceEnv; 46 import org.objectweb.jonas_lib.deployment.xml.JonasServiceRef; 47 import org.objectweb.jonas_lib.deployment.xml.MessageDestinationRef; 48 import org.objectweb.jonas_lib.deployment.xml.ResourceEnvRef; 49 import org.objectweb.jonas_lib.deployment.xml.ResourceRef; 50 import org.objectweb.jonas_lib.deployment.xml.ServiceRef; 51 52 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 53 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException; 54 55 import org.objectweb.jonas.common.Log; 56 57 import org.objectweb.util.monolog.api.BasicLevel; 58 import org.objectweb.util.monolog.api.Logger; 59 60 72 73 public abstract class JndiEnvRefsGroupDesc extends DescriptionGroupDesc implements JndiEnvRefsGroup { 74 75 78 private Vector resourceEnvRefs = new Vector (); 79 80 83 private Vector resourceRefs = new Vector (); 84 85 88 private Vector envEntries = new Vector (); 89 90 93 private Vector serviceRefs = new Vector (); 94 95 98 private Vector ejbRefs = new Vector (); 99 100 103 private Vector ejbLocalRefs = new Vector (); 104 105 108 private Vector messageDestinationRefs = new Vector (); 109 110 113 private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX); 114 115 126 protected JndiEnvRefsGroupDesc(ClassLoader classLoader, 127 JndiEnvRefsGroupXml app, 128 JonasJndiEnvRefsGroupXml jonasApp, 129 String fileName) 130 throws DeploymentDescException { 131 132 if (classLoader == null) { 134 throw new DeploymentDescException("Classloader is null"); 135 } 136 displayName = null; 138 if (app.getDisplayName() != null) { 139 displayName = app.getDisplayName(); 140 } 141 142 processResourceEnvRef(classLoader, app, jonasApp); 144 145 processResourceRef(classLoader, app, jonasApp); 147 148 processEnvEntry(app); 150 151 processEjbRef(app, jonasApp); 153 154 processEjbLocalRef(app); 156 157 processServiceRef(classLoader, app, jonasApp, fileName); 159 160 processMessageDestinationRef(app, jonasApp); 162 163 164 } 165 166 171 private void processEnvEntry(JndiEnvRefsGroupXml app) throws DeploymentDescException { 172 for (Iterator i = app.getEnvEntryList().iterator(); i.hasNext();) { 174 EnvEntryDesc envEntryDesc = new EnvEntryDesc((EnvEntry) i.next()); 175 envEntries.addElement(envEntryDesc); 176 } 177 } 178 179 186 private void processMessageDestinationRef(JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException { 187 List messageDestinationRefList = app.getMessageDestinationRefList(); 188 List jonasMessageDestinationRefList = jonasApp.getJonasMessageDestinationRefList(); 189 190 191 HashMap messageDestinationRef = new HashMap (); 192 for (Iterator i = jonasMessageDestinationRefList.iterator(); i.hasNext();) { 193 JonasMessageDestinationRef jonasMessageDestinationRef = (JonasMessageDestinationRef) i.next(); 194 String mdrName = jonasMessageDestinationRef.getMessageDestinationRefName(); 195 boolean findMDRef = false; 196 for (Iterator j = messageDestinationRefList.iterator(); j.hasNext() && !findMDRef;) { 197 MessageDestinationRef mdRef = (MessageDestinationRef) j.next(); 198 if (mdrName.equals(mdRef.getMessageDestinationRefName())) { 199 findMDRef = true; 200 } 201 } 202 if (!findMDRef) { 203 throw new DeploymentDescException("message-destination-ref missing for jonas-message-destination-ref " + mdrName); 204 } 205 messageDestinationRef.put(mdrName, jonasMessageDestinationRef); 206 } 207 for (Iterator i = messageDestinationRefList.iterator(); i.hasNext();) { 208 MessageDestinationRef mdRef = (MessageDestinationRef) i.next(); 209 String mdrName = mdRef.getMessageDestinationRefName(); 210 JonasMessageDestinationRef jonasMessageDestinationRef = (JonasMessageDestinationRef) messageDestinationRef.get(mdrName); 211 if (jonasMessageDestinationRef == null) { 212 if ((mdRef.getMessageDestinationLink() == null)) { 214 throw new DeploymentDescException("message-destination-link missing for message-destination-ref-name " + mdrName); 216 } } 217 messageDestinationRefs.addElement(new MessageDestinationRefDesc(mdRef, jonasMessageDestinationRef)); 218 } 219 } 220 221 230 private void processServiceRef(ClassLoader classLoader, JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp, String fileName) throws WSDeploymentDescException { 231 Map links = linksSR2JSR(app, jonasApp); 232 List serviceRefList = app.getServiceRefList(); 233 for (Iterator i = serviceRefList.iterator(); i.hasNext();) { 234 ServiceRef serviceRef = ((ServiceRef) i.next()); 235 JonasServiceRef jsr = (JonasServiceRef) links.get(serviceRef.getServiceRefName()); 236 serviceRefs.addElement(new ServiceRefDesc(classLoader, serviceRef, jsr, fileName)); 237 } 238 } 239 240 245 private void processEjbLocalRef(JndiEnvRefsGroupXml app) throws DeploymentDescException { 246 List ejbLocalRefList = app.getEjbLocalRefList(); 247 for (Iterator i = ejbLocalRefList.iterator(); i.hasNext();) { 248 EjbLocalRef ejbLocalRef = (EjbLocalRef) i.next(); 249 if ((ejbLocalRef.getEjbLink() == null)) { 250 throw new DeploymentDescException("ejb-link missing for ejb-ref-name " + ejbLocalRef.getEjbRefName()); 251 } 252 ejbLocalRefs.addElement(new EjbLocalRefDesc(ejbLocalRef)); 253 } 254 } 255 256 263 private void processEjbRef(JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException { 264 List ejbRefList = app.getEjbRefList(); 265 List jonasEjbRefList = jonasApp.getJonasEjbRefList(); 266 267 HashMap ejbRef = new HashMap (); 268 for (Iterator i = jonasEjbRefList.iterator(); i.hasNext();) { 269 JonasEjbRef jonasEjbRef = (JonasEjbRef) i.next(); 270 String brName = jonasEjbRef.getEjbRefName(); 271 boolean findBRef = false; 272 for (Iterator j = ejbRefList.iterator(); j.hasNext() && !findBRef;) { 273 EjbRef eRef = (EjbRef) j.next(); 274 if (brName.equals(eRef.getEjbRefName())) { 275 findBRef = true; 276 } 277 } 278 if (!findBRef) { 279 throw new DeploymentDescException("ejb-ref missing for jonas-ejb-ref " + brName); 280 } 281 ejbRef.put(brName, jonasEjbRef); 282 } 283 for (Iterator i = ejbRefList.iterator(); i.hasNext();) { 284 EjbRef eRef = (EjbRef) i.next(); 285 String brName = eRef.getEjbRefName(); 286 JonasEjbRef jonasEjbRef = (JonasEjbRef) ejbRef.get(brName); 287 if (jonasEjbRef == null) { 288 if ((eRef.getEjbLink() == null)) { 290 throw new DeploymentDescException("ejb-link missing for ejb-ref-name " + brName); 292 } 293 } 294 ejbRefs.addElement(new EjbRefDesc(eRef, jonasEjbRef)); 295 } 296 } 297 298 306 private void processResourceRef(ClassLoader classLoader, JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException { 307 List resourceRefList = app.getResourceRefList(); 308 List jonasResourceList = jonasApp.getJonasResourceList(); 309 HashMap resource = new HashMap (); 310 for (Iterator i = jonasResourceList.iterator(); i.hasNext();) { 311 JonasResource jonasResource = ((JonasResource) i.next()); 312 String rName = jonasResource.getResRefName(); 313 boolean findResRef = false; 314 for (Iterator j = resourceRefList.iterator(); j.hasNext() && !findResRef;) { 315 if (rName.equals(((ResourceRef) j.next()).getResRefName())) { 316 findResRef = true; 317 } 318 } 319 if (!findResRef) { 320 throw new DeploymentDescException("resource-ref missing for jonas-resource " + rName); 321 } 322 resource.put(rName, jonasResource); 323 } 324 325 for (Iterator i = resourceRefList.iterator(); i.hasNext();) { 326 ResourceRef resourceRef = ((ResourceRef) i.next()); 327 String rName = resourceRef.getResRefName(); 328 if (!resource.containsKey(rName)) { 329 throw new DeploymentDescException("jonas-resource missing for res-ref-name " + rName); 330 } 331 resourceRefs.addElement(new ResourceRefDesc(classLoader, resourceRef, (JonasResource) resource.get(rName))); 332 } 333 } 334 335 343 private void processResourceEnvRef(ClassLoader classLoader, JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException { 344 List resourceEnvRefList = app.getResourceEnvRefList(); 345 List jonasResourceEnvList = jonasApp.getJonasResourceEnvList(); 346 HashMap resourceEnv = new HashMap (); 347 for (Iterator i = jonasResourceEnvList.iterator(); i.hasNext();) { 348 JonasResourceEnv jonasResourceEnv = (JonasResourceEnv) i.next(); 349 String rName = jonasResourceEnv.getResourceEnvRefName(); 350 boolean findResRef = false; 351 for (Iterator j = resourceEnvRefList.iterator(); j.hasNext() && !findResRef;) { 352 ResourceEnvRef resourceEnvRef = (ResourceEnvRef) j.next(); 353 if (rName.equals(resourceEnvRef.getResourceEnvRefName())) { 354 findResRef = true; 355 } 356 } 357 if (!findResRef) { 358 throw new DeploymentDescException("resource-env-ref missing for jonas-resource-env " + rName); 359 } 360 resourceEnv.put(rName, jonasResourceEnv); 361 } 362 for (Iterator i = resourceEnvRefList.iterator(); i.hasNext();) { 363 ResourceEnvRef resourceEnvRef = (ResourceEnvRef) i.next(); 364 String rName = resourceEnvRef.getResourceEnvRefName(); 365 if (!resourceEnv.containsKey(rName)) { 366 throw new DeploymentDescException("jonas-resource-env missing for resource-env-ref-name " + rName); 367 } 368 resourceEnvRefs.addElement(new ResourceEnvRefDesc(classLoader, resourceEnvRef, 369 (JonasResourceEnv) resourceEnv.get(rName))); 370 } 371 } 372 373 378 private Map linksSR2JSR(JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) { 379 Map res = new HashMap (); 380 for (Iterator i = app.getServiceRefList().iterator(); i.hasNext();) { 382 ServiceRef sr = (ServiceRef) i.next(); 383 res.put(sr.getServiceRefName(), null); 384 } 385 if (jonasApp != null) { 387 388 Set keys = res.keySet(); 390 391 for (Iterator i = jonasApp.getJonasServiceRefList().iterator(); i.hasNext();) { 393 JonasServiceRef jsr = (JonasServiceRef) i.next(); 394 String srName = jsr.getServiceRefName(); 395 396 if (keys.contains(srName)) { 397 res.put(srName, jsr); 399 } else { 400 String err = "jonas-service-ref '" + srName + "' is not linked to any service-ref. It will be ignored."; logger.log(BasicLevel.WARN, err); 402 } 403 } 404 } 405 return res; 406 } 407 408 413 public ResourceEnvRefDesc[] getResourceEnvRefDesc() { 414 ResourceEnvRefDesc[] ret = new ResourceEnvRefDesc[resourceEnvRefs.size()]; 415 resourceEnvRefs.copyInto(ret); 416 return ret; 417 } 418 419 424 public ResourceRefDesc[] getResourceRefDesc() { 425 ResourceRefDesc[] ret = new ResourceRefDesc[resourceRefs.size()]; 426 resourceRefs.copyInto(ret); 427 return ret; 428 } 429 430 435 public EnvEntryDesc[] getEnvEntryDesc() { 436 EnvEntryDesc[] ret = new EnvEntryDesc[envEntries.size()]; 437 envEntries.copyInto(ret); 438 return ret; 439 } 440 441 446 public EjbRefDesc[] getEjbRefDesc() { 447 EjbRefDesc[] ret = new EjbRefDesc[ejbRefs.size()]; 448 ejbRefs.copyInto(ret); 449 return ret; 450 } 451 452 457 public EjbLocalRefDesc[] getEjbLocalRefDesc() { 458 EjbLocalRefDesc[] ret = new EjbLocalRefDesc[ejbLocalRefs.size()]; 459 ejbLocalRefs.copyInto(ret); 460 return ret; 461 } 462 463 468 public ServiceRefDesc[] getServiceRefDesc() { 469 ServiceRefDesc[] ret = new ServiceRefDesc[serviceRefs.size()]; 470 serviceRefs.copyInto(ret); 471 return ret; 472 } 473 474 478 public MessageDestinationRefDesc[] getMessageDestinationRefDesc() { 479 MessageDestinationRefDesc[] ret = new MessageDestinationRefDesc[messageDestinationRefs.size()]; 480 messageDestinationRefs.copyInto(ret); 481 return ret; 482 } 483 } 484 | Popular Tags |