You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractDependencyInjectionAspect.aj 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2002-2013 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.beans.factory.aspectj;
  17. import org.aspectj.lang.annotation.SuppressAjWarnings;
  18. import org.aspectj.lang.annotation.control.CodeGenerationHint;
  19. /**
  20. * Abstract base aspect that can perform Dependency
  21. * Injection on objects, however they may be created.
  22. *
  23. * @author Ramnivas Laddad
  24. * @since 2.5.2
  25. */
  26. public abstract aspect AbstractDependencyInjectionAspect {
  27. /**
  28. * Select construction join points for objects to inject dependencies
  29. */
  30. public abstract pointcut beanConstruction(Object bean);
  31. /**
  32. * Select deserialization join points for objects to inject dependencies
  33. */
  34. public abstract pointcut beanDeserialization(Object bean);
  35. /**
  36. * Select join points in a configurable bean
  37. */
  38. public abstract pointcut inConfigurableBean();
  39. /**
  40. * Select join points in beans to be configured prior to construction?
  41. * By default, use post-construction injection matching the default in the Configurable annotation.
  42. */
  43. public pointcut preConstructionConfiguration() : if(false);
  44. /**
  45. * Select the most-specific initialization join point
  46. * (most concrete class) for the initialization of an instance.
  47. */
  48. @CodeGenerationHint(ifNameSuffix="6f1")
  49. public pointcut mostSpecificSubTypeConstruction() :
  50. if(thisJoinPoint.getSignature().getDeclaringType() == thisJoinPoint.getThis().getClass());
  51. /**
  52. * Select least specific super type that is marked for DI (so that injection occurs only once with pre-construction inejection
  53. */
  54. public abstract pointcut leastSpecificSuperTypeConstruction();
  55. /**
  56. * Configure the bean
  57. */
  58. public abstract void configureBean(Object bean);
  59. private pointcut preConstructionCondition() :
  60. leastSpecificSuperTypeConstruction() && preConstructionConfiguration();
  61. private pointcut postConstructionCondition() :
  62. mostSpecificSubTypeConstruction() && !preConstructionConfiguration();
  63. /**
  64. * Pre-construction configuration.
  65. */
  66. @SuppressAjWarnings("adviceDidNotMatch")
  67. before(Object bean) :
  68. beanConstruction(bean) && preConstructionCondition() && inConfigurableBean() {
  69. configureBean(bean);
  70. }
  71. /**
  72. * Post-construction configuration.
  73. */
  74. @SuppressAjWarnings("adviceDidNotMatch")
  75. after(Object bean) returning :
  76. beanConstruction(bean) && postConstructionCondition() && inConfigurableBean() {
  77. configureBean(bean);
  78. }
  79. /**
  80. * Post-deserialization configuration.
  81. */
  82. @SuppressAjWarnings("adviceDidNotMatch")
  83. after(Object bean) returning :
  84. beanDeserialization(bean) && inConfigurableBean() {
  85. configureBean(bean);
  86. }
  87. }