public class MetaClassRegistryImpl
extends Object
implements MetaClassRegistry
A registry of MetaClass instances which caches introspection and reflection information and allows methods to be dynamically added to existing classes at runtime
| Modifiers | Name | Description |
|---|---|---|
static int |
DONT_LOAD_DEFAULT |
Flag to skip loading default metaclasses during registry initialization. |
static String |
EXTENSION_DISABLE_PROPERTY |
System property name used to disable specific extension modules. |
static int |
LOAD_DEFAULT |
Flag to load default metaclasses for standard Java and Groovy types when initializing the registry. |
static String |
MODULE_META_INF_FILE |
|
| Constructor and description |
|---|
MetaClassRegistryImpl()Creates a new MetaClassRegistry with default settings. |
MetaClassRegistryImpl(int loadDefault)Creates a new MetaClassRegistry with optional default metaclass loading. |
MetaClassRegistryImpl(boolean useAccessible)
|
MetaClassRegistryImpl(int loadDefault, boolean useAccessible)Creates a new MetaClassRegistry with customizable settings. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)Adds a listener for constant metaclasses. |
|
public void |
addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)Adds a listener for constant metaclasses. |
|
protected void |
fireConstantMetaClassUpdate(Object obj, Class c, MetaClass oldMC, MetaClass newMc)Causes the execution of all registered listeners. |
|
public static MetaClassRegistry |
getInstance(int includeExtension)Singleton of MetaClassRegistry. |
|
public FastArray |
getInstanceMethods()Gets the instance methods registered in this registry. |
|
public final MetaClass |
getMetaClass(Class theClass)Gets the MetaClass for the given class. |
|
public MetaClass |
getMetaClass(Object obj)Gets the metaclass for the given object. |
|
public MetaClassCreationHandle |
getMetaClassCreationHandler()Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon |
|
public MetaClassRegistryChangeEventListener[] |
getMetaClassRegistryChangeEventListeners()Gets an array of all registered ConstantMetaClassListener instances. |
|
public ExtensionModuleRegistry |
getModuleRegistry()Gets the extension module registry. |
|
public FastArray |
getStaticMethods()Gets the static methods registered in this registry. |
|
public Iterator |
iterator()Returns an iterator to iterate over all constant metaclasses. |
|
public void |
registerExtensionModuleFromProperties(Properties properties, ClassLoader classLoader, Map<CachedClass, List<MetaMethod>> map)Registers extension module methods from the given properties. |
|
public void |
removeMetaClass(Class theClass)Removes the metaclass for the given class, resetting it to null. |
|
public void |
removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)Removes a constant metaclass listener. |
|
public void |
setMetaClass(Class theClass, MetaClass theMetaClass)Sets the metaclass for the given class, replacing any existing metaclass. |
|
public void |
setMetaClass(Object obj, MetaClass theMetaClass)Sets the per-instance metaclass for the given object. |
|
public void |
setMetaClassCreationHandle(MetaClassCreationHandle handle)Sets a handle internally used to create MetaClass implementations. |
|
public boolean |
useAccessible()Returns whether reflection access modifiers are being set. |
Flag to skip loading default metaclasses during registry initialization.
System property name used to disable specific extension modules. When set, the value should be a comma-separated list of extension module names to disable.
Flag to load default metaclasses for standard Java and Groovy types when initializing the registry.
Creates a new MetaClassRegistry with default settings. Loads default metaclasses for standard Java and Groovy types.
Creates a new MetaClassRegistry with optional default metaclass loading.
loadDefault - either LOAD_DEFAULT to load default metaclasses or DONT_LOAD_DEFAULT to skip loading
useAccessible - defines whether the AccessibleObject.setAccessible
method will be called to enable access to all methods when using reflectionCreates a new MetaClassRegistry with customizable settings.
loadDefault - either LOAD_DEFAULT to load default metaclasses or DONT_LOAD_DEFAULT to skip loadinguseAccessible - whether to use AccessibleObject.setAccessible() for reflection accessAdds a listener for constant metaclasses.
listener - the listenerAdds a listener for constant metaclasses. This listener cannot be removed!
listener - the listenerCauses the execution of all registered listeners. This method is used mostly internal to kick of the listener notification. It can also be used by subclasses to achieve the same.
obj - object instance if the MetaClass change is on a per-instance metaclass (or null if global)c - the classoldMC - the old MetaClassnewMc - the new MetaClassSingleton of MetaClassRegistry.
Gets the instance methods registered in this registry.
Gets the MetaClass for the given class.
theClass - the class to get the metaclass forGets the metaclass for the given object. For Class objects, returns the metaclass for that class; for other objects, returns the instance-specific metaclass if set, otherwise the metaclass for the object's class.
obj - the object to get the metaclass forGets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon
Gets an array of all registered ConstantMetaClassListener instances.
Gets the extension module registry. The registry keeps track of all loaded extension modules.
Gets the static methods registered in this registry.
Returns an iterator to iterate over all constant metaclasses. This iterator can be seen as making a snapshot of the current state of the registry. The snapshot will include all metaclasses that has been used unless they are already collected. Collected metaclasses will be skipped automatically, so you can expect that each element of the iteration is not null. Calling this method is thread safe, the usage of the iterator is not.
Registers extension module methods from the given properties. This method scans for extension modules defined in properties and registers their methods.
properties - the properties containing extension module definitionsclassLoader - the class loader to use for loading extension modulesmap - the map to store the loaded meta methodsRemoves the metaclass for the given class, resetting it to null. This forces a new metaclass to be created the next time one is needed.
theClass - the class to remove the metaclass forRemoves a constant metaclass listener.
listener - the listenerSets the metaclass for the given class, replacing any existing metaclass.
theClass - the class to set the metaclass fortheMetaClass - the new metaclassSets the per-instance metaclass for the given object. This allows individual instances to have their own custom metaclass implementation.
obj - the object to set the metaclass fortheMetaClass - the new metaclass for this instanceSets a handle internally used to create MetaClass implementations. When replacing the handle with a custom version, you should reuse the old handle to keep custom logic and to use the default logic as fall back. WARNING: experimental code, likely to change soon
handle - the handleReturns whether reflection access modifiers are being set. When true, the AccessibleObject.setAccessible(true) method will be called when using reflection to access methods and fields.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.