KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > target > SingletonTargetSource


1 /*
2  * Copyright 2002-2007 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.target;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.springframework.aop.TargetSource;
22 import org.springframework.util.Assert;
23 import org.springframework.util.ObjectUtils;
24
25 /**
26  * Implementation of the {@link org.springframework.aop.TargetSource} interface
27  * that holds a given object. This is the default implementation of the TargetSource
28  * interface, as used by the Spring AOP framework. There is usually no need to
29  * create objects of this class in application code.
30  *
31  * <p>This class is serializable. However, the actual serializability of a
32  * SingletonTargetSource will depend on whether the target is serializable.
33  *
34  * @author Rod Johnson
35  * @author Juergen Hoeller
36  * @see org.springframework.aop.framework.AdvisedSupport#setTarget(Object)
37  */

38 public class SingletonTargetSource implements TargetSource, Serializable JavaDoc {
39
40     /** use serialVersionUID from Spring 1.2 for interoperability */
41     private static final long serialVersionUID = 9031246629662423738L;
42
43
44     /** Target cached and invoked using reflection */
45     private final Object JavaDoc target;
46
47
48     /**
49      * Create a new SingletonTargetSource for the given target.
50      * @param target the target object
51      */

52     public SingletonTargetSource(Object JavaDoc target) {
53         Assert.notNull(target, "Target object must not be null");
54         this.target = target;
55     }
56
57
58     public Class JavaDoc getTargetClass() {
59         return this.target.getClass();
60     }
61     
62     public Object JavaDoc getTarget() {
63         return this.target;
64     }
65     
66     public void releaseTarget(Object JavaDoc target) {
67         // nothing to do
68
}
69
70     public boolean isStatic() {
71         return true;
72     }
73
74
75     /**
76      * Two invoker interceptors are equal if they have the same target or if the
77      * targets or the targets are equal.
78      */

79     public boolean equals(Object JavaDoc other) {
80         if (this == other) {
81             return true;
82         }
83         if (!(other instanceof SingletonTargetSource)) {
84             return false;
85         }
86         SingletonTargetSource otherTargetSource = (SingletonTargetSource) other;
87         return this.target.equals(otherTargetSource.target);
88     }
89
90     /**
91      * SingletonTargetSource uses the hash code of the target object.
92      */

93     public int hashCode() {
94         return this.target.hashCode();
95     }
96
97     public String JavaDoc toString() {
98         return "SingletonTargetSource for target object [" + ObjectUtils.identityToString(this.target) + "]";
99     }
100
101 }
102
Popular Tags