1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.fulcrum.yaafi.interceptor.util;
21
22 import java.lang.reflect.Method;
23
24
25
26
27
28
29 public class MethodToStringBuilderImpl implements InterceptorToStringBuilder
30 {
31
32 public static final int INCLUDE_RETURNTYPE = 0x1;
33
34
35 private static int defaultMode = 0x01;
36
37
38 private int mode;
39
40
41 private static final int BUF_SIZE = 512;
42
43
44 private Method method;
45
46
47
48
49 public MethodToStringBuilderImpl()
50 {
51 this.mode = MethodToStringBuilderImpl.defaultMode;
52 }
53
54
55
56
57
58
59 public MethodToStringBuilderImpl(Method method)
60 {
61 this.method = method;
62 this.mode = MethodToStringBuilderImpl.defaultMode;
63 }
64
65
66
67
68
69
70
71 public MethodToStringBuilderImpl(Method method, int mode)
72 {
73 this.method = method;
74 this.mode = mode;
75 }
76
77
78
79
80 public void setMaxArgLength(int maxArgLength)
81 {
82
83 }
84
85
86
87
88 public void setMode(int mode)
89 {
90 this.mode = mode;
91 }
92
93
94
95
96 public void setTarget(Object target)
97 {
98 this.method = (Method) target;
99 }
100
101
102
103
104 public String toString()
105 {
106 try
107 {
108 StringBuilder buffer = new StringBuilder(BUF_SIZE);
109
110 Class<?> returnType = method.getReturnType();
111 Class<?> declaringClass = method.getDeclaringClass();
112 Class[] params = method.getParameterTypes();
113
114
115
116 if ((this.mode & INCLUDE_RETURNTYPE) == 1)
117 {
118 buffer.append( returnType.getSimpleName() );
119 buffer.append( ' ');
120 }
121
122
123
124 buffer.append( declaringClass.getSimpleName() ) ;
125 buffer.append( '.');
126 buffer.append( method.getName() );
127 buffer.append( '(');
128
129
130
131 for (int i = 0; i < params.length; i++)
132 {
133 buffer.append( params[i].getSimpleName() );
134 if (i < (params.length - 1))
135 {
136 buffer.append(",");
137 }
138 }
139
140 buffer.append(")");
141
142 return buffer.toString();
143 }
144 catch (Throwable t)
145 {
146 return "<" + t.getClass().getSimpleName() + ">";
147 }
148 }
149 }