/** * Adds a method to the class which bridges from the service method to the corresponding method in * the filter interface. The next service (either another Bridge, or the terminator at the end of * the pipeline) is passed to the filter). */ private void addBridgeMethod(int position, MethodSignature ms, MethodSignature fms) { StringBuffer buffer = new StringBuffer(100); if (ms.getReturnType() != void.class) buffer.append("return "); buffer.append("_filter."); buffer.append(ms.getName()); buffer.append("("); boolean comma = false; int filterParameterCount = fms.getParameterTypes().length; for (int i = 0; i < position; i++) { if (comma) buffer.append(", "); buffer.append("$"); // Add one to the index to get the parameter symbol ($0 is the implicit // this parameter). buffer.append(i + 1); comma = true; } if (comma) buffer.append(", "); // _next is the variable in -this- Bridge that points to the -next- Bridge // or the terminator for the pipeline. The filter is expected to reinvoke the // method on the _next that's passed to it. buffer.append("_next"); for (int i = position + 1; i < filterParameterCount; i++) { buffer.append(", $"); buffer.append(i); } buffer.append(");"); // This should work, unless the exception types turn out to not be compatble. We still // don't do a check on that, and not sure that Javassist does either! _classFab.addMethod(Modifier.PUBLIC, ms, buffer.toString()); }
public boolean matchMethod(MethodSignature sig) { return sig.getName().indexOf(_nameSubstring) >= 0; }