View Javadoc

1   /*
2    * Copyright 2005 John G. Wilson
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package groovy.lang;
19  
20  import java.lang.reflect.Method;
21  import java.util.List;
22  
23  import org.codehaus.groovy.ast.ClassNode;
24  import org.codehaus.groovy.runtime.InvokerHelper;
25  
26  /***
27   * @author John Wilson
28   *
29   */
30  
31  public class DelegatingMetaClass extends MetaClass {
32      protected final MetaClass delegate;
33      
34      public DelegatingMetaClass(final MetaClass delegate) {
35          super(delegate.theClass);
36          
37          this.delegate = delegate;
38      }
39     
40      public DelegatingMetaClass(final Class theClass) {
41          this(new MetaClassImpl(InvokerHelper.getInstance().getMetaRegistry(), theClass));
42      }
43      
44      /* (non-Javadoc)
45       * @see groovy.lang.MetaClass#addNewInstanceMethod(java.lang.reflect.Method)
46       */
47      public void addNewInstanceMethod(Method method) {
48          delegate.addNewInstanceMethod(method);
49      }
50      /* (non-Javadoc)
51       * @see groovy.lang.MetaClass#addNewStaticMethod(java.lang.reflect.Method)
52       */
53      public void addNewStaticMethod(Method method) {
54          delegate.addNewStaticMethod(method);
55      }
56      /* (non-Javadoc)
57       * @see groovy.lang.MetaClass#initialize()
58       */
59      public void initialize() {
60          delegate.initialize();
61      }
62  
63      /* (non-Javadoc)
64       * @see groovy.lang.MetaClass#getAttribute(java.lang.Object, java.lang.String)
65       */
66      public Object getAttribute(Object object, String attribute) {
67          return delegate.getAttribute(object, attribute);
68      }
69      /* (non-Javadoc)
70       * @see groovy.lang.MetaClass#getClassNode()
71       */
72      public ClassNode getClassNode() {
73           return delegate.getClassNode();
74      }
75      /* (non-Javadoc)
76       * @see groovy.lang.MetaClass#getMetaMethods()
77       */
78      public List getMetaMethods() {
79          return delegate.getMetaMethods();
80      }
81      /* (non-Javadoc)
82       * @see groovy.lang.MetaClass#getMethods()
83       */
84      public List getMethods() {
85          return delegate.getMethods();
86      }
87      /* (non-Javadoc)
88       * @see groovy.lang.MetaClass#getProperties()
89       */
90      public List getProperties() {
91          return delegate.getProperties();
92      }
93      /* (non-Javadoc)
94       * @see groovy.lang.MetaClass#getProperty(java.lang.Object, java.lang.String)
95       */
96      public Object getProperty(Object object, String property) {
97          return delegate.getProperty(object, property);
98      }
99      /* (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 }