Author: pete.muir(a)jboss.org
Date: 2008-05-13 18:22:11 -0400 (Tue, 13 May 2008)
New Revision: 8185
Modified:
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java
Log:
Move injection stuff around
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java 2008-05-13
22:21:53 UTC (rev 8184)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java 2008-05-13
22:22:11 UTC (rev 8185)
@@ -1,45 +1,29 @@
package org.jboss.seam.wicket.ioc;
-import static org.jboss.seam.ScopeType.STATELESS;
-import static org.jboss.seam.ScopeType.UNSPECIFIED;
-
import java.io.Serializable;
import java.lang.reflect.Method;
-import org.jboss.seam.Component;
-import org.jboss.seam.Namespace;
+import javassist.util.proxy.MethodHandler;
+
import org.jboss.seam.annotations.In;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
import org.jboss.seam.util.Reflections;
-import javassist.util.proxy.MethodHandler;
-
-// TODO Replace with a client side Seam interceptor
-public class InjectionInterceptor implements MethodHandler, Serializable
+public abstract class InjectionInterceptor implements MethodHandler, Serializable
{
-
private String name;
private In annotation;
- private String metaModelName;
- private transient MetaModel metaModel;
public InjectionInterceptor(BijectedAttribute<In> in)
{
this.name = in.getName();
this.annotation = in.getAnnotation();
- this.metaModelName = in.getMetaModel().getMetaModelName();
}
-
- private static LogProvider log = Logging.getLogProvider(InjectionInterceptor.class);
public Object invoke(final Object proxy, final Method method, final Method proceed,
final Object[] params) throws Throwable
{
if (!org.jboss.seam.web.Session.instance().isInvalid())
{
- return Reflections.invoke(method, getValueToInject(proxy), params);
+ return Reflections.invoke(method, getValueToInject(name, annotation, proxy),
params);
}
else
{
@@ -47,74 +31,6 @@
}
}
- private Object getValueToInject(Object bean)
- {
- if ( name.startsWith("#") )
- {
- if ( log.isDebugEnabled() )
- {
- log.trace("trying to inject with EL expression: " + name);
- }
- return Expressions.instance().createValueExpression(name).getValue();
- }
- else if ( annotation.scope()==UNSPECIFIED )
- {
- if ( log.isDebugEnabled() )
- {
- log.trace("trying to inject with hierarchical context search: " +
name);
- }
- return getInstanceInAllNamespaces(name, annotation.create());
- }
- else
- {
- if ( annotation.create() )
- {
- throw new IllegalArgumentException(
- "cannot combine create=true with explicit scope on @In: " +
- getMetaModel().getAttributeMessage(name)
- );
- }
- if ( annotation.scope()==STATELESS )
- {
- throw new IllegalArgumentException(
- "cannot specify explicit scope=STATELESS on @In: " +
- getMetaModel().getAttributeMessage(name)
- );
- }
-
-
- log.trace("trying to inject from specified context: " + name);
-
- if ( annotation.scope().isContextActive() )
- {
- return annotation.scope().getContext().get(name);
- }
- }
- return null;
- }
+ protected abstract Object getValueToInject(String name, In annotation, Object value);
- private Object getInstanceInAllNamespaces(String name, boolean create)
- {
- Object result;
- result = Component.getInstance(name, create);
- if (result==null)
- {
- for ( Namespace namespace: Init.instance().getGlobalImports() )
- {
- result = namespace.getComponentInstance(name, create);
- if (result!=null) break;
- }
- }
- return result;
- }
-
- private MetaModel getMetaModel()
- {
- if (metaModel == null)
- {
- metaModel = MetaModel.forName(metaModelName);
- }
- return metaModel;
- }
-
}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java 2008-05-13 22:21:53 UTC (rev
8184)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java 2008-05-13 22:22:11 UTC (rev
8185)
@@ -1,5 +1,7 @@
package org.jboss.seam.wicket.ioc;
+import static org.jboss.seam.ScopeType.STATELESS;
+import static org.jboss.seam.ScopeType.UNSPECIFIED;
import static org.jboss.seam.wicket.ioc.MetaModelUtils.createProxyFactory;
import static org.jboss.seam.wicket.ioc.MetaModelUtils.toName;
@@ -12,7 +14,13 @@
import javassist.util.proxy.ProxyObject;
+import org.jboss.seam.Component;
+import org.jboss.seam.Namespace;
import org.jboss.seam.annotations.In;
+import org.jboss.seam.core.Expressions;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
/**
* Controls injection for a MetaModel
@@ -26,7 +34,9 @@
private List<BijectedAttribute<In>> inAttributes = new
ArrayList<BijectedAttribute<In>>();
- private MetaModel metaModel;
+ private final MetaModel metaModel;
+
+ private static LogProvider log = Logging.getLogProvider(Injector.class);
public Injector(MetaModel metaModel)
{
@@ -57,16 +67,21 @@
{
for ( BijectedAttribute<In> in : inAttributes )
{
- // Currently need a proxy here as Wicket has no native support for interceptors
- // TODO Replace this with a Seam ClientSide interceptor. Needs JBSEAM-699
- in.set( instance, wrap( instance, in ) );
+ in.set( instance, wrap( in, metaModel.getMetaModelName() ) );
}
}
- private static Object wrap(Object bean, BijectedAttribute<In> in) throws
Exception
+ private static Object wrap(final BijectedAttribute<In> in, final String
metaModelName) throws Exception
{
ProxyObject proxy = getProxyFactory(in.getType()).newInstance();
- proxy.setHandler(new InjectionInterceptor(in));
+ proxy.setHandler(new InjectionInterceptor(in)
+ {
+ @Override
+ protected Object getValueToInject(String name, In annotation, Object value)
+ {
+ return getValue(name, annotation, metaModelName, value);
+ }
+ });
return proxy;
}
@@ -84,4 +99,70 @@
}
}
+ private static Object getValue(String name, In annotation, String metaModelName,
Object bean)
+ {
+ if ( name.startsWith("#") )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.trace("trying to inject with EL expression: " + name);
+ }
+ return Expressions.instance().createValueExpression(name).getValue();
+ }
+ else if ( annotation.scope()==UNSPECIFIED )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.trace("trying to inject with hierarchical context search: " +
name);
+ }
+ return getInstanceInAllNamespaces(name, annotation.create());
+ }
+ else
+ {
+ if ( annotation.create() )
+ {
+ throw new IllegalArgumentException(
+ "cannot combine create=true with explicit scope on @In: " +
+ getMetaModel(metaModelName).getAttributeMessage(name)
+ );
+ }
+ if ( annotation.scope()==STATELESS )
+ {
+ throw new IllegalArgumentException(
+ "cannot specify explicit scope=STATELESS on @In: " +
+ getMetaModel(metaModelName).getAttributeMessage(name)
+ );
+ }
+
+
+ log.trace("trying to inject from specified context: " + name);
+
+ if ( annotation.scope().isContextActive() )
+ {
+ return annotation.scope().getContext().get(name);
+ }
+ }
+ return null;
+ }
+
+ private static Object getInstanceInAllNamespaces(String name, boolean create)
+ {
+ Object result;
+ result = Component.getInstance(name, create);
+ if (result==null)
+ {
+ for ( Namespace namespace: Init.instance().getGlobalImports() )
+ {
+ result = namespace.getComponentInstance(name, create);
+ if (result!=null) break;
+ }
+ }
+ return result;
+ }
+
+ private static MetaModel getMetaModel(String metaModelName)
+ {
+ return MetaModel.forName(metaModelName);
+ }
+
}