org.codehaus.groovy.runtime.metaclass
Class MetaClassRegistryImpl

java.lang.Object
  extended by org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl
All Implemented Interfaces:
MetaClassRegistry

public class MetaClassRegistryImpl
extends java.lang.Object
implements MetaClassRegistry

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

Version:
$Revision: 10896 $
Author:
James Strachan, John Wilson, Jochen Theodorou, Graeme Rocher, Alex Tkachman

Nested Class Summary
private  class MetaClassRegistryImpl.LocallyKnownClasses
           
private  class MetaClassRegistryImpl.MyThreadLocal
           
 
Nested classes/interfaces inherited from interface groovy.lang.MetaClassRegistry
MetaClassRegistry.MetaClassCreationHandle
 
Field Summary
private  int constantMetaClassCount
           
private  ConcurrentReaderHashMap constantMetaClasses
           
static int DONT_LOAD_DEFAULT
           
private static MetaClassRegistry instanceExclude
           
private static MetaClassRegistry instanceInclude
           
private  FastArray instanceMethods
           
static int LOAD_DEFAULT
           
private  MemoryAwareConcurrentReadMap loaderMap
           
private  MetaClassRegistryImpl.MyThreadLocal locallyKnown
           
private  MetaClassRegistry.MetaClassCreationHandle metaClassCreationHandle
           
private  FastArray staticMethods
           
private  boolean useAccessible
           
private  java.lang.Integer version
           
private  MemoryAwareConcurrentReadMap weakMetaClasses
           
 
Constructor Summary
MetaClassRegistryImpl()
           
MetaClassRegistryImpl(boolean useAccessible)
           
MetaClassRegistryImpl(int loadDefault)
           
MetaClassRegistryImpl(int loadDefault, boolean useAccessible)
           
 
Method Summary
private  MetaClass getGlobalMetaClass(java.lang.Class theClass)
           
static MetaClassRegistry getInstance(int includeExtension)
          Singleton of MetaClassRegistry.
 FastArray getInstanceMethods()
           
 MetaClass getMetaClass(java.lang.Class theClass)
           
 MetaClassRegistry.MetaClassCreationHandle getMetaClassCreationHandler()
          Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon
 FastArray getStaticMethods()
           
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
private  void registerMethods(java.lang.Class theClass, boolean useInstanceMethods, java.util.Map map)
           
 void removeMetaClass(java.lang.Class theClass)
          Removes a cached MetaClass from the registry
 void setMetaClass(java.lang.Class theClass, MetaClass theMetaClass)
          Registers a new MetaClass in the registry to customize the type
 void setMetaClassCreationHandle(MetaClassRegistry.MetaClassCreationHandle handle)
          Sets a handle internally used to create MetaClass implementations.
 boolean useAccessible()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constantMetaClassCount

private volatile int constantMetaClassCount

constantMetaClasses

private ConcurrentReaderHashMap constantMetaClasses

weakMetaClasses

private MemoryAwareConcurrentReadMap weakMetaClasses

loaderMap

private MemoryAwareConcurrentReadMap loaderMap

useAccessible

private boolean useAccessible

instanceMethods

private FastArray instanceMethods

staticMethods

private FastArray staticMethods

version

private volatile java.lang.Integer version

locallyKnown

private MetaClassRegistryImpl.MyThreadLocal locallyKnown

LOAD_DEFAULT

public static final int LOAD_DEFAULT
See Also:
Constant Field Values

DONT_LOAD_DEFAULT

public static final int DONT_LOAD_DEFAULT
See Also:
Constant Field Values

instanceInclude

private static MetaClassRegistry instanceInclude

instanceExclude

private static MetaClassRegistry instanceExclude

metaClassCreationHandle

private MetaClassRegistry.MetaClassCreationHandle metaClassCreationHandle
Constructor Detail

MetaClassRegistryImpl

public MetaClassRegistryImpl()

MetaClassRegistryImpl

public MetaClassRegistryImpl(int loadDefault)

MetaClassRegistryImpl

public MetaClassRegistryImpl(boolean useAccessible)
Parameters:
useAccessible - defines whether or not the AccessibleObject.setAccessible(boolean) method will be called to enable access to all methods when using reflection

MetaClassRegistryImpl

public MetaClassRegistryImpl(int loadDefault,
                             boolean useAccessible)
Method Detail

installMetaClassCreationHandle

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:
MetaClassRegistry.MetaClassCreationHandle

registerMethods

private void registerMethods(java.lang.Class theClass,
                             boolean useInstanceMethods,
                             java.util.Map map)

getGlobalMetaClass

private MetaClass getGlobalMetaClass(java.lang.Class theClass)

getMetaClass

public MetaClass getMetaClass(java.lang.Class theClass)
Specified by:
getMetaClass in interface MetaClassRegistry

removeMetaClass

public void removeMetaClass(java.lang.Class theClass)
Description copied from interface: MetaClassRegistry
Removes a cached MetaClass from the registry

Specified by:
removeMetaClass in interface MetaClassRegistry
Parameters:
theClass - The Java class of the MetaClass to remove

setMetaClass

public void setMetaClass(java.lang.Class theClass,
                         MetaClass theMetaClass)
Registers a new MetaClass in the registry to customize the type

Specified by:
setMetaClass in interface MetaClassRegistry
Parameters:
theClass -
theMetaClass -

useAccessible

public boolean useAccessible()

getMetaClassCreationHandler

public MetaClassRegistry.MetaClassCreationHandle getMetaClassCreationHandler()
Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon

Specified by:
getMetaClassCreationHandler in interface MetaClassRegistry
Returns:
the handle

setMetaClassCreationHandle

public void setMetaClassCreationHandle(MetaClassRegistry.MetaClassCreationHandle handle)
Sets a handle internally used to create MetaClass implementations. When replacing the handle with a custom version, you should resuse the old handle to keep custom logic and to use the default logic as fallback. WARNING: experimental code, likely to change soon

Specified by:
setMetaClassCreationHandle in interface MetaClassRegistry
Parameters:
handle - the handle

getInstance

public static MetaClassRegistry getInstance(int includeExtension)
Singleton of MetaClassRegistry. Shall we use threadlocal to store the instance?

Parameters:
includeExtension -

getInstanceMethods

public FastArray getInstanceMethods()

getStaticMethods

public FastArray getStaticMethods()


Copyright © ${year} The Codehaus. All Rights Reserved.