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.SingletonAspectInstanceFactory;
20: import org.springframework.core.Ordered;
21: import org.springframework.core.annotation.Order;
22:
23: /**
24: * Implementation of {@link MetadataAwareAspectInstanceFactory} that is backed
25: * by a specified singleton object, returning the same instance for every
26: * {@link #getAspectInstance()} call.
27: *
28: * @author Rod Johnson
29: * @author Juergen Hoeller
30: * @since 2.0
31: * @see SimpleMetadataAwareAspectInstanceFactory
32: */
33: public class SingletonMetadataAwareAspectInstanceFactory extends
34: SingletonAspectInstanceFactory implements
35: MetadataAwareAspectInstanceFactory {
36:
37: private final AspectMetadata metadata;
38:
39: /**
40: * Create a new SingletonMetadataAwareAspectInstanceFactory for the given aspect.
41: * @param aspectInstance the singleton aspect instance
42: * @param aspectName the name of the aspect
43: */
44: public SingletonMetadataAwareAspectInstanceFactory(
45: Object aspectInstance, String aspectName) {
46: super (aspectInstance);
47: this .metadata = new AspectMetadata(aspectInstance.getClass(),
48: aspectName);
49: }
50:
51: public final AspectMetadata getAspectMetadata() {
52: return this .metadata;
53: }
54:
55: /**
56: * Check whether the aspect class carries an
57: * {@link org.springframework.core.annotation.Order} annotation,
58: * falling back to <code>Ordered.LOWEST_PRECEDENCE</code>.
59: * @see org.springframework.core.annotation.Order
60: */
61: protected int getOrderForAspectClass(Class aspectClass) {
62: Order order = (Order) aspectClass.getAnnotation(Order.class);
63: if (order != null) {
64: return order.value();
65: }
66: return Ordered.LOWEST_PRECEDENCE;
67: }
68:
69: }
|