java.lang.Object
org.zeroturnaround.javarebel.integration.support.CBPs

public abstract class CBPs extends Object
This class provides a fluent API for processing classes. It can be used to create two types of processors: direct and delayed. A direct processor takes a ClassPool and a CtClass and performs all the proccessing directly on the given CtClass instance. A delayed processor gathers a bunch of processing commands, and can later execute them all on a given CtClass. A delayed processor is also a JavassistClassBytecodeProcessor.

The process method is used to create a direct processor. Methods like implement(Class) and implement(String) are used to create delayed processors.

Here is how one would use a direct processor:


 CBPs.process(cp, ctClass)
     .importPackage("org.zeroturnaround.javarebel")
     .importPackage("org.zeroturnaround.javarebel.integration.util")
     
     .addInterface(ClassEventListener.class)
     
     .addLoggerField("jrLog", "MyPlugin")
     
     .addMethod("" +
         "public void onClassEvent(int eventType, Class klass) {" +
         "  jrLog.info(\"Class reload event received for \" + klass);" +
         "}")
     
     .addMethod("" +
         "public int priority() {" +
         "  return PRIORITY_DEFAULT;" +
         "}")
     
     .insertAfterLeafCtors("{" +
         "  ReloaderFactory.getInstance().addClassReloadListener(WeakUtil.weakCEL(this));" +
         "}");
 
Here is how one could use a delayed processor in a plugin class to implement simple one method interfaces:

 integration.addIntegrationProcessor(
   "com.ibm.ws.jaxws.webcontainer.LibertyJaxWsServlet",
   CBPs.implement(JrLibertyJaxWsServlet.class)
       .withMethod("" +
           "public void setWsEndpointInfo(Object epInfo) {" +
           "  endpoint.setEndpointInfo(epInfo);" +
           "}"));
 
  • Constructor Details

    • CBPs

      public CBPs()
  • Method Details

    • implement

      public static CBPs.DelayedProcessor implement(String intfName)
    • implement

      public static CBPs.DelayedProcessor implement(Class<?> intf)
    • process

      public static CBPs.DirectProcessor process(org.zeroturnaround.bundled.javassist.ClassPool cp, org.zeroturnaround.bundled.javassist.CtClass ctClass)
    • replaceMethodCall

      public static org.zeroturnaround.bundled.javassist.expr.ExprEditor replaceMethodCall(String methodName, String src)
      Creates an ExprEditor that replaces a method call with given source code. Example usage:
      
       CBPs.process(cp, ctClass)
           .instrument("createPersistentAutomaticTimers",
               CBPs.replaceMethodCall("existsTaskGroup", "$_ = false;"))