| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.uruma.binding.method; |
| 17 | |
|
| 18 | |
import java.lang.reflect.Method; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import org.seasar.framework.util.MethodUtil; |
| 23 | |
import org.seasar.uruma.core.UrumaConstants; |
| 24 | |
import org.seasar.uruma.core.UrumaMessageCodes; |
| 25 | |
import org.seasar.uruma.log.UrumaLogger; |
| 26 | |
import org.seasar.uruma.util.AssertionUtil; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public class MethodBinding { |
| 34 | 4 | private static final UrumaLogger logger = UrumaLogger |
| 35 | |
.getLogger(MethodBinding.class); |
| 36 | |
|
| 37 | |
protected Object target; |
| 38 | |
|
| 39 | |
protected Method method; |
| 40 | |
|
| 41 | 428 | protected List<ArgumentsFilter> argumentsFilterList = new ArrayList<ArgumentsFilter>(); |
| 42 | |
|
| 43 | |
protected MethodCallback callback; |
| 44 | |
|
| 45 | |
private String description; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
MethodBinding(final Object target, final Method method, |
| 56 | 428 | final MethodCallback callback) { |
| 57 | 428 | AssertionUtil.assertNotNull("target", target); |
| 58 | 428 | AssertionUtil.assertNotNull("method", method); |
| 59 | |
|
| 60 | 428 | this.target = target; |
| 61 | 428 | this.method = method; |
| 62 | 428 | this.description = UrumaLogger.getObjectDescription(target) |
| 63 | |
+ UrumaConstants.HASH_MARK + method.getName(); |
| 64 | 428 | this.callback = callback; |
| 65 | 428 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public Object invoke() { |
| 76 | 0 | return invoke(null); |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public Object invoke(final Object[] args) { |
| 90 | 44 | if (logger.isInfoEnabled()) { |
| 91 | 0 | logger.log(UrumaMessageCodes.START_METHOD_CALL, UrumaLogger |
| 92 | |
.getObjectDescription(target), method.getName(), args); |
| 93 | |
} |
| 94 | |
|
| 95 | 44 | Object[] filteredArgs = args; |
| 96 | 44 | for (ArgumentsFilter filter : argumentsFilterList) { |
| 97 | 88 | filteredArgs = filter.filter(filteredArgs); |
| 98 | |
} |
| 99 | 44 | Object result = MethodUtil.invoke(method, target, filteredArgs); |
| 100 | |
|
| 101 | 44 | if (logger.isInfoEnabled()) { |
| 102 | 0 | logger.log(UrumaMessageCodes.END_METHOD_CALL, UrumaLogger |
| 103 | |
.getObjectDescription(target), method.getName(), result); |
| 104 | |
} |
| 105 | |
|
| 106 | 44 | return callback(args, result); |
| 107 | |
} |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
public void addArgumentsFilter(final ArgumentsFilter argumentsFilter) { |
| 118 | 848 | this.argumentsFilterList.add(argumentsFilter); |
| 119 | 848 | } |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
public Method getMethod() { |
| 127 | 0 | return this.method; |
| 128 | |
} |
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
public Object getTarget() { |
| 136 | 44 | return this.target; |
| 137 | |
} |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
public void setCallback(final MethodCallback callback) { |
| 146 | 428 | this.callback = callback; |
| 147 | 428 | } |
| 148 | |
|
| 149 | |
protected Object callback(final Object[] args, final Object returnValue) { |
| 150 | 44 | if (callback != null) { |
| 151 | 44 | return callback.callback(this, args, returnValue); |
| 152 | |
} else { |
| 153 | 0 | return returnValue; |
| 154 | |
} |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
@Override |
| 161 | |
public String toString() { |
| 162 | 0 | return this.description; |
| 163 | |
} |
| 164 | |
} |