Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2003-2007 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package groovy.lang;

A handle for the MetaClassRegistry that changes all classes loaded into the Grails VM to use ExpandoMetaClass instances

The handle should be registered with the Groovy runtime before Groovy loads, for example in your main method. GroovySystem.metaClassRegistry.metaClassCreationHandle = new ExpandoMetaClassCreationHandle()

	/* (non-Javadoc)
	 * @see groovy.lang.MetaClassRegistry.MetaClassCreationHandle#create(java.lang.Class, groovy.lang.MetaClassRegistry)
	 */
	protected MetaClass createNormalMetaClass(Class theClassMetaClassRegistry registry) {
		if(theClass != ExpandoMetaClass.class) {
			return new ExpandoMetaClass(theClasstruetrue);
		}
		else {
			return super.create(theClassregistry);
		}
	}

    
Registers a modified ExpandoMetaClass with the creation handle

Parameters:
emc The EMC
    public void registerModifiedMetaClass(ExpandoMetaClass emc) {
        final Class klazz = emc.getJavaClass();
        GroovySystem.getMetaClassRegistry().setMetaClass(klazz,emc);
    }
	public boolean hasModifiedMetaClass(ExpandoMetaClass emc) {
		return emc.getClassInfo().getModifiedExpando() != null;
	}

    

Enables the ExpandoMetaClassCreationHandle with the registry ExpandoMetaClassCreationHandle.enable();

    public static void enable() {
        final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
        synchronized (metaClassRegistry) {
            if (metaClassRegistry.getMetaClassCreationHandler() != ) {
                ClassInfo.clearModifiedExpandos();
                metaClassRegistry.setMetaClassCreationHandle();
            }
        }
    }
    public static void disable() {
        final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
        synchronized (metaClassRegistry) {
            if (metaClassRegistry.getMetaClassCreationHandler() == ) {
                ClassInfo.clearModifiedExpandos();
                metaClassRegistry.setMetaClassCreationHandle(new MetaClassCreationHandle());
            }
        }
    }
New to GrepCode? Check out our FAQ X