KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > aspectj > SingletonAspectInstanceFactory


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;
18
19 import org.springframework.core.Ordered;
20 import org.springframework.util.Assert;
21
22 /**
23  * Simple implementation of AspectInstanceFactory backed by a singleton object.
24  *
25  * @author Rod Johnson
26  * @author Juergen Hoeller
27  * @since 2.0
28  */

29 public class SingletonAspectInstanceFactory implements AspectInstanceFactory {
30     
31     private final Object JavaDoc aspectInstance;
32
33
34     /**
35      * Create a new SingletonAspectInstanceFactory for the given aspect instance.
36      * @param aspectInstance the singleton aspect instance
37      */

38     public SingletonAspectInstanceFactory(Object JavaDoc aspectInstance) {
39         Assert.notNull(aspectInstance, "Aspect instance must not be null");
40         this.aspectInstance = aspectInstance;
41     }
42
43
44     public final Object JavaDoc getAspectInstance() {
45         return this.aspectInstance;
46     }
47
48     /**
49      * Determine the order for this factory's aspect instance,
50      * either an instance-specific order expressed through implementing
51      * the {@link org.springframework.core.Ordered} interface,
52      * or a fallback order.
53      * @see org.springframework.core.Ordered
54      * @see #getOrderForAspectClass
55      */

56     public int getOrder() {
57         if (this.aspectInstance instanceof Ordered) {
58             return ((Ordered) this.aspectInstance).getOrder();
59         }
60         return getOrderForAspectClass(this.aspectInstance.getClass());
61     }
62
63     /**
64      * Determine a fallback order for the case that the aspect instance
65      * does not express an instance-specific order through implementing
66      * the {@link org.springframework.core.Ordered} interface.
67      * <p>The default implementation simply returns <code>Ordered.LOWEST_PRECEDENCE</code>.
68      * @param aspectClass the aspect class
69      */

70     protected int getOrderForAspectClass(Class JavaDoc aspectClass) {
71         return Ordered.LOWEST_PRECEDENCE;
72     }
73
74 }
75
Popular Tags