groovy.util
Class Proxy

java.lang.Object
  extended bygroovy.lang.GroovyObjectSupport
      extended bygroovy.util.Proxy
All Implemented Interfaces:
GroovyObject

public class Proxy
extends GroovyObjectSupport

Dynamic groovy proxy for another object. All property accesses and method invocations get forwarded to actual object, unless the proxy overrides it. The calling order can be set to try the real or proxy first.

Author:
Troy Heninger

Constructor Summary
Proxy(java.lang.Object real)
          Constructor.
Proxy(java.lang.Object real, boolean tryRealFirst)
          Constructor.
 
Method Summary
 MetaClass getMetaClass()
          Returns the MetaClass for the real object.
 java.lang.Object getProperty(java.lang.String property)
          Get the property of this proxy, or the real object if property doesn't exist.
 MetaClass getProxyMetaClass()
          Returns the MetaClass for the proxy object.
 java.lang.Object getRealObject()
          Returns the encapsulated object.
 java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)
          Call a method of this proxy, or the real object if method doesn't exist.
 void setMetaClass(MetaClass metaClass)
          Dynamically change the meta class to use for the real object.
 void setProperty(java.lang.String property, java.lang.Object newValue)
          Set the property of this proxy, or the real object if property doesn't exist.
 void setProxyMetaClass(MetaClass metaClass)
          Dynamically change the meta class to use for the proxy object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Proxy

public Proxy(java.lang.Object real)
Constructor. Takes real object to be excapsulated and set's the order to the real object first.

Parameters:
real - the real object

Proxy

public Proxy(java.lang.Object real,
             boolean tryRealFirst)
Constructor. Takes real object to be excapsulated and order.

Parameters:
real - the real object
tryRealFirst - call real object first if true
Method Detail

getProperty

public java.lang.Object getProperty(java.lang.String property)
Get the property of this proxy, or the real object if property doesn't exist.

Specified by:
getProperty in interface GroovyObject
Overrides:
getProperty in class GroovyObjectSupport
Parameters:
property - property to retrieve
Returns:
property's value

setProperty

public void setProperty(java.lang.String property,
                        java.lang.Object newValue)
Set the property of this proxy, or the real object if property doesn't exist.

Specified by:
setProperty in interface GroovyObject
Overrides:
setProperty in class GroovyObjectSupport
Parameters:
property - property to set
newValue - value to store

getMetaClass

public MetaClass getMetaClass()
Returns the MetaClass for the real object.

Specified by:
getMetaClass in interface GroovyObject
Overrides:
getMetaClass in class GroovyObjectSupport
Returns:
MetaClass of real object

getProxyMetaClass

public MetaClass getProxyMetaClass()
Returns the MetaClass for the proxy object.

Returns:
MetaClass of proxy object

getRealObject

public java.lang.Object getRealObject()
Returns the encapsulated object.

Returns:
the real object

invokeMethod

public java.lang.Object invokeMethod(java.lang.String name,
                                     java.lang.Object args)
Call a method of this proxy, or the real object if method doesn't exist.

Specified by:
invokeMethod in interface GroovyObject
Overrides:
invokeMethod in class GroovyObjectSupport
Parameters:
name - method to invoke
args - arguments to pass
Returns:

setMetaClass

public void setMetaClass(MetaClass metaClass)
Dynamically change the meta class to use for the real object.

Specified by:
setMetaClass in interface GroovyObject
Overrides:
setMetaClass in class GroovyObjectSupport
Parameters:
metaClass - substitute real meta class

setProxyMetaClass

public void setProxyMetaClass(MetaClass metaClass)
Dynamically change the meta class to use for the proxy object.

Parameters:
metaClass - substitute meta class for the proxy object


Copyright © 2003-2004 The Codehaus. All Rights Reserved.