01: /*
02: * Copyright 2006 John G. Wilson
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * @author John Wilson
24: *
25: */
26:
27: public class PojoWrapper extends Wrapper {
28: protected MetaClass delegate;
29: protected final Object wrapped;
30:
31: public PojoWrapper(final Object wrapped, final Class constrainedType) {
32: super (constrainedType);
33: this .wrapped = wrapped;
34:
35: /*
36: * This check is temporary - remove before 1.0 release
37: */
38: // if (wrapped instanceof GroovyObject) {
39: // throw new RuntimeException("trying to wrap the groovyObject "
40: // + wrapped.getClass().getName()
41: // + " in a PojoWrapper");
42: // }
43: }
44:
45: public Object unwrap() {
46: return this .wrapped;
47: }
48:
49: /**
50: * Note the rest of these method will only be used post 1.0
51: */
52:
53: /* (non-Javadoc)
54: * @see groovy.lang.GroovyObject#getProperty(java.lang.String)
55: */
56: public Object getProperty(final String property) {
57: return this .delegate.getProperty(this .wrapped, property);
58: }
59:
60: /* (non-Javadoc)
61: * @see groovy.lang.GroovyObject#invokeMethod(java.lang.String, java.lang.Object)
62: */
63: public Object invokeMethod(final String methodName,
64: final Object arguments) {
65: return this .delegate.invokeMethod(this .wrapped, methodName,
66: arguments);
67: }
68:
69: /* (non-Javadoc)
70: * @see groovy.lang.GroovyObject#setMetaClass(groovy.lang.MetaClass)
71: */
72: public void setMetaClass(final MetaClass metaClass) {
73: this .delegate = metaClass;
74: }
75:
76: /* (non-Javadoc)
77: * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object)
78: */
79: public void setProperty(final String property, final Object newValue) {
80: this .delegate.setProperty(this .wrapped, property, newValue);
81: }
82:
83: protected Object getWrapped() {
84: return this .wrapped;
85: }
86:
87: protected MetaClass getDelegatedMetaClass() {
88: return this.delegate;
89: }
90: }
|