Class MetaClassRegistryImpl
java.lang.Object
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl
- All Implemented Interfaces:
MetaClassRegistry
A registry of MetaClass instances which caches introspection and
reflection information and allows methods to be dynamically added to
existing classes at runtime
-
Nested Class Summary
Nested classes/interfaces inherited from interface groovy.lang.MetaClassRegistry
MetaClassRegistry.MetaClassCreationHandle
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMetaClassRegistryImpl
(boolean useAccessible) MetaClassRegistryImpl
(int loadDefault) MetaClassRegistryImpl
(int loadDefault, boolean useAccessible) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a listener for constant meta classes.void
Adds a listener for constant meta classes.protected void
fireConstantMetaClassUpdate
(Object obj, Class c, MetaClass oldMC, MetaClass newMc) Causes the execution of all registered listeners.static MetaClassRegistry
getInstance
(int includeExtension) Singleton of MetaClassRegistry.final MetaClass
getMetaClass
(Class theClass) The main function of the registry If a meta class exists then return it otherwise create one, put it in the registry and return itgetMetaClass
(Object obj) Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soonGets an array of all registered ConstantMetaClassListener instances.iterator()
Returns an iterator to iterate over all constant meta classes.void
registerExtensionModuleFromProperties
(Properties properties, ClassLoader classLoader, Map<CachedClass, List<MetaMethod>> map) void
removeMetaClass
(Class theClass) Removes a cached MetaClass from the registryvoid
Removes a constant meta class listener.void
setMetaClass
(Class theClass, MetaClass theMetaClass) Registers a new MetaClass in the registry to customize the typevoid
setMetaClass
(Object obj, MetaClass theMetaClass) void
Sets a handle internally used to create MetaClass implementations.boolean
-
Field Details
-
MODULE_META_INF_FILE
Deprecated.UseExtensionModuleScanner.MODULE_META_INF_FILE
instead- See Also:
-
EXTENSION_DISABLE_PROPERTY
- See Also:
-
LOAD_DEFAULT
public static final int LOAD_DEFAULT- See Also:
-
DONT_LOAD_DEFAULT
public static final int DONT_LOAD_DEFAULT- See Also:
-
-
Constructor Details
-
MetaClassRegistryImpl
public MetaClassRegistryImpl() -
MetaClassRegistryImpl
public MetaClassRegistryImpl(int loadDefault) -
MetaClassRegistryImpl
public MetaClassRegistryImpl(boolean useAccessible) - Parameters:
useAccessible
- defines whether or not theAccessibleObject.setAccessible(boolean)
method will be called to enable access to all methods when using reflection
-
MetaClassRegistryImpl
public MetaClassRegistryImpl(int loadDefault, boolean useAccessible)
-
-
Method Details
-
registerExtensionModuleFromProperties
public void registerExtensionModuleFromProperties(Properties properties, ClassLoader classLoader, Map<CachedClass, List<MetaMethod>> map) -
getModuleRegistry
-
getMetaClass
Description copied from interface:MetaClassRegistry
The main function of the registry If a meta class exists then return it otherwise create one, put it in the registry and return it- Specified by:
getMetaClass
in interfaceMetaClassRegistry
-
getMetaClass
-
removeMetaClass
Description copied from interface:MetaClassRegistry
Removes a cached MetaClass from the registry- Specified by:
removeMetaClass
in interfaceMetaClassRegistry
- Parameters:
theClass
- The Java class of the MetaClass to remove
-
setMetaClass
Registers a new MetaClass in the registry to customize the type- Specified by:
setMetaClass
in interfaceMetaClassRegistry
- Parameters:
theClass
-theMetaClass
-
-
setMetaClass
-
useAccessible
public boolean useAccessible() -
getMetaClassCreationHandler
Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon- Specified by:
getMetaClassCreationHandler
in interfaceMetaClassRegistry
- Returns:
- the handle
-
setMetaClassCreationHandle
Sets 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- Specified by:
setMetaClassCreationHandle
in interfaceMetaClassRegistry
- Parameters:
handle
- the handle
-
addMetaClassRegistryChangeEventListener
Adds a listener for constant meta classes.- Specified by:
addMetaClassRegistryChangeEventListener
in interfaceMetaClassRegistry
- Parameters:
listener
- the listener
-
addNonRemovableMetaClassRegistryChangeEventListener
public void addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener) Adds a listener for constant meta classes. This listener cannot be removed!- Specified by:
addNonRemovableMetaClassRegistryChangeEventListener
in interfaceMetaClassRegistry
- Parameters:
listener
- the listener
-
removeMetaClassRegistryChangeEventListener
public void removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener) Removes a constant meta class listener.- Specified by:
removeMetaClassRegistryChangeEventListener
in interfaceMetaClassRegistry
- Parameters:
listener
- the listener
-
fireConstantMetaClassUpdate
Causes 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.- Parameters:
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 MetaClass
-
getMetaClassRegistryChangeEventListeners
Gets an array of all registered ConstantMetaClassListener instances.- Specified by:
getMetaClassRegistryChangeEventListeners
in interfaceMetaClassRegistry
- Returns:
- an array containing all change listener
-
getInstance
Singleton of MetaClassRegistry.- Parameters:
includeExtension
-- Returns:
- the registry
-
getInstanceMethods
-
getStaticMethods
-
iterator
Returns an iterator to iterate over all constant meta classes. This iterator can be seen as making a snapshot of the current state of the registry. The snapshot will include all meta classes that has been used unless they are already collected. Collected meta classes 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.- Specified by:
iterator
in interfaceMetaClassRegistry
- Returns:
- the iterator.
-
ExtensionModuleScanner.MODULE_META_INF_FILE
instead