01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
32: SimpleAspectInstanceFactory implements
33: MetadataAwareAspectInstanceFactory {
34:
35: private final AspectMetadata metadata;
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: */
42: public SimpleMetadataAwareAspectInstanceFactory(Class aspectClass,
43: String aspectName) {
44: super (aspectClass);
45: this .metadata = new AspectMetadata(aspectClass, aspectName);
46: }
47:
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: protected int getOrderForAspectClass(Class aspectClass) {
60: Order order = (Order) aspectClass.getAnnotation(Order.class);
61: if (order != null) {
62: return order.value();
63: }
64: return Ordered.LOWEST_PRECEDENCE;
65: }
66:
67: }
|