Author: ivaynberg
Date: Mon Feb  2 08:03:42 2009
New Revision: 739938

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

Removed:
    
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceTypeStore.java
Modified:
    
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceComponentInjector.java
    
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceProxyTargetLocator.java

Modified: 
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceComponentInjector.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceComponentInjector.java?rev=739938&r1=739937&r2=739938&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceComponentInjector.java
 (original)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceComponentInjector.java
 Mon Feb  2 08:03:42 2009
@@ -94,7 +94,6 @@
        public GuiceComponentInjector(Application app, Injector injector)
        {
                app.setMetaData(GuiceInjectorHolder.INJECTOR_KEY, new 
GuiceInjectorHolder(injector));
-               app.setMetaData(GuiceTypeStore.TYPESTORE_KEY, new 
GuiceTypeStore());
        }
 
        public void inject(Object object)
@@ -112,8 +111,7 @@
                                        {
                                                Annotation bindingAnnotation = 
findBindingAnnotation(field.getAnnotations());
                                                Object proxy = 
LazyInitProxyFactory.createProxy(field.getType(),
-                                                               new 
GuiceProxyTargetLocator(field.getGenericType(),
-                                                                               
bindingAnnotation));
+                                                               new 
GuiceProxyTargetLocator(field, bindingAnnotation));
 
                                                if (!field.isAccessible())
                                                {
@@ -160,8 +158,7 @@
                                                {
                                                        Annotation 
bindingAnnotation = findBindingAnnotation(paramAnnotations[i]);
                                                        args[i] = 
LazyInitProxyFactory.createProxy(paramTypes[i],
-                                                                       new 
GuiceProxyTargetLocator(genericParamTypes[i],
-                                                                               
        bindingAnnotation));
+                                                                       new 
GuiceProxyTargetLocator(method, i, bindingAnnotation));
                                                }
                                                catch 
(MoreThanOneBindingException e)
                                                {

Modified: 
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceProxyTargetLocator.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceProxyTargetLocator.java?rev=739938&r1=739937&r2=739938&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceProxyTargetLocator.java
 (original)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.5/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceProxyTargetLocator.java
 Mon Feb  2 08:03:42 2009
@@ -17,9 +17,12 @@
 package org.apache.wicket.guice;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 
 import org.apache.wicket.Application;
+import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.proxy.IProxyTargetLocator;
 
 import com.google.inject.Key;
@@ -29,18 +32,33 @@
 {
        private static final long serialVersionUID = 1L;
 
-       private final String typeName;
        private final Annotation bindingAnnotation;
 
-       GuiceProxyTargetLocator(Type type, Annotation bindingAnnotation)
+       private final String[] data;
+
+       /** index of argument in the method being injected, or -1 for field */
+       private final int argIndex;
+
+       GuiceProxyTargetLocator(Field field, Annotation bindingAnnotation)
        {
-               // I'm not too happy about
-               typeName = type.toString();
                this.bindingAnnotation = bindingAnnotation;
+               data = new String[2];
+               data[0] = field.getDeclaringClass().getName();
+               data[1] = field.getName();
+               argIndex = -1;
+       }
 
-               GuiceTypeStore typeStore = 
(GuiceTypeStore)Application.get().getMetaData(
-                               GuiceTypeStore.TYPESTORE_KEY);
-               typeStore.setType(typeName, type);
+       GuiceProxyTargetLocator(Method method, int argIndex, Annotation 
bindingAnnotation)
+       {
+               this.bindingAnnotation = bindingAnnotation;
+               data = new String[2 + method.getParameterTypes().length];
+               data[0] = method.getDeclaringClass().getName();
+               data[1] = method.getName();
+               for (int i = 0; i < method.getParameterTypes().length; i++)
+               {
+                       data[2 + i] = method.getParameterTypes()[i].getName();
+               }
+               this.argIndex = argIndex;
        }
 
        public Object locateProxyTarget()
@@ -48,9 +66,32 @@
                final GuiceInjectorHolder holder = 
(GuiceInjectorHolder)Application.get().getMetaData(
                                GuiceInjectorHolder.INJECTOR_KEY);
 
-               final GuiceTypeStore typeStore = 
(GuiceTypeStore)Application.get().getMetaData(
-                               GuiceTypeStore.TYPESTORE_KEY);
-               final Type type = typeStore.getType(typeName);
+               final Type type;
+               try
+               {
+
+                       Class< ? > clazz = Class.forName(data[0]);
+                       if (argIndex < 0)
+                       {
+                               final Field field = 
clazz.getDeclaredField(data[1]);
+                               type = field.getGenericType();
+                       }
+                       else
+                       {
+                               Class< ? >[] paramTypes = new Class[data.length 
- 2];
+                               for (int i = 2; i < data.length; i++)
+                               {
+                                       paramTypes[2 - i] = 
Class.forName(data[i]);
+                               }
+                               final Method method = 
clazz.getDeclaredMethod(data[1], paramTypes);
+                               type = 
method.getGenericParameterTypes()[argIndex];
+                       }
+               }
+               catch (Exception e)
+               {
+                       throw new WicketRuntimeException("Error accessing 
member: " + data[1] + " of class: " +
+                                       data[0], e);
+               }
 
                // using TypeLiteral to retrieve the key gives us automatic 
support for
                // Providers and other injectable TypeLiterals


Reply via email to