Top Description Inners Fields Constructors Methods
org.codehaus.groovy.runtime.metaclass

public Class MetaClassRegistryImpl

extends Object
implements MetaClassRegistry
Class Inheritance
All Implemented Interfaces
groovy.lang.MetaClassRegistry
Imports
groovy.lang.ExpandoMetaClass, .GroovyRuntimeException, .MetaClass, .MetaClassRegistry, .MetaClassRegistryChangeEvent, .MetaClassRegistryChangeEventListener, .MetaMethod, org.codehaus.groovy.classgen.Verifier, org.codehaus.groovy.reflection.CachedClass, .CachedMethod, .ClassInfo, .GeneratedMetaMethod, .ReflectionCache, org.codehaus.groovy.runtime.DefaultGroovyMethods, .DefaultGroovyStaticMethods, org.codehaus.groovy.runtime.m12n.ExtensionModule, .ExtensionModuleRegistry, .ExtensionModuleScanner, org.codehaus.groovy.util.FastArray, .ManagedConcurrentLinkedQueue, .ReferenceBundle, org.codehaus.groovy.vmplugin.VMPluginFactory, java.lang.reflect.Constructor, .Field, .InvocationTargetException, .Modifier, java.util.ArrayList, .HashMap, .Iterator, .LinkedList, .List, .Map, .Properties

A registry of MetaClass instances which caches introspection and reflection information and allows methods to be dynamically added to existing classes at runtime

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final LinkedList<MetaClassRegistryChangeEventListener>
public static final int
private static final MetaClass[]
private static final MetaClassRegistryChangeEventListener[]
private static MetaClassRegistry
private static MetaClassRegistry
private final FastArray
public static final int
private volatile MetaClassRegistry.MetaClassCreationHandle
private final ManagedConcurrentLinkedQueue<MetaClass>
public static final String
private final ExtensionModuleRegistry
private final LinkedList<MetaClassRegistryChangeEventListener>
private final FastArray
private final boolean

Constructor Summary

AccessConstructor and Description
public
public
MetaClassRegistryImpl(int loadDefault)

public
MetaClassRegistryImpl(boolean
defines whether or not the java.lang.reflect.AccessibleObject#setAccessible(boolean) method will be called to enable access to all methods when using reflection
useAccessible
)

public
MetaClassRegistryImpl(final int loadDefault, final boolean useAccessible)

Method Summary

Modifier and TypeMethod and Description
public void
public void
private void
protected void
fireConstantMetaClassUpdate(Object
object instance if the MetaClass change is on a per-instance metaclass (or null if global)
obj
,
Class<T>
the class
c
,
final MetaClass
the old MetaClass
oldMC
,
MetaClass
the new MetaClass
newMc
)

Causes the execution of all registered listeners.

public static synchronized MetaClassRegistry

Returns:

the registry
getInstance
(int includeExtension)

Singleton of MetaClassRegistry.

public FastArray
public final MetaClass
getMetaClass(Class<T> theClass)

Implements groovy.lang.MetaClassRegistry.getMetaClass.

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
public MetaClass
public MetaClassRegistry.MetaClassCreationHandle

Returns:

the handle
getMetaClassCreationHandler
()

Implements groovy.lang.MetaClassRegistry.getMetaClassCreationHandler.

Gets a handle internally used to create MetaClass implementations

Warning

experimental code, likely to change soon

public MetaClassRegistryChangeEventListener[]
getMetaClassRegistryChangeEventListeners()

Implements groovy.lang.MetaClassRegistry.getMetaClassRegistryChangeEventListeners.

Gets an array of all registered ConstantMetaClassListener instances.
public ExtensionModuleRegistry
public FastArray
private void
installMetaClassCreationHandle()

Looks for a class called 'groovy.runtime.metaclass.CustomMetaClassCreationHandle' and if it exists uses it as the MetaClassCreationHandle otherwise uses the default

public Iterator<E>

Returns:

the iterator.
iterator
()

Implements groovy.lang.MetaClassRegistry.iterator.

Returns an iterator to iterate over all constant meta classes.
private static void
public void
registerExtensionModuleFromProperties(final Properties properties, final ClassLoader classLoader, final Map<CachedClass, List<MetaMethod>> map)

private void
registerMethods(final Class<T> theClass, final boolean useMethodWrapper, final boolean useInstanceMethods, Map<CachedClass, List<MetaMethod>> map)

public void
removeMetaClass(Class<T>
The Java class of the MetaClass to remove
theClass
)

Implements groovy.lang.MetaClassRegistry.removeMetaClass.

Removes a cached MetaClass from the registry
public void
private void
setMetaClass(Class<T> theClass, MetaClass oldMc, MetaClass newMc)

if oldMc is null, newMc will replace whatever meta class was used before.

public void
setMetaClass(Class<T> theClass, MetaClass theMetaClass)

Implements groovy.lang.MetaClassRegistry.setMetaClass.

Registers a new MetaClass in the registry to customize the type
public void
setMetaClass(Object obj, MetaClass theMetaClass)

public void
setMetaClassCreationHandle(MetaClassRegistry.MetaClassCreationHandle
the handle
handle
)

Implements groovy.lang.MetaClassRegistry.setMetaClassCreationHandle.

Sets a handle internally used to create MetaClass implementations.
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

changeListenerListback to summary
private final LinkedList<MetaClassRegistryChangeEventListener> changeListenerList
DONT_LOAD_DEFAULTback to summary
public static final int DONT_LOAD_DEFAULT
EMPTY_METACLASS_ARRAYback to summary
private static final MetaClass[] EMPTY_METACLASS_ARRAY
EMPTY_METACLASSREGISTRYCHANGEEVENTLISTENER_ARRAYback to summary
private static final MetaClassRegistryChangeEventListener[] EMPTY_METACLASSREGISTRYCHANGEEVENTLISTENER_ARRAY
instanceExcludeback to summary
private static MetaClassRegistry instanceExclude
instanceIncludeback to summary
private static MetaClassRegistry instanceInclude
instanceMethodsback to summary
private final FastArray instanceMethods
LOAD_DEFAULTback to summary
public static final int LOAD_DEFAULT
metaClassCreationHandleback to summary
private volatile MetaClassRegistry.MetaClassCreationHandle metaClassCreationHandle
metaClassInfoback to summary
private final ManagedConcurrentLinkedQueue<MetaClass> metaClassInfo
MODULE_META_INF_FILEback to summary
public static final String MODULE_META_INF_FILE
Annotations
@Deprecated
moduleRegistryback to summary
private final ExtensionModuleRegistry moduleRegistry
nonRemoveableChangeListenerListback to summary
private final LinkedList<MetaClassRegistryChangeEventListener> nonRemoveableChangeListenerList
staticMethodsback to summary
private final FastArray staticMethods
useAccessibleback to summary
private final boolean useAccessible

Constructor Detail

MetaClassRegistryImplback to summary
public MetaClassRegistryImpl()
MetaClassRegistryImplback to summary
public MetaClassRegistryImpl(int loadDefault)
MetaClassRegistryImplback to summary
public MetaClassRegistryImpl(boolean useAccessible)
Parameters
useAccessible:boolean

defines whether or not the java.lang.reflect.AccessibleObject#setAccessible(boolean) method will be called to enable access to all methods when using reflection

MetaClassRegistryImplback to summary
public MetaClassRegistryImpl(final int loadDefault, final boolean useAccessible)

Method Detail

addMetaClassRegistryChangeEventListenerback to summary
public void addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

Implements groovy.lang.MetaClassRegistry.addMetaClassRegistryChangeEventListener.

Adds a listener for constant meta classes.

Parameters
listener:MetaClassRegistryChangeEventListener

the listener

addNonRemovableMetaClassRegistryChangeEventListenerback to summary
public void addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

Implements groovy.lang.MetaClassRegistry.addNonRemovableMetaClassRegistryChangeEventListener.

Adds a listener for constant meta classes. This listener cannot be removed!

Parameters
listener:MetaClassRegistryChangeEventListener

the listener

createMetaMethodFromClassback to summary
private void createMetaMethodFromClass(Map<CachedClass, List<MetaMethod>> map, Class<T> aClass)
fireConstantMetaClassUpdateback to summary
protected void fireConstantMetaClassUpdate(Object obj, Class<T> c, final MetaClass oldMC, MetaClass newMc)

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

object instance if the MetaClass change is on a per-instance metaclass (or null if global)

c:Class<T>

the class

oldMC:MetaClass

the old MetaClass

newMc:MetaClass

the new MetaClass

getInstanceback to summary
public static synchronized MetaClassRegistry getInstance(int includeExtension)

Singleton of MetaClassRegistry.

Returns:MetaClassRegistry

the registry

getInstanceMethodsback to summary
public FastArray getInstanceMethods()
getMetaClassback to summary
public final MetaClass getMetaClass(Class<T> theClass)

Implements groovy.lang.MetaClassRegistry.getMetaClass.

Doc from groovy.lang.MetaClassRegistry.getMetaClass.

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

getMetaClassback to summary
public MetaClass getMetaClass(Object obj)
getMetaClassCreationHandlerback to summary
public MetaClassRegistry.MetaClassCreationHandle getMetaClassCreationHandler()

Implements groovy.lang.MetaClassRegistry.getMetaClassCreationHandler.

Gets a handle internally used to create MetaClass implementations

Warning

experimental code, likely to change soon

Returns:MetaClassRegistry.MetaClassCreationHandle

the handle

getMetaClassRegistryChangeEventListenersback to summary
public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners()

Implements groovy.lang.MetaClassRegistry.getMetaClassRegistryChangeEventListeners.

Gets an array of all registered ConstantMetaClassListener instances.

Returns:MetaClassRegistryChangeEventListener[]

Doc from groovy.lang.MetaClassRegistry.getMetaClassRegistryChangeEventListeners.

an array containing all change listener

getModuleRegistryback to summary
public ExtensionModuleRegistry getModuleRegistry()
getStaticMethodsback to summary
public FastArray getStaticMethods()
installMetaClassCreationHandleback to summary
private void installMetaClassCreationHandle()

Looks for a class called 'groovy.runtime.metaclass.CustomMetaClassCreationHandle' and if it exists uses it as the MetaClassCreationHandle otherwise uses the default

See Also
groovy.lang.MetaClassRegistry.MetaClassCreationHandle
iteratorback to summary
public Iterator<E> iterator()

Implements groovy.lang.MetaClassRegistry.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.

Returns:Iterator<E>

the iterator.

refreshMopMethodsback to summary
private static void refreshMopMethods(final Map<CachedClass, List<MetaMethod>> map)
registerExtensionModuleFromPropertiesback to summary
public void registerExtensionModuleFromProperties(final Properties properties, final ClassLoader classLoader, final Map<CachedClass, List<MetaMethod>> map)
registerMethodsback to summary
private void registerMethods(final Class<T> theClass, final boolean useMethodWrapper, final boolean useInstanceMethods, Map<CachedClass, List<MetaMethod>> map)
removeMetaClassback to summary
public void removeMetaClass(Class<T> theClass)

Implements groovy.lang.MetaClassRegistry.removeMetaClass.

Doc from groovy.lang.MetaClassRegistry.removeMetaClass.

Removes a cached MetaClass from the registry

Parameters
theClass:Class<T>

The Java class of the MetaClass to remove

removeMetaClassRegistryChangeEventListenerback to summary
public void removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

Implements groovy.lang.MetaClassRegistry.removeMetaClassRegistryChangeEventListener.

Removes a constant meta class listener.

Parameters
listener:MetaClassRegistryChangeEventListener

the listener

setMetaClassback to summary
private void setMetaClass(Class<T> theClass, MetaClass oldMc, MetaClass newMc)

if oldMc is null, newMc will replace whatever meta class was used before. if oldMc is not null, then newMc will be used only if the stored mc is the same as oldMc

setMetaClassback to summary
public void setMetaClass(Class<T> theClass, MetaClass theMetaClass)

Implements groovy.lang.MetaClassRegistry.setMetaClass.

Registers a new MetaClass in the registry to customize the type

setMetaClassback to summary
public void setMetaClass(Object obj, MetaClass theMetaClass)
setMetaClassCreationHandleback to summary
public void setMetaClassCreationHandle(MetaClassRegistry.MetaClassCreationHandle handle)

Implements groovy.lang.MetaClassRegistry.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

Parameters
handle:MetaClassRegistry.MetaClassCreationHandle

the handle

useAccessibleback to summary
public boolean useAccessible()
org.codehaus.groovy.runtime.metaclass back to summary

private Class MetaClassRegistryImpl.DefaultModuleListener

extends Object
implements ExtensionModuleListener
Class Inheritance
  • java.lang.Object
  • org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.DefaultModuleListener
All Implemented Interfaces
org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.ExtensionModuleListener

Field Summary

Modifier and TypeField and Description
private final Map<CachedClass, List<MetaMethod>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
private final Map<CachedClass, List<MetaMethod>> map

Constructor Detail

DefaultModuleListenerback to summary
public DefaultModuleListener(final Map<CachedClass, List<MetaMethod>> map)

Method Detail

onModuleback to summary
public void onModule(final ExtensionModule module)

Implements org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.ExtensionModuleListener.onModule.