001    /*
002     * Copyright 2005 John G. Wilson
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     *
016     */
017    
018    package groovy.lang;
019    
020    import java.lang.reflect.Method;
021    import java.util.List;
022    
023    import org.codehaus.groovy.ast.ClassNode;
024    import org.codehaus.groovy.runtime.InvokerHelper;
025    
026    /**
027     * @author John Wilson
028     *
029     */
030    
031    public class DelegatingMetaClass extends MetaClass {
032        protected final MetaClass delegate;
033        
034        public DelegatingMetaClass(final MetaClass delegate) {
035            super(delegate.theClass);
036            
037            this.delegate = delegate;
038        }
039       
040        public DelegatingMetaClass(final Class theClass) {
041            this(new MetaClassImpl(InvokerHelper.getInstance().getMetaRegistry(), theClass));
042        }
043        
044        /* (non-Javadoc)
045         * @see groovy.lang.MetaClass#addNewInstanceMethod(java.lang.reflect.Method)
046         */
047        public void addNewInstanceMethod(Method method) {
048            delegate.addNewInstanceMethod(method);
049        }
050        /* (non-Javadoc)
051         * @see groovy.lang.MetaClass#addNewStaticMethod(java.lang.reflect.Method)
052         */
053        public void addNewStaticMethod(Method method) {
054            delegate.addNewStaticMethod(method);
055        }
056        /* (non-Javadoc)
057         * @see groovy.lang.MetaClass#initialize()
058         */
059        public void initialize() {
060            delegate.initialize();
061        }
062    
063        /* (non-Javadoc)
064         * @see groovy.lang.MetaClass#getAttribute(java.lang.Object, java.lang.String)
065         */
066        public Object getAttribute(Object object, String attribute) {
067            return delegate.getAttribute(object, attribute);
068        }
069        /* (non-Javadoc)
070         * @see groovy.lang.MetaClass#getClassNode()
071         */
072        public ClassNode getClassNode() {
073             return delegate.getClassNode();
074        }
075        /* (non-Javadoc)
076         * @see groovy.lang.MetaClass#getMetaMethods()
077         */
078        public List getMetaMethods() {
079            return delegate.getMetaMethods();
080        }
081        /* (non-Javadoc)
082         * @see groovy.lang.MetaClass#getMethods()
083         */
084        public List getMethods() {
085            return delegate.getMethods();
086        }
087        /* (non-Javadoc)
088         * @see groovy.lang.MetaClass#getProperties()
089         */
090        public List getProperties() {
091            return delegate.getProperties();
092        }
093        /* (non-Javadoc)
094         * @see groovy.lang.MetaClass#getProperty(java.lang.Object, java.lang.String)
095         */
096        public Object getProperty(Object object, String property) {
097            return delegate.getProperty(object, property);
098        }
099        /* (non-Javadoc)
100         * @see groovy.lang.MetaClass#invokeConstructor(java.lang.Object[])
101         */
102        public Object invokeConstructor(Object[] arguments) {
103            return delegate.invokeConstructor(arguments);
104        }
105    
106        /* (non-Javadoc)
107         * @see groovy.lang.MetaClass#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object)
108         */
109        public Object invokeMethod(Object object, String methodName, Object arguments) {
110            return delegate.invokeMethod(object, methodName, arguments);
111        }
112        /* (non-Javadoc)
113         * @see groovy.lang.MetaClass#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object[])
114         */
115        public Object invokeMethod(Object object, String methodName, Object[] arguments) {
116            return delegate.invokeMethod(object, methodName, arguments);
117        }
118        /* (non-Javadoc)
119         * @see groovy.lang.MetaClass#invokeStaticMethod(java.lang.Object, java.lang.String, java.lang.Object[])
120         */
121        public Object invokeStaticMethod(Object object, String methodName, Object[] arguments) {
122            return delegate.invokeStaticMethod(object, methodName, arguments);
123        }
124    
125        /* (non-Javadoc)
126         * @see groovy.lang.MetaClass#setAttribute(java.lang.Object, java.lang.String, java.lang.Object)
127         */
128        public void setAttribute(Object object, String attribute, Object newValue) {
129            delegate.setAttribute(object, attribute, newValue);
130        }
131        /* (non-Javadoc)
132         * @see groovy.lang.MetaClass#setProperty(java.lang.Object, java.lang.String, java.lang.Object)
133         */
134        public void setProperty(Object object, String property, Object newValue) {
135            delegate.setProperty(object, property, newValue);
136        }
137        /* (non-Javadoc)
138         * @see java.lang.Object#equals(java.lang.Object)
139         */
140        public boolean equals(Object obj) {
141            return delegate.equals(obj);
142        }
143        /* (non-Javadoc)
144         * @see java.lang.Object#hashCode()
145         */
146        public int hashCode() {
147            return delegate.hashCode();
148        }
149        /* (non-Javadoc)
150         * @see java.lang.Object#toString()
151         */
152        public String toString() {
153            return delegate.toString();
154        }
155        /**
156         * @deprecated
157         */
158        public MetaMethod pickMethod(String methodName, Class[] arguments) {
159            return delegate.pickMethod(methodName,arguments);
160        }
161        /**
162         * @deprecated
163         */
164        protected MetaMethod retrieveMethod(String methodName, Class[] arguments) {
165            return delegate.retrieveMethod(methodName,arguments);
166        }
167    }