| Method from org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl Detail: |
public void addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener) {
synchronized (changeListenerList) {
changeListenerList.add(listener);
}
}
Adds a listener for constant meta classes. |
protected void fireConstantMetaClassUpdate(Class c,
MetaClass newMc) {
MetaClassRegistryChangeEventListener[] listener = getMetaClassRegistryChangeEventListeners();
MetaClassRegistryChangeEvent cmcu = new MetaClassRegistryChangeEvent(this,c,newMc);
for (int i=0; i< listener.length; i++) {
listener[i].updateConstantMetaClass(cmcu);
}
}
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. |
public static MetaClassRegistry getInstance(int includeExtension) {
if (includeExtension != DONT_LOAD_DEFAULT) {
if (instanceInclude == null) {
instanceInclude = new MetaClassRegistryImpl();
}
return instanceInclude;
} else {
if (instanceExclude == null) {
instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT);
}
return instanceExclude;
}
}
Singleton of MetaClassRegistry. |
public FastArray getInstanceMethods() {
return instanceMethods;
}
|
public final MetaClass getMetaClass(Class theClass) {
return ClassInfo.getClassInfo(theClass).getMetaClass();
}
|
public MetaClass getMetaClass(Object obj) {
return ClassInfo.getClassInfo(obj.getClass()).getMetaClass(obj);
}
|
public MetaClassCreationHandle getMetaClassCreationHandler() {
return metaClassCreationHandle;
}
Gets a handle internally used to create MetaClass implementations
WARNING: experimental code, likely to change soon |
public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() {
synchronized (changeListenerList) {
return (MetaClassRegistryChangeEventListener[]) changeListenerList.toArray(new MetaClassRegistryChangeEventListener[0]);
}
}
Gets an array of of all registered ConstantMetaClassListener instances. |
public FastArray getStaticMethods() {
return staticMethods;
}
|
public Iterator iterator() {
final MetaClass[] refs;
synchronized (metaClassInfo) {
refs = (MetaClass[]) metaClassInfo.toArray(new MetaClass[0]);
}
return new Iterator() {
// index in the ref array
private int index=0;
// the current meta class
private MetaClass currentMeta;
// used to ensure that hasNext has been called
private boolean hasNextCalled=false;
// the cached hasNext call value
private boolean hasNext=false;
public boolean hasNext() {
if (hasNextCalled) return hasNext;
hasNextCalled = true;
if(index < refs.length) {
hasNext=true;
currentMeta= refs[index];
index++;
} else {
hasNext=false;
}
return hasNext;
}
private void ensureNext() {
// we ensure that hasNext has been called before
// next is called
hasNext();
hasNextCalled=false;
}
public Object next() {
ensureNext();
return currentMeta;
}
public void remove() {
ensureNext();
setMetaClass(currentMeta.getTheClass(),currentMeta,null);
currentMeta=null;
}
};
}
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. |
public void removeMetaClass(Class theClass) {
setMetaClass(theClass, null, null);
}
|
public void removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener) {
synchronized (changeListenerList) {
Object first = changeListenerList.getFirst();
changeListenerList.remove(listener);
// we want to keep the first entry!
if (changeListenerList.size()==0) changeListenerList.addFirst(first);
}
}
Removes a constant meta class listener. |
public void setMetaClass(Class theClass,
MetaClass theMetaClass) {
setMetaClass(theClass,null,theMetaClass);
}
Registers a new MetaClass in the registry to customize the type |
public void setMetaClass(Object obj,
MetaClass theMetaClass) {
Class theClass = obj.getClass ();
final ClassInfo info = ClassInfo.getClassInfo(theClass);
info.lock();
try {
info.setPerInstanceMetaClass(obj, theMetaClass);
}
finally {
info.unlock();
}
fireConstantMetaClassUpdate(theClass, theMetaClass);
}
|
public void setMetaClassCreationHandle(MetaClassCreationHandle handle) {
if(handle == null) throw new IllegalArgumentException("Cannot set MetaClassCreationHandle to null value!");
ClassInfo.clearModifiedExpandos();
metaClassCreationHandle = handle;
}
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 |
public boolean useAccessible() {
return useAccessible;
}
|