Package org.apache.tapestry5.plastic
Class PlasticManager
- java.lang.Object
-
- org.apache.tapestry5.plastic.PlasticManager
-
- All Implemented Interfaces:
PlasticClassListenerHub
public class PlasticManager extends Object implements PlasticClassListenerHub
Manages the internal class loaders and other logics necessary to load and transform existing classes, or to create new classes dynamically at runtime. New instances are instantiates usingwithClassLoader(ClassLoader)
orwithContextClassLoader()
, then configuring the returned options object before invokingPlasticManager.PlasticManagerBuilder.create()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PlasticManager.PlasticManagerBuilder
A builder object for configuring the PlasticManager before instantiating it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPlasticClassListener(PlasticClassListener listener)
<T> ClassInstantiator<T>
createClass(Class<T> baseClass, PlasticClassTransformer callback)
Creates an entirely new class, extending from the provided base class.<T> ClassInstantiator<T>
createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback)
Creates an entirely new class.<T> ClassInstantiator<T>
createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback, boolean introduceInterface)
Creates an entirely new class.<T> ClassInstantiator<T>
createProxy(Class<T> interfaceType, PlasticClassTransformer callback)
Creates an entirely new class.<T> ClassInstantiator<T>
createProxy(Class<T> interfaceType, PlasticClassTransformer callback, boolean introduceInterface)
Creates an entirely new class.<T> PlasticClassTransformation<T>
createProxyTransformation(Class interfaceType, Class implementationType)
ReturnscreateProxyTransformation(interfaceType, implementationType, true)
<T> PlasticClassTransformation<T>
createProxyTransformation(Class interfaceType, Class implementationType, boolean introduceInterface)
Creates the underlyingPlasticClassTransformation
for an interface proxy.<T> ClassInstantiator<T>
getClassInstantiator(String className)
Gets theClassInstantiator
for the indicated class, which must be in a transformed package.ClassLoader
getClassLoader()
Returns the ClassLoader that is used to instantiate transformed classes.void
removePlasticClassListener(PlasticClassListener listener)
static PlasticManager.PlasticManagerBuilder
withClassLoader(ClassLoader loader)
Creates a new builder using the specified class loader.static PlasticManager.PlasticManagerBuilder
withContextClassLoader()
Creates a new builder using the thread's context class loader.
-
-
-
Method Detail
-
withContextClassLoader
public static PlasticManager.PlasticManagerBuilder withContextClassLoader()
Creates a new builder using the thread's context class loader.
-
withClassLoader
public static PlasticManager.PlasticManagerBuilder withClassLoader(ClassLoader loader)
Creates a new builder using the specified class loader.
-
getClassLoader
public ClassLoader getClassLoader()
Returns the ClassLoader that is used to instantiate transformed classes. The parent class loader of the returned class loader is the context class loader, or the class loader specified bywithClassLoader(ClassLoader)
.- Returns:
- class loader used to load classes in controlled packages
-
getClassInstantiator
public <T> ClassInstantiator<T> getClassInstantiator(String className)
Gets theClassInstantiator
for the indicated class, which must be in a transformed package.- Parameters:
className
- fully qualified class name- Returns:
- instantiator (configured via the delegate for the class
- Throws:
IllegalArgumentException
- if the class is not a transformed class
-
createClass
public <T> ClassInstantiator<T> createClass(Class<T> baseClass, PlasticClassTransformer callback)
Creates an entirely new class, extending from the provided base class.- Parameters:
baseClass
- class to extend from, which must be a class, not an interfacecallback
- used to configure the new class- Returns:
- the instantiator, which allows instances of the new class to be created
-
createProxy
public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, PlasticClassTransformer callback)
Creates an entirely new class. The class extends from Object and implements the provided interface.- Parameters:
interfaceType
- class to extend from, which must be a class, not an interfacecallback
- used to configure the new class- Returns:
- the instantiator, which allows instances of the new class to be created
- See Also:
createProxyTransformation(Class, Class)
-
createProxy
public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, PlasticClassTransformer callback, boolean introduceInterface)
Creates an entirely new class. The class extends from Object and implements the provided interface.- Parameters:
interfaceType
- class to extend from, which must be a class, not an interfacecallback
- used to configure the new class- Returns:
- the instantiator, which allows instances of the new class to be created
- See Also:
createProxyTransformation(Class, Class)
-
createProxy
public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback)
Creates an entirely new class. The class extends from Object and implements the provided interface.- Parameters:
interfaceType
- class to extend from, which must be a class, not an interfaceimplementationType
- class that implements interfaceType. It can be null.callback
- used to configure the new class- Returns:
- the instantiator, which allows instances of the new class to be created
- Since:
- 5.4
- See Also:
createProxyTransformation(Class, Class)
-
createProxy
public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback, boolean introduceInterface)
Creates an entirely new class. The class extends from Object and implements the provided interface.- Parameters:
interfaceType
- class to extend from, which must be a class, not an interfaceimplementationType
- class that implements interfaceType. It can be null.callback
- used to configure the new classintroduceInterface
- whether to introduce the interface to the Plastic class or not.- Returns:
- the instantiator, which allows instances of the new class to be created
- Since:
- 5.4.5
- See Also:
createProxyTransformation(Class, Class)
-
createProxyTransformation
public <T> PlasticClassTransformation<T> createProxyTransformation(Class interfaceType, Class implementationType)
ReturnscreateProxyTransformation(interfaceType, implementationType, true)
-
createProxyTransformation
public <T> PlasticClassTransformation<T> createProxyTransformation(Class interfaceType, Class implementationType, boolean introduceInterface)
Creates the underlyingPlasticClassTransformation
for an interface proxy. This should only be used in the cases where encapsulating the PlasticClass construction into a callback is not feasible (which is the case for some of the older APIs inside Tapestry IoC).- Parameters:
interfaceType
- class proxy will extend fromimplementationType
- class that implements interfaceType. It can be null.introduceInterface
- whetherresult.getPlasticClass().introduceInterface(interfaceType);
should be called or not.- Returns:
- transformation from which an instantiator may be created
-
addPlasticClassListener
public void addPlasticClassListener(PlasticClassListener listener)
- Specified by:
addPlasticClassListener
in interfacePlasticClassListenerHub
-
removePlasticClassListener
public void removePlasticClassListener(PlasticClassListener listener)
- Specified by:
removePlasticClassListener
in interfacePlasticClassListenerHub
-
-