/** * Creates a new builder using the thread's context class loader. */ public static PlasticManagerBuilder withContextClassLoader() { return withClassLoader(Thread.currentThread().getContextClassLoader()); }
@Override public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, PlasticClassTransformer callback) { return manager.createProxy(interfaceType, callback); }
@Override public <T> PlasticClassTransformation<T> createProxyTransformation(Class<T> interfaceType, Class<? extends T> implementationType) { return manager.createProxyTransformation(interfaceType, implementationType); }
/** * Invoked at object creation, or when there are updates to class files (i.e., invalidation), to create a new set of * Javassist class pools and loaders. */ private void initializeService() { PlasticManagerBuilder builder = PlasticManager.withClassLoader(parent).delegate(this) .packages(controlledPackageNames); if (!productionMode) { builder.enable(TransformationOption.FIELD_WRITEBEHIND); } manager = builder.create(); manager.addPlasticClassListener(this); proxyFactory = new PlasticProxyFactoryImpl(manager, logger); classToInstantiator.clear(); classToModel.clear(); }
@Override public ClassLoader getClassLoader() { return manager.getClassLoader(); }
@Override public void addPlasticClassListener(PlasticClassListener listener) { manager.addPlasticClassListener(listener); }
/** * Creates the PlasticManager with the current set of options. * * @return the PlasticManager */ public PlasticManager create() { lock(); return new PlasticManager(loader, delegate, packages, options); } }
public Instantiator invoke() { // Force the creation of the class (and the transformation of the class). This will first // trigger transformations of any base classes. final ClassInstantiator<Component> plasticInstantiator = manager.getClassInstantiator(className); final ComponentModel model = classToModel.get(className); return new Instantiator() { public Component newInstance(InternalComponentResources resources) { return plasticInstantiator.with(ComponentResources.class, resources) .with(InternalComponentResources.class, resources).newInstance(); } public ComponentModel getModel() { return model; } @Override public String toString() { return String.format("[Instantiator[%s]", className); } }; } });
public Class toClass(String typeName) { try { return PlasticInternalUtils.toClass(manager.getClassLoader(), typeName); } catch (ClassNotFoundException ex) { throw new RuntimeException(String.format( "Unable to convert type '%s' to a Class: %s", typeName, ExceptionUtils.toMessage(ex)), ex); } }
public PlasticProxyFactoryImpl(PlasticManager manager, Logger logger) { assert manager != null; this.manager = manager; if (logger != null) { manager.addPlasticClassListener(new PlasticClassListenerLogger(logger)); } }
/** * Creates the PlasticManager with the current set of options. * * @return the PlasticManager */ public PlasticManager create() { lock(); return new PlasticManager(loader, delegate, packages, options); } }
/** * Creates a new builder using the thread's context class loader. */ public static PlasticManagerBuilder withContextClassLoader() { return withClassLoader(Thread.currentThread().getContextClassLoader()); }
@Override public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback) { return manager.createProxy(interfaceType, implementationType, callback); }
/** * Creates an entirely new class. The class extends from Object and implements the provided interface. * * @param interfaceType * class to extend from, which must be a class, not an interface * @param implementationType * class that implements interfaceType. It can be null. * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created * @see #createProxyTransformation(Class, Class) * @since 5.4 */ public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback) { assert callback != null; PlasticClassTransformation<T> transformation = createProxyTransformation(interfaceType, implementationType); callback.transform(transformation.getPlasticClass()); return transformation.createInstantiator(); }
private ClassNode readClassNode(Class clazz) { byte[] bytecode = PlasticInternalUtils.readBytecodeForClass(manager.getClassLoader(), clazz.getName(), false); return bytecode == null ? null : PlasticInternalUtils.convertBytecodeToClassNode(bytecode); }
public PlasticProxyFactoryImpl(ClassLoader parentClassLoader, Logger logger) { this(PlasticManager.withClassLoader(parentClassLoader).create(), logger); }
/** * Creates an entirely new class. The class extends from Object and implements the provided interface. * * @param interfaceType * class to extend from, which must be a class, not an interface * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created * @see #createProxyTransformation(Class, Class) */ public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, PlasticClassTransformer callback) { return createProxy(interfaceType, null, callback); }
/** * Creates an entirely new class. The class extends from Object and implements the provided interface. * * @param interfaceType * class to extend from, which must be a class, not an interface * @param implementationType * class that implements interfaceType. It can be null. * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created * @see #createProxyTransformation(Class, Class) * @since 5.4 */ public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback) { assert callback != null; PlasticClassTransformation<T> transformation = createProxyTransformation(interfaceType, implementationType); callback.transform(transformation.getPlasticClass()); return transformation.createInstantiator(); }
/** * Creates an entirely new class. The class extends from Object and implements the provided interface. * * @param interfaceType * class to extend from, which must be a class, not an interface * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created * @see #createProxyTransformation(Class, Class) */ public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, PlasticClassTransformer callback) { return createProxy(interfaceType, null, callback); }