KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > aspectj > annotation > SingletonMetadataAwareAspectInstanceFactory


1 /*
2  * Copyright 2002-2006 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.SingletonAspectInstanceFactory;
20 import org.springframework.core.Ordered;
21 import org.springframework.core.annotation.Order;
22
23 /**
24  * Implementation of AspectInstanceFactory that wraps a singleton instance.
25  *
26  * @author Rod Johnson
27  * @author Juergen Hoeller
28  * @since 2.0
29  */

30 public class SingletonMetadataAwareAspectInstanceFactory extends SingletonAspectInstanceFactory
31         implements MetadataAwareAspectInstanceFactory {
32     
33     private final AspectMetadata metadata;
34
35
36     /**
37      * Create a new SingletonMetadataAwareAspectInstanceFactory for the given aspect.
38      * @param aspectInstance the singleton aspect instance
39      * @param aspectName the name of the aspect
40      */

41     public SingletonMetadataAwareAspectInstanceFactory(Object JavaDoc aspectInstance, String JavaDoc aspectName) {
42         super(aspectInstance);
43         this.metadata = new AspectMetadata(aspectInstance.getClass(), aspectName);
44     }
45
46
47     public AspectMetadata getAspectMetadata() {
48         return this.metadata;
49     }
50
51     /**
52      * Check whether the aspect class carries an
53      * {@link org.springframework.core.annotation.Order} annotation,
54      * falling back to <code>Ordered.LOWEST_PRECEDENCE</code>.
55      * @see org.springframework.core.annotation.Order
56      */

57     protected int getOrderForAspectClass(Class JavaDoc aspectClass) {
58         Order order = (Order) aspectClass.getAnnotation(Order.class);
59         if (order != null) {
60             return order.value();
61         }
62         return Ordered.LOWEST_PRECEDENCE;
63     }
64
65 }
66
Popular Tags