/*
 * Copyright 2004-2005 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package grails.util;

import org.codehaus.groovy.runtime.InvokerHelper;

import groovy.lang.MissingPropertyException;
import groovy.util.Proxy;
/** 
 * Extends the Groovy Proxy implementation and adds proxying of property getters/setters
 * 
* @author Graeme Rocher
* @since Oct 20, 2005
*/
public class ExtendProxy extends Proxy {

	public Object getProperty(String property) {
		try {			
			return super.getProperty(property);
		}
		catch(MissingPropertyException mpe) {
			return InvokerHelper.getMetaClass(getAdaptee()).getProperty(getAdaptee(),property);
		}
	}

	public void setProperty(String property, Object newValue) {
		try {			
			super.setProperty(property,newValue);
		}
		catch(MissingPropertyException mpe) {
			InvokerHelper.getMetaClass(getAdaptee()).setProperty(getAdaptee(),property,newValue);
		}
	}
	
	

}

@@ -766,12 +766,42 @@
 xy;%0A
+%0Aimport java.util.Collection;%0A%0A
 /**
- 
 %0A * 
@@ -914,16 +914,47 @@
  Rocher%0A
+* @author Jonathan Carlson%0A * %0A
 * @since
@@ -1012,17 +1012,20 @@
 roxy %7B%0A%0A
-%09
+    
 public O
@@ -1061,30 +1061,42 @@
 erty) %7B%0A
-%09%09try %7B%09%09%09%0A%09%09%09
+        try %7B%0A            
 return s
@@ -1123,22 +1123,34 @@
 perty);%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 catch(Mi
@@ -1179,19 +1179,28 @@
  mpe) %7B%0A
-%09%09%09
+            
 return I
@@ -1279,17 +1279,29 @@
 y);%0A
-%09%09%7D%0A%09%7D%0A%0A%09
+        %7D%0A    %7D%0A%0A    
 publ
@@ -1360,22 +1360,34 @@
 ) %7B%0A
-%09%09try %7B%09%09%09%0A%09%09%09
+        try %7B%0A            
 supe
@@ -1424,14 +1424,26 @@
 e);%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 catc
@@ -1480,11 +1480,20 @@
 ) %7B%0A
-%09%09%09
+            
 Invo
@@ -1578,18 +1578,569 @@
 e);%0A
-%09%09%7D%0A%09%7D%0A%09%0A%09
+        %7D%0A    %7D%0A%0A    /**%0A     * This method allows transparent iterating over an adapted collection.%0A     * The previous behavior was to return the adaptee instead of the iterator()%0A     * when iterator()was called so this keeps that behavior for non-collections.%0A     * @return either an Iterator (if adaptee is a collection) or this.%0A     *%0A     */%0A    public Object iterator() %7B%0A        if(getAdaptee() instanceof Collection) %7B%0A           return ((Collection)getAdaptee()).iterator();%0A        %7D%0A        else %7B%0A            return getAdaptee();%0A        %7D%0A    %7D
 %0A%0A%7D%0A

Patch from Jason to allow iteration over a proxy