You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2009/11/12 07:06:03 UTC

svn commit: r835247 - in /wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot: AnnotProxyFieldValueFactory.java AnnotSpringInjector.java SpringComponentInjector.java

Author: ivaynberg
Date: Thu Nov 12 06:06:02 2009
New Revision: 835247

URL: http://svn.apache.org/viewvc?rev=835247&view=rev
Log:
WICKET-2573

Modified:
    wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java
    wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotSpringInjector.java
    wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/SpringComponentInjector.java

Modified: wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java?rev=835247&r1=835246&r2=835247&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java (original)
+++ wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java Thu Nov 12 06:06:02 2009
@@ -62,17 +62,32 @@
 
 	private final ConcurrentHashMap<SpringBeanLocator, Object> cache = new ConcurrentHashMap<SpringBeanLocator, Object>();
 
+	private final boolean wrapInProxies;
+
 	/**
 	 * @param contextLocator
 	 *            spring context locator
 	 */
 	public AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator)
 	{
+		this(contextLocator, true);
+	}
+
+	/**
+	 * @param contextLocator
+	 *            spring context locator
+	 * @param wrapInProxies
+	 *            whether or not wicket should wrap dependencies with specialized proxies that can
+	 *            be safely serialized. in most cases this should be set to true.
+	 */
+	public AnnotProxyFieldValueFactory(ISpringContextLocator contextLocator, boolean wrapInProxies)
+	{
 		if (contextLocator == null)
 		{
 			throw new IllegalArgumentException("[contextLocator] argument cannot be null");
 		}
 		this.contextLocator = contextLocator;
+		this.wrapInProxies = wrapInProxies;
 	}
 
 	/**
@@ -93,13 +108,23 @@
 				return cache.get(locator);
 			}
 
-			Object proxy = LazyInitProxyFactory.createProxy(field.getType(), locator);
+
+			final Object target;
+			if (wrapInProxies)
+			{
+				target = LazyInitProxyFactory.createProxy(field.getType(), locator);
+			}
+			else
+			{
+				target = locator.locateProxyTarget();
+			}
+
 			// only put the proxy into the cache if the bean is a singleton
 			if (locator.isSingletonBean())
 			{
-				cache.put(locator, proxy);
+				cache.put(locator, target);
 			}
-			return proxy;
+			return target;
 		}
 		else
 		{

Modified: wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotSpringInjector.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotSpringInjector.java?rev=835247&r1=835246&r2=835247&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotSpringInjector.java (original)
+++ wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotSpringInjector.java Thu Nov 12 06:06:02 2009
@@ -35,16 +35,31 @@
 	 * Constructor
 	 * 
 	 * @param locator
-	 * 		spring context locator
+	 *            spring context locator
 	 */
 	public AnnotSpringInjector(ISpringContextLocator locator)
 	{
-		initFactory(locator);
+		this(locator, true);
 	}
 
-	private void initFactory(ISpringContextLocator locator)
+
+	/**
+	 * Constructor
+	 * 
+	 * @param locator
+	 *            spring context locator
+	 * @param wrapInProxies
+	 *            whether or not wicket should wrap dependencies with specialized proxies that can
+	 *            be safely serialized. in most cases this should be set to true.
+	 */
+	public AnnotSpringInjector(ISpringContextLocator locator, boolean wrapInProxies)
+	{
+		initFactory(locator, wrapInProxies);
+	}
+
+	private void initFactory(ISpringContextLocator locator, boolean wrapInProxies)
 	{
-		factory = new AnnotProxyFieldValueFactory(locator);
+		factory = new AnnotProxyFieldValueFactory(locator, wrapInProxies);
 	}
 
 	@Override

Modified: wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/SpringComponentInjector.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/SpringComponentInjector.java?rev=835247&r1=835246&r2=835247&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/SpringComponentInjector.java (original)
+++ wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/SpringComponentInjector.java Thu Nov 12 06:06:02 2009
@@ -32,8 +32,8 @@
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
 /**
- * {@link IComponentInstantiationListener} that injects component properties annotated with {@link
- * SpringBean} annotations.
+ * {@link IComponentInstantiationListener} that injects component properties annotated with
+ * {@link SpringBean} annotations.
  * 
  * To install in yourapplication.init() call
  * <code>addComponentInstantiationListener(new SpringComponentInjector(this));</code> Non-wicket
@@ -59,29 +59,33 @@
 
 	/**
 	 * Constructor used when spring application context is declared in the spring standard way and
-	 * can be located through {@link
-	 * WebApplicationContextUtils#getRequiredWebApplicationContext(ServletContext)}
+	 * can be located through
+	 * {@link WebApplicationContextUtils#getRequiredWebApplicationContext(ServletContext)}
 	 * 
 	 * @param webapp
-	 * 		wicket web application
+	 *            wicket web application
 	 */
 	public SpringComponentInjector(WebApplication webapp)
 	{
 		// locate application context through spring's default location
 		// mechanism and pass it on to the proper constructor
 		this(webapp, WebApplicationContextUtils.getRequiredWebApplicationContext(webapp
-				.getServletContext()));
+				.getServletContext()), true);
 	}
 
 	/**
 	 * Constructor
 	 * 
 	 * @param webapp
-	 * 		wicket web application
+	 *            wicket web application
 	 * @param ctx
-	 * 		spring's application context
+	 *            spring's application context
+	 * @param wrapInProxies
+	 *            whether or not wicket should wrap dependencies with specialized proxies that can
+	 *            be safely serialized. in most cases this should be set to true.
 	 */
-	public SpringComponentInjector(WebApplication webapp, ApplicationContext ctx)
+	public SpringComponentInjector(WebApplication webapp, ApplicationContext ctx,
+			boolean wrapInProxies)
 	{
 		if (webapp == null)
 		{
@@ -97,7 +101,7 @@
 		webapp.setMetaData(CONTEXT_KEY, new ApplicationContextHolder(ctx));
 
 		// ... and create and register the annotation aware injector
-		InjectorHolder.setInjector(new AnnotSpringInjector(new ContextLocator()));
+		InjectorHolder.setInjector(new AnnotSpringInjector(new ContextLocator(), wrapInProxies));
 	}
 
 	/**