Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv30194
Modified Files:
AbstractAutowireCapableObjectFactory.cs
AbstractObjectFactory.cs
Log Message:
SPRNET-720 - Change ObjectNameAutoProxyCreator default behavior to proxy the product of a IFactoryObject and not the IFactoryObject itself
SPRNET-721 - Intercept all target interfaces when using an introduction with ObjectNameAutoProxyCreator
Index: AbstractAutowireCapableObjectFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs,v
retrieving revision 1.81
retrieving revision 1.82
diff -C2 -d -r1.81 -r1.82
*** AbstractAutowireCapableObjectFactory.cs 28 Aug 2007 14:16:40 -0000 1.81
--- AbstractAutowireCapableObjectFactory.cs 7 Sep 2007 01:52:24 -0000 1.82
***************
*** 2112,2115 ****
--- 2112,2129 ----
+ /// <summary>
+ /// Applies the <code>PostProcessAfterInitialization</code> callback of all
+ /// registered IObjectPostProcessors, giving them a chance to post-process
+ /// the object obtained from IFactoryObjects (for example, to auto-proxy them)
+ /// </summary>
+ /// <param name="instance">The instance obtained from the IFactoryObject.</param>
+ /// <param name="objectName">Name of the object.</param>
+ /// <returns>The object instance to expose</returns>
+ /// <exception cref="ObjectsException">if any post-processing failed.</exception>
+ protected override object PostProcessObjectFromFactoryObject(object instance, string objectName)
+ {
+ return ApplyObjectPostProcessorsAfterInitialization(instance, objectName);
+ }
+
#endregion
Index: AbstractObjectFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectFactory.cs,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** AbstractObjectFactory.cs 28 Aug 2007 14:16:40 -0000 1.70
--- AbstractObjectFactory.cs 7 Sep 2007 01:52:25 -0000 1.71
***************
*** 226,231 ****
public object GetObject(string name, Type requiredType, object[] arguments)
{
- object instance = null;
string objectName = TransformedObjectName(name);
// eagerly check singleton cache for manually registered singletons...
object sharedInstance = GetSingleton(objectName);
--- 226,231 ----
public object GetObject(string name, Type requiredType, object[] arguments)
{
string objectName = TransformedObjectName(name);
+ object instance = null;
// eagerly check singleton cache for manually registered singletons...
object sharedInstance = GetSingleton(objectName);
***************
*** 727,731 ****
protected virtual object GetObjectForInstance(string name, object instance)
{
! string objectName = TransformedObjectName(name);
// don't let calling code try to dereference the
--- 727,731 ----
protected virtual object GetObjectForInstance(string name, object instance)
{
! //string objectName = TransformedObjectName(name);
// don't let calling code try to dereference the
***************
*** 733,737 ****
if (IsFactoryDereference(name) && !(instance is IFactoryObject))
{
! throw new ObjectIsNotAFactoryException(objectName, instance);
}
--- 733,737 ----
if (IsFactoryDereference(name) && !(instance is IFactoryObject))
{
! throw new ObjectIsNotAFactoryException(TransformedObjectName(name), instance);
}
***************
*** 744,749 ****
--- 744,751 ----
if (!IsFactoryDereference(name))
{
+
// return object instance from factory...
IFactoryObject factory = (IFactoryObject) instance;
+ string objectName = TransformedObjectName(name);
#region Instrumentation
***************
*** 756,767 ****
#endregion
! try
! {
! instance = factory.GetObject();
! }
! catch (Exception ex)
! {
! throw new ObjectCreationException("IFactoryObject threw exception on object creation.", ex);
! }
if (factory is IConfigurableFactoryObject)
--- 758,764 ----
#endregion
! RootObjectDefinition rod =
! (ContainsObjectDefinition(objectName) ? GetMergedObjectDefinition(objectName,true) : null);
! instance = GetObjectFromFactoryObject(factory,objectName, rod);
if (factory is IConfigurableFactoryObject)
***************
*** 773,777 ****
if (log.IsDebugEnabled)
{
! log.Debug(string.Format("Factory object with name '{0}' is configurable.", objectName));
}
--- 770,774 ----
if (log.IsDebugEnabled)
{
! log.Debug(string.Format("Factory object with name '{0}' is configurable.", TransformedObjectName(name)));
}
***************
*** 788,792 ****
if (instance == null)
{
! throw new FactoryObjectNotInitializedException(objectName,
"Factory object returned null object - "
+ "possible cause: not fully initialized due to "
--- 785,789 ----
if (instance == null)
{
! throw new FactoryObjectNotInitializedException(TransformedObjectName(name),
"Factory object returned null object - "
+ "possible cause: not fully initialized due to "
***************
*** 801,805 ****
log.Debug(
string.Format("Calling code asked for IFactoryObject instance for name '{0}'.",
! objectName));
}
}
--- 798,802 ----
log.Debug(
string.Format("Calling code asked for IFactoryObject instance for name '{0}'.",
! TransformedObjectName(name)));
}
}
***************
*** 809,812 ****
--- 806,869 ----
/// <summary>
+ /// Obtain an object to expose from the given IFactoryObject.
+ /// </summary>
+ /// <param name="factory">The IFactoryObject instance.</param>
+ /// <param name="objectName">Name of the object.</param>
+ /// <param name="rod">The merged object definition.</param>
+ /// <returns>The object obtained from the IFactoryObject</returns>
+ /// <exception cref="ObjectCreationException">If IFactoryObject object creation failed.</exception>
+ private object GetObjectFromFactoryObject(IFactoryObject factory, string objectName, RootObjectDefinition rod)
+ {
+ object instance;
+
+ try
+ {
+ instance = factory.GetObject();
+ }
+ catch (FactoryObjectNotInitializedException ex) {
+ throw new ObjectCurrentlyInCreationException("Object Name = " + objectName + ", " + ex, ex);
+ }
+ catch (Exception ex)
+ {
+ throw new ObjectCreationException("IFactoryObject threw exception on object creation for object with name = " + objectName, ex);
+ }
+
+ // Do not accept a null value for a FactoryBean that's not fully
+ // initialized yet: Many FactoryBeans just return null then.
+ if (instance == null && IsSingletonCurrentlyInCreation(objectName)) {
+ throw new ObjectCurrentlyInCreationException(objectName, "FactoryObject which is currently in creation returned null from GetObject");
+ }
+
+ if (instance != null)
+ {
+ try {
+ instance = PostProcessObjectFromFactoryObject(instance, objectName);
+ }
+ catch (Exception ex) {
+ throw new ObjectCreationException(rod.ResourceDescription, objectName,
+ "Post-processing of the FactoryObject's object failed", ex);
+ }
+ }
+
+ return instance;
+ }
+
+ /// <summary>
+ /// Post-process the given object that has been obtained from the FactoryObject.
+ /// The resulting object will be exposed for object references.
+ /// </summary>
+ /// <remarks>The default implementation simply returns the given object
+ /// as-is. Subclasses may override this, for example, to apply
+ /// post-processors.</remarks>
+ /// <param name="instance">The instance obtained from the IFactoryObject.</param>
+ /// <param name="objectName">Name of the object.</param>
+ /// <returns>The object instance to expose</returns>
+ /// <exception cref="ObjectsException">if any post-processing failed.</exception>
+ protected virtual object PostProcessObjectFromFactoryObject(object instance, string objectName)
+ {
+ return instance;
+ }
+
+ /// <summary>
/// Convenience method to pull an <see cref="Spring.Objects.Factory.IFactoryObject"/>
/// from this factory.
|