-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathAnimalFactory.java
More file actions
61 lines (56 loc) · 1.25 KB
/
Copy pathAnimalFactory.java
File metadata and controls
61 lines (56 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package proxy;
import java.lang.reflect.Proxy;
import proxy.annon.AnnoInjection;
import proxy.imp.AOPMethod;
public class AnimalFactory {
/***
* 获取对象方法
* @param obj
* @return
*/
private static Object getAnimalBase(Object obj,AOPMethod method){
//获取代理对象
return Proxy.newProxyInstance(obj.getClass().getClassLoader(),
obj.getClass().getInterfaces(),
new AOPHandle(AnnoInjection.getBean(obj),method));
}
/***
* 获取对象方法
* @param obj
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAnimal(Object obj,AOPMethod aopMethod){
return (T) getAnimalBase(obj,aopMethod);
}
/***
* 获取对象方法
* @param className
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAnimal(String className,AOPMethod method){
Object obj=null;
try {
obj= getAnimalBase(Class.forName(className).newInstance(),method);
} catch (Exception e) {
e.printStackTrace();
}
return (T)obj;
}
/***
* 获取对象方法
* @param clz
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAnimal(Class<?> clz,AOPMethod method){
Object obj=null;
try {
obj= getAnimalBase(clz.newInstance(),method);
} catch (Exception e) {
e.printStackTrace();
}
return (T)obj;
}
}