1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.introspection;
21
22 import java.lang.reflect.Method;
23
24
25
26
27
28
29
30
31
32 public class MethodInvocationSettings {
33 private Method method=null;
34 private Object[] parameters=null;
35 private Object object=null;
36 private boolean staticMethod=false;
37
38
39
40
41 public MethodInvocationSettings(Method method){
42 super();
43 setMethod(method);
44 }
45 private boolean checkObject(){
46 if (isStaticMethod()) return true;
47 if (method.getDeclaringClass().isAssignableFrom(object.getClass())) return true;
48 return false;
49 }
50 private boolean checkParameters(){
51 if (method==null) return false;
52 Class[] paramTypes=method.getParameterTypes();
53 if (paramTypes.length!=parameters.length) return false;
54 for (int i=0; i<parameters.length;i++){
55 if (!paramTypes[i].isAssignableFrom(parameters[i].getClass())) return(false);
56 }
57 return true;
58 }
59
60
61
62
63 public Method getMethod() {
64 return method;
65 }
66
67
68
69
70 public Object getObject() {
71 return object;
72 }
73
74
75
76
77 public Object[] getParameters() {
78 return parameters;
79 }
80
81
82
83
84 public boolean isStaticMethod() {
85 return staticMethod;
86 }
87
88
89
90
91
92 public void setMethod(Method method){
93 this.method=method;
94 staticMethod=java.lang.reflect.Modifier.isStatic(method.getModifiers());
95 }
96
97
98
99
100 public void setObject(Object object) {
101 this.object = object;
102 }
103
104
105
106
107 public void setParameters(Object[] parameters) {
108 this.parameters = parameters;
109 }
110
111
112
113 public String toString(){
114 String className=method.getClass().getName();
115 StringBuffer b=new StringBuffer(className.substring(className.lastIndexOf(".")));
116 b.append(".");
117 b.append(method.getName());
118 b.append("(");
119 b.append(")");
120 if (staticMethod) b.append("<S>");
121 return b.toString();
122 }
123 }