1 /* 2 * Copyright 2002-2009 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 * http://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 17 package org.springframework.aop.aspectj.annotation; 18 19 import org.springframework.aop.aspectj.SimpleAspectInstanceFactory; 20 import org.springframework.core.Ordered; 21 import org.springframework.core.annotation.Order; 22 23 /** 24 * Implementation of {@link MetadataAwareAspectInstanceFactory} that 25 * creates a new instance of the specified aspect class for every 26 * {@link #getAspectInstance()} call. 27 * 28 * @author Juergen Hoeller 29 * @since 2.0.4 30 */ 31 public class SimpleMetadataAwareAspectInstanceFactory extends SimpleAspectInstanceFactory 32 implements MetadataAwareAspectInstanceFactory { 33 34 private final AspectMetadata metadata; 35 36 37 /** 38 * Create a new SimpleMetadataAwareAspectInstanceFactory for the given aspect class. 39 * @param aspectClass the aspect class 40 * @param aspectName the aspect name 41 */ SimpleMetadataAwareAspectInstanceFactory(Class aspectClass, String aspectName)42 public SimpleMetadataAwareAspectInstanceFactory(Class aspectClass, String aspectName) { 43 super(aspectClass); 44 this.metadata = new AspectMetadata(aspectClass, aspectName); 45 } 46 47 getAspectMetadata()48 public final AspectMetadata getAspectMetadata() { 49 return this.metadata; 50 } 51 52 /** 53 * Determine a fallback order for the case that the aspect instance 54 * does not express an instance-specific order through implementing 55 * the {@link org.springframework.core.Ordered} interface. 56 * <p>The default implementation simply returns <code>Ordered.LOWEST_PRECEDENCE</code>. 57 * @param aspectClass the aspect class 58 */ 59 @Override getOrderForAspectClass(Class<?> aspectClass)60 protected int getOrderForAspectClass(Class<?> aspectClass) { 61 Order order = aspectClass.getAnnotation(Order.class); 62 if (order != null) { 63 return order.value(); 64 } 65 return Ordered.LOWEST_PRECEDENCE; 66 } 67 68 } 69