Top Description Inners Methods
groovy.lang

public Interface MetaClassRegistry

Known Direct Implementers
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl
Imports
org.codehaus.groovy.runtime.GeneratedClosure, org.codehaus.groovy.runtime.metaclass.ClosureMetaClass, java.lang.reflect.Constructor, java.util.Iterator

A MetaClassRegistry is an object that is responsible for managing the a cache of MetaClass instances. Each java.lang.Class instance has an associated MetaClass and client code can query this interface for the MetaClass for a given associated java.lang.Class
See Also
groovy.lang.MetaClass

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MetaClassRegistry.MetaClassCreationHandle

Class used as base for the creation of MetaClass implementations.

Method Summary

Modifier and TypeMethod and Description
public void
addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener
- the update listener
listener
)

Adds a meta class change listener for constant meta classes

public void
addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener
- the update listener
listener
)

Adds a meta class change listener for constant meta classes.

public MetaClass
getMetaClass(Class<T> 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 it

public MetaClassRegistry.MetaClassCreationHandle

Returns:

The MetaClassCreationHandle instance
getMetaClassCreationHandler
()

Retrieves the MetaClassCreationHandle that is responsible for constructing MetaClass instances

public MetaClassRegistryChangeEventListener[]

Returns:

an array containing all change listener
getMetaClassRegistryChangeEventListeners
()

Returns all registered class change listener for constant meta classes.

public Iterator<E>

Returns:

Iterator for the constant meta classes
iterator
()

Gets a snapshot of the current constant meta classes and returns it as Iterator.

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

Removes a cached MetaClass from the registry

public void
removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener
- the update listener
listener
)

Removes a meta class change listener for constant meta classes

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

Adds a metaclass to the registry for the given class

public void
setMetaClassCreationHandle(MetaClassRegistry.MetaClassCreationHandle
The handle instance
handle
)

Sets the MetaClassCreationHandle instance that is responsible for constructing instances

Method Detail

addMetaClassRegistryChangeEventListenerback to summary
public void addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

Adds a meta class change listener for constant meta classes

Parameters
listener:MetaClassRegistryChangeEventListener

- the update listener

addNonRemovableMetaClassRegistryChangeEventListenerback to summary
public void addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

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

Parameters
listener:MetaClassRegistryChangeEventListener

- the update listener

getMetaClassback to summary
public MetaClass getMetaClass(Class<T> 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 it

getMetaClassCreationHandlerback to summary
public MetaClassRegistry.MetaClassCreationHandle getMetaClassCreationHandler()

Retrieves the MetaClassCreationHandle that is responsible for constructing MetaClass instances

Returns:MetaClassRegistry.MetaClassCreationHandle

The MetaClassCreationHandle instance

getMetaClassRegistryChangeEventListenersback to summary
public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners()

Returns all registered class change listener for constant meta classes.

Returns:MetaClassRegistryChangeEventListener[]

an array containing all change listener

iteratorback to summary
public Iterator<E> iterator()

Gets a snapshot of the current constant meta classes and returns it as Iterator. Modifications done using this Iterator will not cause a ConcurrentModificationException. If a MetaClass is removed using this Iterator, then the MetaClass will only be removed if the MetaClass was not replaced by another MetaClass in the meantime. If a MetaClass is added while using this Iterator, then it will be part of the Iteration. If a MetaClass replaces another constant meta class, then the Iteration might show two meta classes for the same class.

Note

This Iterator may not used with multiple threads.

Returns:Iterator<E>

Iterator for the constant meta classes

removeMetaClassback to summary
public void removeMetaClass(Class<T> theClass)

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)

Removes a meta class change listener for constant meta classes

Parameters
listener:MetaClassRegistryChangeEventListener

- the update listener

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

Adds a metaclass to the registry for the given class

Parameters
theClass:Class<T>

The class

theMetaClass:MetaClass

The MetaClass for theClass

setMetaClassCreationHandleback to summary
public void setMetaClassCreationHandle(MetaClassRegistry.MetaClassCreationHandle handle)

Sets the MetaClassCreationHandle instance that is responsible for constructing instances

Parameters
handle:MetaClassRegistry.MetaClassCreationHandle

The handle instance

groovy.lang back to summary

public Class MetaClassRegistry.MetaClassCreationHandle

extends Object
Class Inheritance
Known Direct Subclasses
groovy.lang.ExpandoMetaClassCreationHandle

Class used as base for the creation of MetaClass implementations. The Class defaults to MetaClassImpl, if the class loading fails to find a special meta class. The name for such a meta class would be the class name it is created for with the prefix "groovy.runtime.metaclass." By replacing the handle in the registry you can have any control over the creation of what MetaClass is used for a class that you want to have.

Warning

experimental code, likely to change soon

Field Summary

Modifier and TypeField and Description
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final MetaClass
create(Class<T>
The class to create a metaclass for
theClass
,
MetaClassRegistry
The metaclass registry the metaclass we be registered in.
registry
)

Creates a metaclass implementation for theClass.

protected MetaClass
private MetaClass
public boolean
isDisableCustomMetaClassLookup()

Returns whether custom meta classes are disabled.

public void
setDisableCustomMetaClassLookup(boolean
flag saying to disable lookup of custom meta classes
disableCustomMetaClassLookup
)

Set flag saying to disable lookup of custom meta classes It's enough to call this method only once in your application for handle which was set in to registry as every new handle will inherit this property

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

disableCustomMetaClassLookupback to summary
private boolean disableCustomMetaClassLookup

Constructor Detail

MetaClassCreationHandleback to summary
public MetaClassCreationHandle()

Method Detail

createback to summary
public final MetaClass create(Class<T> theClass, MetaClassRegistry registry)

Creates a metaclass implementation for theClass.

Parameters
theClass:Class<T>

The class to create a metaclass for

registry:MetaClassRegistry

The metaclass registry the metaclass we be registered in.

createNormalMetaClassback to summary
protected MetaClass createNormalMetaClass(Class<T> theClass, MetaClassRegistry registry)
createWithCustomLookupback to summary
private MetaClass createWithCustomLookup(Class<T> theClass, MetaClassRegistry registry)
isDisableCustomMetaClassLookupback to summary
public boolean isDisableCustomMetaClassLookup()

Returns whether custom meta classes are disabled.

setDisableCustomMetaClassLookupback to summary
public void setDisableCustomMetaClassLookup(boolean disableCustomMetaClassLookup)

Set flag saying to disable lookup of custom meta classes It's enough to call this method only once in your application for handle which was set in to registry as every new handle will inherit this property

Parameters
disableCustomMetaClassLookup:boolean

flag saying to disable lookup of custom meta classes