001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.j2ee.deployment.annotation; 019 020 import java.util.ArrayList; 021 import java.util.List; 022 023 import org.apache.geronimo.common.DeploymentException; 024 import org.apache.geronimo.xbeans.javaee.EjbJarType; 025 import org.apache.geronimo.xbeans.javaee.EjbLocalRefType; 026 import org.apache.geronimo.xbeans.javaee.EjbRefType; 027 import org.apache.geronimo.xbeans.javaee.EntityBeanType; 028 import org.apache.geronimo.xbeans.javaee.EnvEntryType; 029 import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType; 030 import org.apache.geronimo.xbeans.javaee.MessageDestinationRefType; 031 import org.apache.geronimo.xbeans.javaee.MessageDrivenBeanType; 032 import org.apache.geronimo.xbeans.javaee.PersistenceContextRefType; 033 import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType; 034 import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType; 035 import org.apache.geronimo.xbeans.javaee.ResourceRefType; 036 import org.apache.geronimo.xbeans.javaee.ServiceRefType; 037 import org.apache.geronimo.xbeans.javaee.SessionBeanType; 038 import org.apache.xmlbeans.XmlObject; 039 040 /** 041 * Wrapper class to encapsulate the EjbJarType class with an interface that the various 042 * AnnotationHelpers can use 043 * <p/> 044 * <p><strong>Remaining ToDo(s):</strong> 045 * <ul> 046 * <li>None 047 * </ul> 048 * 049 * @version $Rev $Date 050 * @since Geronimo 2.0 051 */ 052 public class AnnotatedEjbJar implements AnnotatedApp { 053 054 private final EjbJarType ejbJar; 055 private List<EjbRefType> ambiguousEjbRefs; 056 private AnnotatedApp delegate; 057 058 059 public AnnotatedEjbJar(EjbJarType ejbJar) { 060 this.ejbJar = ejbJar; 061 } 062 063 public void setBean(XmlObject bean) throws DeploymentException { 064 if (bean instanceof EntityBeanType) { 065 delegate = new EntityBean((EntityBeanType) bean); 066 } else if (bean instanceof MessageDrivenBeanType) { 067 delegate = new MessageDriveBean((MessageDrivenBeanType) bean); 068 } else if (bean instanceof SessionBeanType) { 069 delegate = new SessionBean((SessionBeanType) bean); 070 } else { 071 throw new DeploymentException("Unrecognized XmlBeans object: " + bean); 072 } 073 } 074 075 /** 076 * EjbJarType methods used for the @EJB, @EJBs annotations 077 */ 078 public EjbLocalRefType[] getEjbLocalRefArray() { 079 return delegate.getEjbLocalRefArray(); 080 } 081 082 public EjbLocalRefType addNewEjbLocalRef() { 083 return delegate.addNewEjbLocalRef(); 084 } 085 086 public EjbRefType[] getEjbRefArray() { 087 return delegate.getEjbRefArray(); 088 } 089 090 public EjbRefType addNewEjbRef() { 091 return delegate.addNewEjbRef(); 092 } 093 094 095 /** 096 * EjbJarType methods used for the @Resource, @Resources annotations 097 */ 098 public EnvEntryType[] getEnvEntryArray() { 099 return delegate.getEnvEntryArray(); 100 } 101 102 public EnvEntryType addNewEnvEntry() { 103 return delegate.addNewEnvEntry(); 104 } 105 106 public ServiceRefType[] getServiceRefArray() { 107 return delegate.getServiceRefArray(); 108 } 109 110 public ServiceRefType addNewServiceRef() { 111 return delegate.addNewServiceRef(); 112 } 113 114 public ResourceRefType[] getResourceRefArray() { 115 return delegate.getResourceRefArray(); 116 } 117 118 public ResourceRefType addNewResourceRef() { 119 return delegate.addNewResourceRef(); 120 } 121 122 public MessageDestinationRefType[] getMessageDestinationRefArray() { 123 return delegate.getMessageDestinationRefArray(); 124 } 125 126 public MessageDestinationRefType addNewMessageDestinationRef() { 127 return delegate.addNewMessageDestinationRef(); 128 } 129 130 public ResourceEnvRefType[] getResourceEnvRefArray() { 131 return delegate.getResourceEnvRefArray(); 132 } 133 134 public ResourceEnvRefType addNewResourceEnvRef() { 135 return delegate.addNewResourceEnvRef(); 136 } 137 138 public LifecycleCallbackType[] getPostConstructArray() { 139 return delegate.getPostConstructArray(); 140 } 141 142 public LifecycleCallbackType addPostConstruct() { 143 return delegate.addPostConstruct(); 144 } 145 146 public LifecycleCallbackType[] getPreDestroyArray() { 147 return delegate.getPreDestroyArray(); 148 } 149 150 public LifecycleCallbackType addPreDestroy() { 151 return delegate.addPreDestroy(); 152 } 153 154 public PersistenceContextRefType[] getPersistenceContextRefArray() { 155 return delegate.getPersistenceContextRefArray(); 156 } 157 158 public PersistenceContextRefType addNewPersistenceContextRef() { 159 return delegate.addNewPersistenceContextRef(); 160 } 161 162 public PersistenceUnitRefType[] getPersistenceUnitRefArray() { 163 return delegate.getPersistenceUnitRefArray(); 164 } 165 166 public PersistenceUnitRefType addNewPersistenceUnitRef() { 167 return delegate.addNewPersistenceUnitRef(); 168 } 169 170 public String getComponentType() { 171 return null; 172 } 173 174 /** 175 * ejbJar getter 176 * 177 * @return String representation of ejbJar 178 */ 179 public String toString() { 180 return ejbJar.xmlText(); 181 } 182 183 184 public EjbJarType getEjbJar() { 185 return ejbJar; 186 } 187 188 /** 189 * ambiguousRefs getter 190 * <p/> 191 * <p>There is no corresponding setter method. To add a new item to the list do: 192 * <pre> 193 * getAmbiguousEjbRefs().add(ejbRef); 194 * </pre> 195 * 196 * @return ambiguousRefs list 197 */ 198 public List<EjbRefType> getAmbiguousEjbRefs() { 199 if (ambiguousEjbRefs == null) { 200 ambiguousEjbRefs = new ArrayList<EjbRefType>(); 201 } 202 return this.ambiguousEjbRefs; 203 } 204 205 public static class EntityBean implements AnnotatedApp { 206 private final EntityBeanType bean; 207 208 209 public EntityBean(EntityBeanType bean) { 210 this.bean = bean; 211 } 212 213 public EjbLocalRefType[] getEjbLocalRefArray() { 214 return bean.getEjbLocalRefArray(); 215 } 216 217 218 public EjbLocalRefType addNewEjbLocalRef() { 219 return bean.addNewEjbLocalRef(); 220 } 221 222 223 public EjbRefType[] getEjbRefArray() { 224 return bean.getEjbRefArray(); 225 } 226 227 228 public EjbRefType addNewEjbRef() { 229 return bean.addNewEjbRef(); 230 } 231 232 233 public EnvEntryType[] getEnvEntryArray() { 234 return bean.getEnvEntryArray(); 235 } 236 237 238 public EnvEntryType addNewEnvEntry() { 239 return bean.addNewEnvEntry(); 240 } 241 242 243 public ServiceRefType[] getServiceRefArray() { 244 return bean.getServiceRefArray(); 245 } 246 247 248 public ServiceRefType addNewServiceRef() { 249 return bean.addNewServiceRef(); 250 } 251 252 253 public ResourceRefType[] getResourceRefArray() { 254 return bean.getResourceRefArray(); 255 } 256 257 258 public ResourceRefType addNewResourceRef() { 259 return bean.addNewResourceRef(); 260 } 261 262 263 public MessageDestinationRefType[] getMessageDestinationRefArray() { 264 return bean.getMessageDestinationRefArray(); 265 } 266 267 268 public MessageDestinationRefType addNewMessageDestinationRef() { 269 return bean.addNewMessageDestinationRef(); 270 } 271 272 273 public ResourceEnvRefType[] getResourceEnvRefArray() { 274 return bean.getResourceEnvRefArray(); 275 } 276 277 278 public ResourceEnvRefType addNewResourceEnvRef() { 279 return bean.addNewResourceEnvRef(); 280 } 281 282 283 public String toString() { 284 return bean.xmlText(); 285 } 286 287 public List<EjbRefType> getAmbiguousEjbRefs() { 288 throw new AssertionError("don't call this"); 289 } 290 291 292 public LifecycleCallbackType[] getPostConstructArray() { 293 return bean.getPostConstructArray(); 294 } 295 296 297 public LifecycleCallbackType addPostConstruct() { 298 return bean.addNewPostConstruct(); 299 } 300 301 302 public LifecycleCallbackType[] getPreDestroyArray() { 303 return bean.getPreDestroyArray(); 304 } 305 306 307 public LifecycleCallbackType addPreDestroy() { 308 return bean.addNewPreDestroy(); 309 } 310 311 312 public PersistenceContextRefType[] getPersistenceContextRefArray() { 313 return bean.getPersistenceContextRefArray(); 314 } 315 316 317 public PersistenceContextRefType addNewPersistenceContextRef() { 318 return bean.addNewPersistenceContextRef(); 319 } 320 321 322 public PersistenceUnitRefType[] getPersistenceUnitRefArray() { 323 return bean.getPersistenceUnitRefArray(); 324 } 325 326 327 public PersistenceUnitRefType addNewPersistenceUnitRef() { 328 return bean.addNewPersistenceUnitRef(); 329 } 330 331 public String getComponentType() { 332 return bean.getEjbClass().getStringValue().trim(); 333 } 334 } 335 336 public static class MessageDriveBean implements AnnotatedApp { 337 private final MessageDrivenBeanType bean; 338 339 340 public MessageDriveBean(MessageDrivenBeanType bean) { 341 this.bean = bean; 342 } 343 344 345 public EjbLocalRefType[] getEjbLocalRefArray() { 346 return bean.getEjbLocalRefArray(); 347 } 348 349 350 public EjbLocalRefType addNewEjbLocalRef() { 351 return bean.addNewEjbLocalRef(); 352 } 353 354 355 public EjbRefType[] getEjbRefArray() { 356 return bean.getEjbRefArray(); 357 } 358 359 360 public EjbRefType addNewEjbRef() { 361 return bean.addNewEjbRef(); 362 } 363 364 365 public EnvEntryType[] getEnvEntryArray() { 366 return bean.getEnvEntryArray(); 367 } 368 369 370 public EnvEntryType addNewEnvEntry() { 371 return bean.addNewEnvEntry(); 372 } 373 374 375 public ServiceRefType[] getServiceRefArray() { 376 return bean.getServiceRefArray(); 377 } 378 379 380 public ServiceRefType addNewServiceRef() { 381 return bean.addNewServiceRef(); 382 } 383 384 385 public ResourceRefType[] getResourceRefArray() { 386 return bean.getResourceRefArray(); 387 } 388 389 390 public ResourceRefType addNewResourceRef() { 391 return bean.addNewResourceRef(); 392 } 393 394 395 public MessageDestinationRefType[] getMessageDestinationRefArray() { 396 return bean.getMessageDestinationRefArray(); 397 } 398 399 400 public MessageDestinationRefType addNewMessageDestinationRef() { 401 return bean.addNewMessageDestinationRef(); 402 } 403 404 405 public ResourceEnvRefType[] getResourceEnvRefArray() { 406 return bean.getResourceEnvRefArray(); 407 } 408 409 410 public ResourceEnvRefType addNewResourceEnvRef() { 411 return bean.addNewResourceEnvRef(); 412 } 413 414 415 public String toString() { 416 return bean.xmlText(); 417 } 418 419 public List<EjbRefType> getAmbiguousEjbRefs() { 420 throw new AssertionError("don't call this"); 421 } 422 423 424 public LifecycleCallbackType[] getPostConstructArray() { 425 return bean.getPostConstructArray(); 426 } 427 428 429 public LifecycleCallbackType addPostConstruct() { 430 return bean.addNewPostConstruct(); 431 } 432 433 434 public LifecycleCallbackType[] getPreDestroyArray() { 435 return bean.getPreDestroyArray(); 436 } 437 438 439 public LifecycleCallbackType addPreDestroy() { 440 return bean.addNewPreDestroy(); 441 } 442 443 444 public PersistenceContextRefType[] getPersistenceContextRefArray() { 445 return bean.getPersistenceContextRefArray(); 446 } 447 448 449 public PersistenceContextRefType addNewPersistenceContextRef() { 450 return bean.addNewPersistenceContextRef(); 451 } 452 453 454 public PersistenceUnitRefType[] getPersistenceUnitRefArray() { 455 return bean.getPersistenceUnitRefArray(); 456 } 457 458 459 public PersistenceUnitRefType addNewPersistenceUnitRef() { 460 return bean.addNewPersistenceUnitRef(); 461 } 462 463 public String getComponentType() { 464 return bean.getEjbClass().getStringValue().trim(); 465 } 466 } 467 468 public static class SessionBean implements AnnotatedApp { 469 private final SessionBeanType bean; 470 471 472 public SessionBean(SessionBeanType bean) { 473 this.bean = bean; 474 } 475 476 477 public EjbLocalRefType[] getEjbLocalRefArray() { 478 return bean.getEjbLocalRefArray(); 479 } 480 481 482 public EjbLocalRefType addNewEjbLocalRef() { 483 return bean.addNewEjbLocalRef(); 484 } 485 486 487 public EjbRefType[] getEjbRefArray() { 488 return bean.getEjbRefArray(); 489 } 490 491 492 public EjbRefType addNewEjbRef() { 493 return bean.addNewEjbRef(); 494 } 495 496 497 public EnvEntryType[] getEnvEntryArray() { 498 return bean.getEnvEntryArray(); 499 } 500 501 502 public EnvEntryType addNewEnvEntry() { 503 return bean.addNewEnvEntry(); 504 } 505 506 507 public ServiceRefType[] getServiceRefArray() { 508 return bean.getServiceRefArray(); 509 } 510 511 512 public ServiceRefType addNewServiceRef() { 513 return bean.addNewServiceRef(); 514 } 515 516 517 public ResourceRefType[] getResourceRefArray() { 518 return bean.getResourceRefArray(); 519 } 520 521 522 public ResourceRefType addNewResourceRef() { 523 return bean.addNewResourceRef(); 524 } 525 526 527 public MessageDestinationRefType[] getMessageDestinationRefArray() { 528 return bean.getMessageDestinationRefArray(); 529 } 530 531 532 public MessageDestinationRefType addNewMessageDestinationRef() { 533 return bean.addNewMessageDestinationRef(); 534 } 535 536 537 public ResourceEnvRefType[] getResourceEnvRefArray() { 538 return bean.getResourceEnvRefArray(); 539 } 540 541 542 public ResourceEnvRefType addNewResourceEnvRef() { 543 return bean.addNewResourceEnvRef(); 544 } 545 546 547 public String toString() { 548 return bean.xmlText(); 549 } 550 551 public List<EjbRefType> getAmbiguousEjbRefs() { 552 throw new AssertionError("don't call this"); 553 } 554 555 556 public LifecycleCallbackType[] getPostConstructArray() { 557 return bean.getPostConstructArray(); 558 } 559 560 561 public LifecycleCallbackType addPostConstruct() { 562 return bean.addNewPostConstruct(); 563 } 564 565 566 public LifecycleCallbackType[] getPreDestroyArray() { 567 return bean.getPreDestroyArray(); 568 } 569 570 571 public LifecycleCallbackType addPreDestroy() { 572 return bean.addNewPreDestroy(); 573 } 574 575 576 public PersistenceContextRefType[] getPersistenceContextRefArray() { 577 return bean.getPersistenceContextRefArray(); 578 } 579 580 581 public PersistenceContextRefType addNewPersistenceContextRef() { 582 return bean.addNewPersistenceContextRef(); 583 } 584 585 586 public PersistenceUnitRefType[] getPersistenceUnitRefArray() { 587 return bean.getPersistenceUnitRefArray(); 588 } 589 590 591 public PersistenceUnitRefType addNewPersistenceUnitRef() { 592 return bean.addNewPersistenceUnitRef(); 593 } 594 595 public String getComponentType() { 596 return bean.getEjbClass().getStringValue().trim(); 597 } 598 } 599 }