1 16 17 package org.springframework.aop.aspectj.annotation; 18 19 import org.springframework.beans.factory.BeanFactory; 20 import org.springframework.core.Ordered; 21 import org.springframework.core.annotation.Order; 22 23 38 public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInstanceFactory { 39 40 private final BeanFactory beanFactory; 41 42 private final String name; 43 44 private final AspectMetadata aspectMetadata; 45 46 47 54 public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) { 55 this(beanFactory, name, beanFactory.getType(name)); 56 } 57 58 66 public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class type) { 67 this.beanFactory = beanFactory; 68 this.name = name; 69 this.aspectMetadata = new AspectMetadata(type, name); 70 } 71 72 73 public Object getAspectInstance() { 74 return this.beanFactory.getBean(this.name); 75 } 76 77 public AspectMetadata getAspectMetadata() { 78 return this.aspectMetadata; 79 } 80 81 91 public int getOrder() { 92 Class type = this.beanFactory.getType(this.name); 93 if (type != null) { 94 if (Ordered.class.isAssignableFrom(type) && this.beanFactory.isSingleton(this.name)) { 95 return ((Ordered) this.beanFactory.getBean(this.name)).getOrder(); 96 } 97 Order order = (Order) type.getAnnotation(Order.class); 98 if (order != null) { 99 return order.value(); 100 } 101 } 102 return Ordered.LOWEST_PRECEDENCE; 103 } 104 105 106 @Override 107 public String toString() { 108 return getClass().getSimpleName() + ": bean name '" + this.name + "'"; 109 } 110 111 } 112 | Popular Tags |