home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (MutableMetaClass.java)

This example Groovy source code file (MutableMetaClass.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

metaclass, metaclass, mutablemetaclass, mutablemetaclass, reflection

The Groovy MutableMetaClass.java source code

/*
 * 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;

import java.lang.reflect.Method;

/**
 * <p>An interface that defines methods that implementers of mutable Meta classes should specify. It provides operations to perform mutations
 * on the MetaClass instance.</p>
 *
 * <p>Whether a MetaClass allows mutation is up to the MetaClass itself and considerations of Thread safety
 * need to be taken into account when making a MetaClass mutable</p>
 *
 * <p>The default implementation allows mutation of MetaClass instances before initialisation (before the initialize() method is called)
 * but not after, thus ensuring Thread safety once a MetaClass has been constructed and placed in the registry</p>
 *
 * @see MetaClassImpl
 * @see MetaClass
 *
 * @author Graeme Rocher
 * @since 1.5
 */
public interface MutableMetaClass extends MetaClass {

    /**
     * Return whether the MetaClass has been modified or not
     * @return True if it has
     */
    boolean isModified();

    /**
     * adds a new instance method to this MetaClass. Instance
     * methods are able to overwrite the original methods of the
     * class. Calling this method should not be done after
     * initialise was called.
     *
     * @param method the method to be added
     */
     void addNewInstanceMethod(Method method);

    /**
     * adds a new static method to this MetaClass. This is only
     * possible as long as initialise was not called.
     *
     * @param method the method to be added
     */
     void addNewStaticMethod(Method method);

    /**
     * Adds a new MetaMethod to the MetaClass
     *
     * @param metaMethod The MetaMethod to add
     */
    void addMetaMethod(MetaMethod metaMethod);

    /**
     * Adds a new MetaBeanProperty to the MetaClass
     *
     * @param metaBeanProperty The MetaBeanProperty instance
     */
    void addMetaBeanProperty(MetaBeanProperty metaBeanProperty);
    
    // TODO: Add methods like addMetaConstructor, addMetaAttribute, addMetaAnnotation etc.
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy MutableMetaClass.java source code file:

new blog posts

 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.