View Javadoc

    1   /*
    2    * Copyright 2006 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 org.codehaus.groovy.runtime.wrappers;
    19
    20  import groovy.lang.GroovyObject;
    21  import groovy.lang.MetaClass;
    22
    23  /***
    24   * @author John Wilson
    25   *
    26   */
    27
    28  public class GroovyObjectWrapper extends Wrapper {
    29    protected final GroovyObject wrapped;
    30
    31    public GroovyObjectWrapper(final GroovyObject wrapped, final Class constrainedType) {
    32      super(constrainedType);
    33      this.wrapped = wrapped;
    34    }
    35
    36    public Object unwrap() {
    37      return this.wrapped;
    38    }
    39
    40    /***
    41     * Note the rest of these method will only be used post 1.0
    42     */
    43
    44    /* (non-Javadoc)
    45     * @see groovy.lang.GroovyObject#getProperty(java.lang.String)
    46     */
    47    public Object getProperty(final String property) {
    48      return this.wrapped.getProperty(property);
    49    }
    50
    51    /* (non-Javadoc)
    52     * @see groovy.lang.GroovyObject#invokeMethod(java.lang.String, java.lang.Object)
    53     */
    54    public Object invokeMethod(final String name, final Object args) {
    55      return this.wrapped.invokeMethod(name, args);
    56    }
    57
    58    /* (non-Javadoc)
    59     * @see groovy.lang.GroovyObject#setMetaClass(groovy.lang.MetaClass)
    60     */
    61    public void setMetaClass(final MetaClass metaClass) {
    62      this.wrapped.setMetaClass(metaClass);
    63    }
    64
    65    /* (non-Javadoc)
    66     * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object)
    67     */
    68    public void setProperty(final String property, final Object newValue) {
    69      this.wrapped.setProperty(property, newValue);
    70    }
    71
    72    protected Object getWrapped() {
    73      return this.wrapped;
    74    }
    75
    76    protected MetaClass getDelegatedMetaClass() {
    77      return this.wrapped.getMetaClass();
    78    }
    79  }