CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-cglib--cglib-nodep

Code generation library for creating dynamic proxies, bean utilities, and fast reflection alternatives with bundled dependencies

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

CGLib (cglib-nodep)

CGLib is a powerful Java code generation library that enables dynamic class creation, proxy generation, and bytecode manipulation at runtime. The cglib-nodep distribution bundles CGLib with all dependencies (including ASM) into a single JAR without external dependencies, making it ideal for applications that need to avoid dependency conflicts.

Package Information

  • Package Name: cglib-nodep
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib-nodep</artifactId>
      <version>3.3.0</version>
    </dependency>

Core Imports

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.beans.BeanCopier;
import net.sf.cglib.reflect.FastClass;

Basic Usage

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

// Create enhanced proxy class
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(MyClass.class);
enhancer.setCallback(new MethodInterceptor() {
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("Before method: " + method.getName());
        Object result = proxy.invokeSuper(obj, args);
        System.out.println("After method: " + method.getName());
        return result;
    }
});

MyClass proxy = (MyClass) enhancer.create();
proxy.someMethod(); // Will be intercepted

Architecture

CGLib is organized around several key components:

  • Proxy Generation: Dynamic creation of enhanced classes that extend existing classes or implement interfaces
  • Method Interception: Callback-based system for intercepting and modifying method calls
  • Bean Utilities: High-performance utilities for JavaBean manipulation (copying, mapping, generation)
  • Fast Reflection: Optimized alternatives to Java reflection for method/constructor invocation
  • Code Generation: Low-level bytecode generation framework using ASM (repackaged to avoid conflicts)
  • Runtime Enhancement: Dynamic class modification and proxy creation without compile-time dependencies

Capabilities

Proxy and Enhancement

Core proxy generation functionality for creating enhanced classes with method interception, callback support, and dynamic interface implementation.

public class Enhancer {
    public static Object create(Class type, Callback callback);
    public static Object create(Class superclass, Class[] interfaces, Callback callback); 
    public void setSuperclass(Class superclass);
    public void setCallback(Callback callback);
    public Object create();
}

public interface MethodInterceptor extends Callback {
    Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable;
}

public class MethodProxy {
    public Object invoke(Object obj, Object[] args) throws Throwable;
    public Object invokeSuper(Object obj, Object[] args) throws Throwable;
}

Proxy and Enhancement

Bean Utilities

High-performance JavaBean manipulation utilities including property copying, dynamic bean generation, and Map-based bean access.

public abstract class BeanCopier {
    public static BeanCopier create(Class source, Class target, boolean useConverter);
    public abstract void copy(Object from, Object to, Converter converter);
}

public abstract class BeanMap implements Map {
    public static BeanMap create(Object bean);
    public abstract Object get(Object bean, Object key);
    public abstract Object put(Object bean, Object key, Object value);
}

public class BeanGenerator {
    public void addProperty(String name, Class type);
    public Object create();
}

Bean Utilities

Reflection Utilities

Fast alternatives to Java reflection for method and constructor invocation, plus method delegation utilities.

public abstract class FastClass {
    public static FastClass create(Class type);
    public abstract Object invoke(String name, Class[] parameterTypes, Object obj, Object[] args) throws InvocationTargetException;
    public abstract Object newInstance() throws InvocationTargetException;
    public abstract FastMethod getMethod(String name, Class[] parameterTypes);
}

public class FastMethod {
    public Object invoke(Object obj, Object[] args) throws InvocationTargetException;
    public Method getJavaMethod();
}

public abstract class MethodDelegate {
    public static MethodDelegate create(Object target, String methodName, Class iface);
}

Reflection Utilities

Core Utilities

Essential utilities for key generation, transformations, predicates, and low-level code generation support.

public abstract class KeyFactory {
    public static KeyFactory create(Class keyInterface);
    public abstract Object newInstance(Object[] args);
}

public interface Converter {
    Object convert(Object value, Class target, Object context);
}

public interface Transformer {
    Object transform(Object value);
}

public interface Predicate {
    boolean evaluate(Object arg);
}

Core Utilities

Transformation Utilities

Bytecode transformation utilities for modifying classes at load time and generating transformed versions of existing classes.

public class TransformingClassLoader extends AbstractClassLoader {
    public TransformingClassLoader(ClassLoader parent, ClassFilter filter, ClassTransformerFactory t);
}

public abstract class ClassTransformer extends ClassVisitor {
    public abstract void setTarget(ClassVisitor target);
}

public interface ClassFilter {
    boolean accept(String className);
}

Transformation Utilities

Utility Classes

High-performance utility classes for string switching and parallel array sorting operations.

public abstract class StringSwitcher {
    public static StringSwitcher create(String[] strings, int[] ints, boolean fixedInput);
    public abstract int intValue(String s);
}

public abstract class ParallelSorter {
    public static ParallelSorter create(Object[] arrays);
    public abstract void quickSort(int index);
}

Utility Classes

Types

Core Callback Types

public interface Callback {
    // Marker interface for all callback types
}

public interface MethodInterceptor extends Callback {
    Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable;
}

public interface FixedValue extends Callback {
    Object loadObject() throws Exception;
}

public interface LazyLoader extends Callback {
    Object loadObject() throws Exception;
}

public interface Dispatcher extends Callback {
    Object loadObject() throws Exception;
}

public interface NoOp extends Callback {
    // Marker interface - no methods
}

public interface CallbackFilter {
    int accept(Method method);
}

Factory Interface

public interface Factory {
    Object newInstance(Callback callback);
    Object newInstance(Callback[] callbacks);
    Callback getCallback(int index);
    void setCallback(int index, Callback callback);
    void setCallbacks(Callback[] callbacks);
    Callback[] getCallbacks();
}

Exception Types

public class BulkBeanException extends RuntimeException {
    public BulkBeanException(String message, int index);
    public int getIndex();
}

public class UndeclaredThrowableException extends RuntimeException {
    public UndeclaredThrowableException(Throwable t);
    public Throwable getUndeclaredThrowable();
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/cglib/cglib-nodep@3.3.x
Publish Source
CLI
Badge
tessl/maven-cglib--cglib-nodep badge