org.apache.ojb.broker.core.proxy
Class AbstractProxyFactory

java.lang.Object
  extended by org.apache.ojb.broker.core.proxy.AbstractProxyFactory
All Implemented Interfaces:
java.io.Serializable, ProxyFactory
Direct Known Subclasses:
ProxyFactoryCGLIBImpl, ProxyFactoryJDKImpl

public abstract class AbstractProxyFactory
extends java.lang.Object
implements ProxyFactory

Abstract implementation for the ProxyFactory

Version:
$Id:
Author:
andrew.clute
See Also:
Serialized Form

Constructor Summary
AbstractProxyFactory()
           
 
Method Summary
 ManageableCollection createCollectionProxy(PBKey brokerKey, Query query, java.lang.Class collectionClass)
          Create a Collection Proxy for a given query.
 IndirectionHandler createIndirectionHandler(PBKey brokerKey, Identity id)
          Creates a new indirection handler instance.
 CollectionProxy getCollectionProxy(java.lang.Object item)
          Return CollectionProxy for item is item is a CollectionProxy, otherwise return null
 java.lang.Class getCollectionProxyClass()
          Returns the collection proxy class.
 IndirectionHandler getIndirectionHandler(java.lang.Object obj)
          Returns the invocation handler object of the given proxy object.
 java.lang.Class getIndirectionHandlerClass()
          Returns the indirection handler class.
 java.lang.Class getListProxyClass()
          Returns the list proxy class.
static ProxyFactory getProxyFactory()
           
 java.lang.Class getRealClass(java.lang.Object objectOrProxy)
          Get the real Class
 java.lang.Object getRealObject(java.lang.Object objectOrProxy)
          Get the real Object
 java.lang.Object getRealObjectIfMaterialized(java.lang.Object objectOrProxy)
          Get the real Object for already materialized Handler
 java.lang.Class getSetProxyClass()
          Returns the set proxy class.
 boolean isCollectionProxy(java.lang.Object item)
          Reports if item is a CollectionProxy.
 boolean isMaterialized(java.lang.Object object)
          Determines whether the object is a materialized object, i.e. no proxy or a proxy that has already been loaded from the database.
 boolean isNormalOjbProxy(java.lang.Object proxyOrObject)
          Determines whether the given object is an OJB proxy.
 boolean isProxy(java.lang.Object proxyOrObject)
          Returns true if the given object is a Proxy or a VirtualProxy instance.
 boolean isVirtualOjbProxy(java.lang.Object proxyOrObject)
          Determines whether the given object is an OJB virtual proxy.
 void setCollectionProxyClass(java.lang.Class collectionProxyClass)
          Dets the proxy class to use for generic collection classes implementing the Collection interface.
 void setIndirectionHandlerClass(java.lang.Class indirectionHandlerClass)
          Sets the indirection handler class.
 void setListProxyClass(java.lang.Class listProxyClass)
          Dets the proxy class to use for collection classes that implement the List interface.
 void setSetProxyClass(java.lang.Class setProxyClass)
          Dets the proxy class to use for collection classes that implement the Set interface.
 java.lang.String toString(java.lang.Object proxy)
          Materialization-safe version of toString.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.ojb.broker.core.proxy.ProxyFactory
createProxy, getDefaultIndirectionHandlerClass, getIndirectionHandlerBaseClass, interfaceRequiredForProxyGeneration
 

Constructor Detail

AbstractProxyFactory

public AbstractProxyFactory()
Method Detail

getIndirectionHandlerClass

public java.lang.Class getIndirectionHandlerClass()
Returns the indirection handler class.

Specified by:
getIndirectionHandlerClass in interface ProxyFactory
Returns:
The class for indirection handlers

setIndirectionHandlerClass

public void setIndirectionHandlerClass(java.lang.Class indirectionHandlerClass)
Sets the indirection handler class.

Specified by:
setIndirectionHandlerClass in interface ProxyFactory
Parameters:
indirectionHandlerClass - The class for indirection handlers

createIndirectionHandler

public IndirectionHandler createIndirectionHandler(PBKey brokerKey,
                                                   Identity id)
Creates a new indirection handler instance.

Specified by:
createIndirectionHandler in interface ProxyFactory
Parameters:
brokerKey - The associated PBKey.
id - The subject's ids
Returns:
The new instance

getListProxyClass

public java.lang.Class getListProxyClass()
Returns the list proxy class.

Specified by:
getListProxyClass in interface ProxyFactory
Returns:
The class used for list proxies

setListProxyClass

public void setListProxyClass(java.lang.Class listProxyClass)
Dets the proxy class to use for collection classes that implement the List interface. Notes that the proxy class must implement the List interface, and have a constructor of the signature (PBKey, Class, Query).

Specified by:
setListProxyClass in interface ProxyFactory
Parameters:
listProxyClass - The proxy class

getSetProxyClass

public java.lang.Class getSetProxyClass()
Returns the set proxy class.

Specified by:
getSetProxyClass in interface ProxyFactory
Returns:
The class used for set proxies

setSetProxyClass

public void setSetProxyClass(java.lang.Class setProxyClass)
Dets the proxy class to use for collection classes that implement the Set interface.

Specified by:
setSetProxyClass in interface ProxyFactory
Parameters:
setProxyClass - The proxy class

getCollectionProxyClass

public java.lang.Class getCollectionProxyClass()
Returns the collection proxy class.

Specified by:
getCollectionProxyClass in interface ProxyFactory
Returns:
The class used for collection proxies

setCollectionProxyClass

public void setCollectionProxyClass(java.lang.Class collectionProxyClass)
Dets the proxy class to use for generic collection classes implementing the Collection interface.

Specified by:
setCollectionProxyClass in interface ProxyFactory
Parameters:
collectionProxyClass - The proxy class

createCollectionProxy

public ManageableCollection createCollectionProxy(PBKey brokerKey,
                                                  Query query,
                                                  java.lang.Class collectionClass)
Create a Collection Proxy for a given query.

Specified by:
createCollectionProxy in interface ProxyFactory
Parameters:
brokerKey - The key of the persistence broker
query - The query
collectionClass - The class to build the proxy for
Returns:
The collection proxy

getRealObject

public final java.lang.Object getRealObject(java.lang.Object objectOrProxy)
Get the real Object

Specified by:
getRealObject in interface ProxyFactory
Parameters:
objectOrProxy -
Returns:
Object

getRealObjectIfMaterialized

public java.lang.Object getRealObjectIfMaterialized(java.lang.Object objectOrProxy)
Get the real Object for already materialized Handler

Specified by:
getRealObjectIfMaterialized in interface ProxyFactory
Parameters:
objectOrProxy -
Returns:
Object or null if the Handel is not materialized

getRealClass

public java.lang.Class getRealClass(java.lang.Object objectOrProxy)
Get the real Class

Specified by:
getRealClass in interface ProxyFactory
Parameters:
objectOrProxy -
Returns:
Class

isNormalOjbProxy

public boolean isNormalOjbProxy(java.lang.Object proxyOrObject)
Determines whether the given object is an OJB proxy.

Specified by:
isNormalOjbProxy in interface ProxyFactory
Returns:
true if the object is an OJB proxy

isVirtualOjbProxy

public boolean isVirtualOjbProxy(java.lang.Object proxyOrObject)
Determines whether the given object is an OJB virtual proxy.

Specified by:
isVirtualOjbProxy in interface ProxyFactory
Returns:
true if the object is an OJB virtual proxy

isProxy

public boolean isProxy(java.lang.Object proxyOrObject)
Returns true if the given object is a Proxy or a VirtualProxy instance.

Specified by:
isProxy in interface ProxyFactory

getIndirectionHandler

public IndirectionHandler getIndirectionHandler(java.lang.Object obj)
Returns the invocation handler object of the given proxy object.

Specified by:
getIndirectionHandler in interface ProxyFactory
Parameters:
obj - The object
Returns:
The invocation handler if the object is an OJB proxy, or null otherwise

isMaterialized

public boolean isMaterialized(java.lang.Object object)
Determines whether the object is a materialized object, i.e. no proxy or a proxy that has already been loaded from the database.

Specified by:
isMaterialized in interface ProxyFactory
Parameters:
object - The object to test
Returns:
true if the object is materialized

getCollectionProxy

public CollectionProxy getCollectionProxy(java.lang.Object item)
Return CollectionProxy for item is item is a CollectionProxy, otherwise return null

Specified by:
getCollectionProxy in interface ProxyFactory

isCollectionProxy

public boolean isCollectionProxy(java.lang.Object item)
Reports if item is a CollectionProxy. TODO: Provide handling for pluggable collection proxy implementations

Specified by:
isCollectionProxy in interface ProxyFactory

toString

public java.lang.String toString(java.lang.Object proxy)
Materialization-safe version of toString. If the object is a yet-unmaterialized proxy, then only the text "unmaterialized proxy for ..." is returned and the proxy is NOT materialized. Otherwise, the normal toString method is called. This useful e.g. for logging etc.

Specified by:
toString in interface ProxyFactory
Parameters:
proxy - The object for which a string representation shall be generated
Returns:
The string representation

getProxyFactory

public static ProxyFactory getProxyFactory()


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30