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.MetaClass;
21
22
23 /***
24 * @author John Wilson
25 *
26 */
27
28 public class PojoWrapper extends Wrapper {
29 protected MetaClass delegate;
30 protected final Object wrapped;
31
32 public PojoWrapper(final Object wrapped, final Class constrainedType) {
33 super(constrainedType);
34 this.wrapped = wrapped;
35
36 /*
37 * This check is temporary - remove before 1.0 release
38 */
39 // if (wrapped instanceof GroovyObject) {
40 // throw new RuntimeException("trying to wrap the groovyObject "
41 // + wrapped.getClass().getName()
42 // + " in a PojoWrapper");
43 // }
44 }
45
46 public Object unwrap() {
47 return this.wrapped;
48 }
49
50 /***
51 * Note the rest of these method will only be used post 1.0
52 */
53
54 /* (non-Javadoc)
55 * @see groovy.lang.GroovyObject#getProperty(java.lang.String)
56 */
57 public Object getProperty(final String property) {
58 return this.delegate.getProperty(this.wrapped, property);
59 }
60
61 /* (non-Javadoc)
62 * @see groovy.lang.GroovyObject#invokeMethod(java.lang.String, java.lang.Object)
63 */
64 public Object invokeMethod(final String methodName, final Object arguments) {
65 return this.delegate.invokeMethod(this.wrapped, methodName, arguments);
66 }
67
68 /* (non-Javadoc)
69 * @see groovy.lang.GroovyObject#setMetaClass(groovy.lang.MetaClass)
70 */
71 public void setMetaClass(final MetaClass metaClass) {
72 this.delegate = metaClass;
73 }
74
75 /* (non-Javadoc)
76 * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object)
77 */
78 public void setProperty(final String property, final Object newValue) {
79 this.delegate.setProperty(this.wrapped, property, newValue);
80 }
81
82 protected Object getWrapped() {
83 return this.wrapped;
84 }
85
86 protected MetaClass getDelegatedMetaClass() {
87 return this.delegate;
88 }
89 }