[seam-commits] Seam SVN: r8465 - in trunk/src/wicket: META-INF and 3 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Jul 14 16:58:02 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-07-14 16:58:02 -0400 (Mon, 14 Jul 2008)
New Revision: 8465
Added:
trunk/src/wicket/META-INF/
trunk/src/wicket/META-INF/seam-deployment.properties
trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
Removed:
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java
Modified:
trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java
trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java
Log:
Rewrite wicket support using class instrumentation using custom classloader
Added: trunk/src/wicket/META-INF/seam-deployment.properties
===================================================================
--- trunk/src/wicket/META-INF/seam-deployment.properties (rev 0)
+++ trunk/src/wicket/META-INF/seam-deployment.properties 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1 @@
+org.jboss.seam.deployment.deploymentHandlers=org.jboss.seam.wicket.two.WicketComponentDeploymentHandler
\ No newline at end of file
Property changes on: trunk/src/wicket/META-INF/seam-deployment.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -19,7 +19,6 @@
import org.jboss.seam.core.Conversation;
import org.jboss.seam.core.Manager;
import org.jboss.seam.wicket.international.SeamStatusMessagesListener;
-import org.jboss.seam.wicket.ioc.SeamInjectionListener;
/**
* The base class for Seam Web Applications
@@ -116,7 +115,6 @@
{
super.init();
inititializeSeamSecurity();
- initializeSeamInjection();
initializeSeamStatusMessages();
}
@@ -132,15 +130,6 @@
getSecuritySettings().setAuthorizationStrategy(new SeamAuthorizationStrategy(getLoginPage()));
}
-
- /**
- * Add Seam injection support to your app. Required for proper functioning
- */
- protected void initializeSeamInjection()
- {
- addComponentInstantiationListener(new SeamInjectionListener());
- }
-
/**
* Add Seam status message transport support to youur app.
*/
Added: trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,344 @@
+package org.jboss.seam.wicket;
+
+import static org.jboss.seam.ScopeType.STATELESS;
+import static org.jboss.seam.ScopeType.UNSPECIFIED;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.Namespace;
+import org.jboss.seam.RequiredException;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Expressions;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.util.Reflections;
+import org.jboss.seam.wicket.ioc.BijectedAttribute;
+import org.jboss.seam.wicket.ioc.BijectedField;
+import org.jboss.seam.wicket.ioc.BijectedMethod;
+import org.jboss.seam.wicket.ioc.InjectedAttribute;
+import org.jboss.seam.wicket.ioc.InjectedField;
+
+public class WicketComponent<T>
+{
+
+ private final class InjectedLogger extends InjectedField<Logger>
+ {
+ private Log logInstance;
+
+ InjectedLogger(Field field, Logger annotation)
+ {
+ super(field, annotation);
+ String category = getAnnotation().value();
+ if ("".equals(category))
+ {
+ logInstance = Logging.getLog(getType());
+ }
+ else
+ {
+ logInstance = Logging.getLog(category);
+ }
+ }
+
+ Log getLogInstance()
+ {
+ return logInstance;
+ }
+
+ public void set(Object bean)
+ {
+ super.set(bean, logInstance);
+ }
+ }
+
+ private static Log log = Logging.getLog(WicketComponent.class);
+
+ private Class<? extends T> type;
+
+ private List<BijectedAttribute<In>> inAttributes = new ArrayList<BijectedAttribute<In>>();
+ private List<BijectedAttribute<Out>> outAttributes = new ArrayList<BijectedAttribute<Out>>();
+ private List<InjectedLogger> loggerFields = new ArrayList<InjectedLogger>();
+
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+ public static <T> WicketComponent<T> getInstance(Class<? extends T> type)
+ {
+ String name = getContextVariableName(type);
+ if (Contexts.getApplicationContext().isSet(name))
+ {
+ return (WicketComponent) Contexts.getApplicationContext().get(name);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static String getContextVariableName(Class<?> type)
+ {
+ return type.getName() + ".wicketComponent";
+ }
+
+ public String getName()
+ {
+ return getContextVariableName(type);
+ }
+
+ public WicketComponent(Class<? extends T> type)
+ {
+ this.type = type;
+ log.info("Class: #0", type);
+ scan();
+ Contexts.getApplicationContext().set(getName(), this);
+ }
+
+ private void scan()
+ {
+ Class clazz = type;
+ for (Method method : clazz.getDeclaredMethods())
+ {
+ add(method);
+ }
+ for (Field field : clazz.getDeclaredFields())
+ {
+ add(field);
+ }
+ }
+
+ public void outject(T target)
+ {
+ for (BijectedAttribute<Out> out : outAttributes)
+ {
+ Object value = out.get(target);
+ if (value==null && out.getAnnotation().required())
+ {
+ throw new RequiredException("@Out attribute requires non-null value: " + out.toString());
+ }
+ else
+ {
+ Component component = null;
+ if (out.getAnnotation().scope()==UNSPECIFIED)
+ {
+ component = Component.forName(out.getContextVariableName());
+ if (value!=null && component!=null)
+ {
+ if (!component.isInstance(value))
+ {
+ throw new IllegalArgumentException("attempted to bind an @Out attribute of the wrong type to: " + out.toString());
+ }
+ }
+ }
+ else if (out.getAnnotation().scope()==STATELESS)
+ {
+ throw new IllegalArgumentException("cannot specify explicit scope=STATELESS on @Out: " + out.toString());
+ }
+
+ ScopeType outScope = component == null ? out.getAnnotation().scope() : component.getScope();
+
+ if (outScope == null)
+ {
+ throw new IllegalArgumentException("cannot determine scope to outject to on @Out: " + out.toString());
+ }
+
+ if (outScope.isContextActive())
+ {
+ if (value==null)
+ {
+ outScope.getContext().remove(out.getContextVariableName());
+ }
+ else
+ {
+ outScope.getContext().set(out.getContextVariableName(), value);
+ }
+ }
+ }
+ }
+ }
+
+
+ public void disinject(T target)
+ {
+ for ( InjectedAttribute<In> in : inAttributes )
+ {
+ if ( !in.getType().isPrimitive() )
+ {
+ in.set(target, null);
+ }
+ }
+
+ }
+
+ public void inject(T instance) throws Exception
+ {
+ for ( BijectedAttribute<In> in : inAttributes )
+ {
+ in.set( instance, getValue(in, instance) );
+ }
+ }
+
+ private void add(Method method)
+ {
+ if ( method.isAnnotationPresent(In.class) )
+ {
+ final In in = method.getAnnotation(In.class);
+ inAttributes.add( new BijectedMethod(method, in)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return in.value();
+ }
+
+ });
+ }
+ if ( method.isAnnotationPresent(Out.class) )
+ {
+ final Out out = method.getAnnotation(Out.class);
+ outAttributes.add( new BijectedMethod(method, out)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return out.value();
+ }
+
+ });
+ }
+ }
+
+ private void add(Field field)
+ {
+ if ( field.isAnnotationPresent(In.class) )
+ {
+ final In in = field.getAnnotation(In.class);
+ inAttributes.add( new BijectedField(field, in)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return in.value();
+ }
+
+ });
+ }
+ if ( field.isAnnotationPresent(Out.class) )
+ {
+ final Out out = field.getAnnotation(Out.class);
+ outAttributes.add( new BijectedField(field, out)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return out.value();
+ }
+
+ });
+ }
+ if ( field.isAnnotationPresent(Logger.class) )
+ {
+ final Logger logger = field.getAnnotation(Logger.class);
+ InjectedLogger loggerField = new InjectedLogger(field, logger);
+
+ if ( Modifier.isStatic( field.getModifiers() ) )
+ {
+ loggerField.set(null);
+ }
+ else
+ {
+ loggerFields.add(loggerField);
+ }
+ }
+ }
+
+ private static Object getValue(BijectedAttribute<In> in, Object bean)
+ {
+ String name = in.getContextVariableName();
+ if ( name.startsWith("#") )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.trace("trying to inject with EL expression: " + name);
+ }
+ return Expressions.instance().createValueExpression(name).getValue();
+ }
+ else if ( in.getAnnotation().scope()==UNSPECIFIED )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.trace("trying to inject with hierarchical context search: " + name);
+ }
+ return getInstanceInAllNamespaces(name, in.getAnnotation().create());
+ }
+ else
+ {
+ if ( in.getAnnotation().create() )
+ {
+ throw new IllegalArgumentException(
+ "cannot combine create=true with explicit scope on @In: " +
+ in.toString()
+ );
+ }
+ if ( in.getAnnotation().scope()==STATELESS )
+ {
+ throw new IllegalArgumentException(
+ "cannot specify explicit scope=STATELESS on @In: " +
+ in.toString()
+ );
+ }
+
+
+ log.trace("trying to inject from specified context: " + name);
+
+ if ( in.getAnnotation().scope().isContextActive() )
+ {
+ return in.getAnnotation().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;
+ }
+
+ public void initialize(T bean)
+ {
+ injectLog(bean);
+ }
+
+ private void injectLog(T bean)
+ {
+ for (InjectedLogger injectedLogger : loggerFields)
+ {
+ injectedLogger.set(bean);
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -9,12 +9,10 @@
*
* TODO Move into Seam core
*/
-public interface BijectedAttribute<T extends Annotation>
+public interface BijectedAttribute<T extends Annotation> extends InjectedAttribute<T>
{
- public String getName();
- public T getAnnotation();
- public Class getType();
- public void set(Object bean, Object value);
+
+ public String getContextVariableName();
public Object get(Object bean);
- public MetaModel getMetaModel();
+
}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -3,57 +3,43 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import org.jboss.seam.util.Reflections;
+
/**
* Implementation of BijectedAttribute for a field
* @author Pete Muir
*
*/
-public class BijectedField<T extends Annotation> implements BijectedAttribute<T>
+public abstract class BijectedField<T extends Annotation> extends InjectedField<T> implements BijectedAttribute<T>
+{
+ private String contextVariableName;
+
+ public BijectedField(Field field, T annotation)
{
- private String name;
- private Field field;
- private T annotation;
- private MetaModel metaModel;
-
- public BijectedField(String name, Field field, T annotation, MetaModel metaModel)
+ super(field, annotation);
+ contextVariableName = getSpecifiedContextVariableName();
+ if (contextVariableName == null || "".equals(contextVariableName))
{
- this.name = name;
- this.field = field;
- this.annotation = annotation;
- this.metaModel = metaModel;
+ contextVariableName = field.getName();
}
- public String getName()
- {
- return name;
- }
- public Field getField()
- {
- return field;
- }
- public T getAnnotation()
- {
- return annotation;
- }
- public Class getType()
- {
- return field.getType();
- }
- public void set(Object bean, Object value)
- {
- metaModel.setFieldValue(bean, field, name, value);
- }
- public Object get(Object bean)
- {
- return metaModel.getFieldValue(bean, field, name);
- }
- @Override
- public String toString()
- {
- return "BijectedField(" + name + ')';
- }
-
- public MetaModel getMetaModel()
- {
- return metaModel;
- }
- }
\ No newline at end of file
+ }
+
+ public Object get(Object bean)
+ {
+ field.setAccessible(true);
+ return Reflections.getAndWrap(field, bean);
+ }
+
+ public String getContextVariableName()
+ {
+ return contextVariableName;
+ }
+
+ protected abstract String getSpecifiedContextVariableName();
+
+ @Override
+ public String toString()
+ {
+ return "BijectedField(" + Reflections.toString(field) + ')';
+ }
+}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,58 +1,79 @@
package org.jboss.seam.wicket.ioc;
+import static org.jboss.seam.util.Reflections.invokeAndWrap;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import org.jboss.seam.util.Reflections;
+
/**
* Implementation of BijectedAttribute for a method
* @author Pete Muir
*
*/
-public class BijectedMethod<T extends Annotation> implements BijectedAttribute<T>
+public abstract class BijectedMethod<T extends Annotation> implements BijectedAttribute<T>
+{
+ private Method method;
+ private T annotation;
+ private String contextVariableName;
+
+ public BijectedMethod(Method method, T annotation)
{
- private String name;
- private Method method;
- private T annotation;
- private MetaModel metaModel;
-
- public BijectedMethod(String name, Method method, T annotation, MetaModel metaModel)
+ this.method = method;
+ this.annotation = annotation;
+ contextVariableName = getSpecifiedContextVariableName();
+ if (contextVariableName == null || "".equals(contextVariableName))
{
- this.name = name;
- this.method = method;
- this.annotation = annotation;
+ if ( method.getName().matches("^(get|set).*") && method.getParameterTypes().length==0 )
+ {
+ contextVariableName = method.getName().substring(3);
+ }
+ else if ( method.getName().matches("^(is).*") && method.getParameterTypes().length==0 )
+ {
+ contextVariableName = method.getName().substring(2);
+ }
}
- public String getName()
- {
- return name;
- }
- public Method getMethod()
- {
- return method;
- }
- public T getAnnotation()
- {
- return annotation;
- }
- public void set(Object bean, Object value)
- {
- metaModel.setPropertyValue(bean, method, name, value);
- }
- public Object get(Object bean)
- {
- return metaModel.getPropertyValue(bean, method, name);
- }
- public Class getType()
- {
- return method.getParameterTypes()[0];
- }
- @Override
- public String toString()
- {
- return "BijectedMethod(" + name + ')';
- }
-
- public MetaModel getMetaModel()
- {
- return metaModel;
- }
- }
\ No newline at end of file
+ }
+
+ public Method getMember()
+ {
+ return method;
+ }
+
+ public T getAnnotation()
+ {
+ return annotation;
+ }
+
+ public void set(Object bean, Object value)
+ {
+ method.setAccessible(true);
+ invokeAndWrap( method, bean, value );
+ }
+
+ public Object get(Object bean)
+ {
+ method.setAccessible(true);
+ return invokeAndWrap(method, bean);
+ }
+
+ public Class getType()
+ {
+ return method.getParameterTypes()[0];
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BijectedMethod(" + Reflections.toString(method) + ')';
+ }
+
+ protected abstract String getSpecifiedContextVariableName();
+
+ public String getContextVariableName()
+ {
+ return contextVariableName;
+ }
+
+}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,71 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import org.jboss.seam.util.Reflections;
-
-/**
- * Implementation of BijectedAttribute for a pair of methods
- * @author Pete Muir
- *
- */
-public class BijectedProperty<T extends Annotation> implements BijectedAttribute<T>
- {
-
- private BijectedMethod<T> getter;
- private BijectedMethod<T> setter;
- private MetaModel metaModel;
-
- public BijectedProperty(String name, Method getter, Method setter, T annotation, MetaModel metaModel)
- {
- this.getter = new BijectedMethod(name, getter, annotation, metaModel);
- this.setter = new BijectedMethod(name, setter, annotation, metaModel);
- }
-
- public BijectedProperty(String name, Method getter, T annotation, MetaModel metaModel)
- {
- this.getter = new BijectedMethod(name, getter, annotation, metaModel);
- try
- {
- Method setterMethod = Reflections.getSetterMethod(getter.getDeclaringClass(), name);
- this.setter = new BijectedMethod(name, setterMethod, annotation, metaModel);
- }
- catch (IllegalArgumentException e) {}
- }
-
- public Object get(Object bean)
- {
- return getter.get(bean);
- }
-
- public T getAnnotation()
- {
- return getter.getAnnotation();
- }
-
- public String getName()
- {
- return getter.getName();
- }
-
- public Class getType()
- {
- return getter.getType();
- }
-
- public void set(Object bean, Object value)
- {
- if (setter == null)
- {
- throw new IllegalArgumentException("Component must have a setter for " + metaModel.getName());
- }
- setter.set(bean, value);
- }
-
- public MetaModel getMetaModel()
- {
- return metaModel;
- }
-
- }
\ No newline at end of file
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,27 @@
+package org.jboss.seam.wicket.ioc;
+
+
+public class BijectionInterceptor<T> extends RootInterceptor<T>
+{
+
+ @Override
+ public void afterInvoke(InvocationContext<T> invocationContext)
+ {
+ invocationContext.getComponent().outject(invocationContext.getBean());
+ invocationContext.getComponent().disinject(invocationContext.getBean());
+ }
+
+ @Override
+ public void beforeInvoke(InvocationContext<T> invocationContext)
+ {
+ try
+ {
+ invocationContext.getComponent().inject(invocationContext.getBean());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,17 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+
+public interface InjectedAttribute<T extends Annotation>
+{
+
+ public abstract T getAnnotation();
+
+ public abstract Class getType();
+
+ public abstract void set(Object bean, Object value);
+
+ public abstract Member getMember();
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,47 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import org.jboss.seam.util.Reflections;
+
+public class InjectedField<T extends Annotation> implements InjectedAttribute<T>
+{
+
+ protected Field field;
+ protected T annotation;
+
+ public InjectedField(Field field, T annotation)
+ {
+ this.field = field;
+ this.annotation = annotation;
+ }
+
+ public Field getMember()
+ {
+ return field;
+ }
+
+ public T getAnnotation()
+ {
+ return annotation;
+ }
+
+ public Class getType()
+ {
+ return field.getType();
+ }
+
+ public void set(Object bean, Object value)
+ {
+ field.setAccessible(true);
+ Reflections.setAndWrap(field, bean, value);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "InjectedField(" + Reflections.toString(field) + ')';
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,36 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-import javassist.util.proxy.MethodHandler;
-
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.util.Reflections;
-
-public abstract class InjectionInterceptor implements MethodHandler, Serializable
-{
- private String name;
- private In annotation;
-
- public InjectionInterceptor(BijectedAttribute<In> in)
- {
- this.name = in.getName();
- this.annotation = in.getAnnotation();
- }
-
- 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(name, annotation, proxy), params);
- }
- else
- {
- return null;
- }
- }
-
- protected abstract Object getValueToInject(String name, In annotation, Object value);
-
-}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,168 +0,0 @@
-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;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-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
- *
- */
-public class Injector
-{
-
- // TODO Ouch
- private static final Map<Class, Class<ProxyObject>> proxyFactories = new HashMap<Class, Class<ProxyObject>>();
-
- private List<BijectedAttribute<In>> inAttributes = new ArrayList<BijectedAttribute<In>>();
-
- private final MetaModel metaModel;
-
- private static LogProvider log = Logging.getLogProvider(Injector.class);
-
- public Injector(MetaModel metaModel)
- {
- this.metaModel = metaModel;
- }
-
- public void add(Method method)
- {
- if ( method.isAnnotationPresent(In.class) )
- {
- In in = method.getAnnotation(In.class);
- String name = toName( in.value(), method );
- inAttributes.add( new BijectedMethod(name, method, in, metaModel) );
- }
- }
-
- public void add(Field field)
- {
- if ( field.isAnnotationPresent(In.class) )
- {
- In in = field.getAnnotation(In.class);
- String name = toName( in.value(), field );
- inAttributes.add( new BijectedField(name, field, in, metaModel) );
- }
- }
-
- public void inject(Object instance) throws Exception
- {
- for ( BijectedAttribute<In> in : inAttributes )
- {
- in.set( instance, wrap( in, metaModel.getMetaModelName() ) );
- }
- }
-
- private static Object wrap(final BijectedAttribute<In> in, final String metaModelName) throws Exception
- {
- ProxyObject proxy = getProxyFactory(in.getType()).newInstance();
- proxy.setHandler(new InjectionInterceptor(in)
- {
- @Override
- protected Object getValueToInject(String name, In annotation, Object value)
- {
- return getValue(name, annotation, metaModelName, value);
- }
- });
- return proxy;
- }
-
- private static Class<ProxyObject> getProxyFactory(Class type)
- {
- if (proxyFactories.containsKey(type))
- {
- return proxyFactories.get(type);
- }
- else
- {
- Class<ProxyObject> factory = createProxyFactory( type );
- proxyFactories.put(type, factory);
- return factory;
- }
- }
-
- 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);
- }
-
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,47 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jboss.seam.wicket.WicketComponent;
+
+public class InvocationContext<T>
+{
+
+ private Constructor<T> constructor;
+ private Method method;
+ private T bean;
+ private WicketComponent<T> component;
+
+ public InvocationContext(Method method, T bean, WicketComponent<T> component)
+ {
+ this.method = method;
+ this.bean = bean;
+ this.component = component;
+ }
+
+ public InvocationContext(Constructor<T> constructor, T bean, WicketComponent<T> component)
+ {
+ this.constructor = constructor;
+ this.bean = bean;
+ this.component = component;
+ }
+
+ public Constructor<T> getConstructor()
+ {
+ return constructor;
+ }
+ public Method getMethod()
+ {
+ return method;
+ }
+ public T getBean()
+ {
+ return bean;
+ }
+ public WicketComponent<T> getComponent()
+ {
+ return component;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,171 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.LoaderClassPath;
+import javassist.Modifier;
+import javassist.NotFoundException;
+import javassist.CtField.Initializer;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.wicket.WicketComponent;
+
+
+public class JavassistInstrumentor
+{
+
+ private static LogProvider log = Logging.getLogProvider(JavassistInstrumentor.class);
+
+ public static String DEFAULT_WICKET_COMPONENT_DIRECTORY_PATH = "WEB-INF/wicket";
+
+ private ClassLoader classLoader;
+
+ private final List<String> classes = new ArrayList<String>();
+ private File wicketComponentDirectory;
+ private ClassPool classPool = new ClassPool();
+
+ public JavassistInstrumentor(ServletContext servletContext)
+ {
+ wicketComponentDirectory = getWicketComponentDirectory(servletContext);
+ }
+
+ public void instrument() throws NotFoundException, CannotCompileException, ClassNotFoundException
+ {
+ ClassLoader parent = Thread.currentThread().getContextClassLoader();
+ classPool = new ClassPool();
+ classLoader = new WicketClassLoader(parent, classPool, classes);
+ classPool.insertClassPath(wicketComponentDirectory.getAbsolutePath());
+ classPool.insertClassPath(new LoaderClassPath(parent));
+
+ if (wicketComponentDirectory.exists())
+ {
+ // Scan for classes
+ handleDirectory(wicketComponentDirectory, null);
+ }
+
+ // Ensure classes are instantiated, and create metadata
+ for (String className : classes)
+ {
+ Class clazz = classLoader.loadClass(className);
+ new WicketComponent(clazz);
+ }
+ }
+
+ private static File getWicketComponentDirectory(ServletContext servletContext)
+ {
+ String path = servletContext.getRealPath(DEFAULT_WICKET_COMPONENT_DIRECTORY_PATH);
+ if (path==null) //WebLogic!
+ {
+ log.debug("Could not find path for " + DEFAULT_WICKET_COMPONENT_DIRECTORY_PATH);
+ }
+ else
+ {
+ File wicketComponentDir = new File(path);
+ if (wicketComponentDir.exists())
+ {
+ return wicketComponentDir;
+ }
+ }
+ return null;
+ }
+
+ private void handleDirectory(File file, String path) throws NotFoundException, CannotCompileException
+ {
+ log.debug("directory: " + file);
+ for ( File child: file.listFiles() )
+ {
+ String newPath = path==null ? child.getName() : path + '/' + child.getName();
+ if ( child.isDirectory() )
+ {
+ handleDirectory(child, newPath);
+ }
+ else
+ {
+ handleItem(newPath);
+ }
+ }
+ }
+
+ private void handleItem(String path) throws NotFoundException, CannotCompileException
+ {
+ if (path.endsWith(".class"))
+ {
+ String className = filenameToClassname(path);
+ instrumentClass(className, classPool);
+ }
+ }
+
+ protected static String filenameToClassname(String filename)
+ {
+ return filename.substring( 0, filename.lastIndexOf(".class") )
+ .replace('/', '.').replace('\\', '.');
+ }
+
+ private void instrumentClass(String className, ClassPool classPool) throws NotFoundException, CannotCompileException
+ {
+ log.debug("Instrumenting " + className);
+ CtClass implementation = classPool.get(className);
+ CtClass handlerClass = classPool.get(WicketHandler.class.getName());
+ CtField handlerField = new CtField(handlerClass, "handler", implementation);
+ Initializer handlerInitializer = Initializer.byCall(handlerClass, "create");
+ implementation.addField(handlerField, handlerInitializer);
+ for (CtMethod method : implementation.getDeclaredMethods())
+ {
+ if (!Modifier.isStatic(method.getModifiers()))
+ {
+ String methodName = method.getName();
+ String methodSignature = "";
+ for (int i = 0; i < method.getParameterTypes().length; i++)
+ {
+ if (i > 0)
+ {
+ methodSignature += ",";
+ }
+ methodSignature += method.getParameterTypes()[i].getName() + ".class";
+ }
+ String methodCall = "this.getClass().getDeclaredMethod(\""+ methodName + "\", methodParameters)";
+ String methodParameters;
+ if (methodSignature.length() > 0)
+ {
+ methodParameters = "Class[] methodParameters = {" + methodSignature + "};";
+ }
+ else
+ {
+ methodParameters = "Class[] methodParameters = new Class[0];";
+ }
+ log.trace("Method call: " + methodCall);
+
+ method.insertBefore(methodParameters + "handler.beforeInvoke(this, " + methodCall + ");");
+ method.insertAfter(methodParameters + "handler.afterInvoke(this, " + methodCall + ");");
+ log.trace("instrumented method " + method.getName());
+ }
+ }
+ for (CtConstructor constructor : implementation.getConstructors())
+ {
+ if (constructor.isConstructor())
+ {
+ constructor.insertBeforeBody("handler.beforeInvoke(this, null);");
+ constructor.insertAfter("handler.afterInvoke(this, null);");
+ log.trace("instrumented constructor " + constructor.getName());
+ }
+ }
+ classes.add(implementation.getName());
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,61 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.seam.util.Reflections;
-
-/**
- * Controls logging for a MetaModel
- *
- */
-public class Loggable
-{
-
- private List<Field> logFields = new ArrayList<Field>();
- private List<org.jboss.seam.log.Log> logInstances = new ArrayList<org.jboss.seam.log.Log>();
-
- private MetaModel metaModel;
-
- public Loggable(MetaModel metaModel)
- {
- this.metaModel = metaModel;
- }
-
- public void add(Field field)
- {
- if ( field.isAnnotationPresent(org.jboss.seam.annotations.Logger.class) )
- {
- String category = field.getAnnotation(org.jboss.seam.annotations.Logger.class).value();
- org.jboss.seam.log.Log logInstance;
- if ( "".equals( category ) )
- {
- logInstance = org.jboss.seam.log.Logging.getLog(metaModel.getBeanClass());
- }
- else
- {
- logInstance = org.jboss.seam.log.Logging.getLog(category);
- }
- if ( Modifier.isStatic( field.getModifiers() ) )
- {
- Reflections.setAndWrap(field, null, logInstance);
- }
- else
- {
- logFields.add(field);
- logInstances.add(logInstance);
- }
- }
- }
-
- public void inject(Object instance) throws Exception
- {
- for (int i=0; i<logFields.size(); i++)
- {
- metaModel.setFieldValue( instance, logFields.get(i), "log", logInstances.get(i) );
- }
- }
-
-}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,149 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import org.jboss.seam.Model;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.util.Reflections;
-
-/**
- * MetaModel for a component
- * @author pmuir
- *
- */
-public abstract class MetaModel extends Model
-{
-
- private Injector injectionSupport;
- private Outjector outjectionSupport;
- private Loggable loggerSupport;
-
- public MetaModel(Class<?> beanClass)
- {
- super(beanClass);
- injectionSupport = new Injector(this);
- outjectionSupport = new Outjector(this);
- loggerSupport = new Loggable(this);
- scan();
- }
-
- public void initialize()
- {
- scan();
- }
-
- public void inject(Object instance) throws Exception
- {
- injectionSupport.inject(instance);
- loggerSupport.inject(instance);
- }
-
- public void outject(Object instance)
- {
- outjectionSupport.outject(instance);
- }
-
- private void scan()
- {
- Class clazz = getBeanClass();
- for ( ; clazz!=Object.class; clazz = clazz.getSuperclass() )
- {
- for ( Method method: clazz.getDeclaredMethods() )
- {
- scanMethod(method);
- }
-
- for ( Field field: clazz.getDeclaredFields() )
- {
- scanField(field);
- }
- }
- }
-
- private void scanField(Field field)
- {
- if ( !field.isAccessible() )
- {
- field.setAccessible(true);
- }
- injectionSupport.add(field);
- loggerSupport.add(field);
- }
-
- private void scanMethod(Method method)
- {
- injectionSupport.add(method);
- }
-
- protected void setFieldValue(Object bean, Field field, String name, Object value)
- {
- try
- {
- Reflections.set(field, bean, value);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not set field value: " + getAttributeMessage(name), e);
- }
- }
-
- protected Object getFieldValue(Object bean, Field field, String name)
- {
- try {
- return Reflections.get(field, bean);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not get field value: " + getAttributeMessage(name), e);
- }
- }
-
- protected String getAttributeMessage(String attributeName)
- {
- return getName() + '.' + attributeName;
- }
-
- protected String getName()
- {
- return getBeanClass().getName();
- }
-
- protected abstract String getMetaModelName();
-
- protected void setPropertyValue(Object bean, Method method, String name, Object value)
- {
- try
- {
- Reflections.invoke(method, bean, value );
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not set property value: " + getAttributeMessage(name), e);
- }
- }
-
- public Object getPropertyValue(Object bean, Method method, String name)
- {
- try {
- return Reflections.invoke(method, bean);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not get property value: " + getAttributeMessage(name), e);
- }
- }
-
- public static MetaModel forName(String name)
- {
- if (Contexts.isApplicationContextActive())
- {
- return (MetaModel) Contexts.getApplicationContext().get(name);
- }
- else
- {
- throw new IllegalStateException("Application context is not active");
- }
- }
-
-}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,94 +0,0 @@
-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.toName;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.seam.RequiredException;
-import org.jboss.seam.annotations.Out;
-
-
-public class Outjector
-{
-
- private List<BijectedAttribute<Out>> outAttributes = new ArrayList<BijectedAttribute<Out>>();
-
- private MetaModel metaModel;
-
- public Outjector(MetaModel metaModel)
- {
- this.metaModel = metaModel;
- }
-
- public void add(Method method)
- {
- Out out = method.getAnnotation(Out.class);
- String name = toName( out.value(), method );
- outAttributes.add( new BijectedMethod(name, method, out, metaModel) );
- }
-
- public void add(Field field)
- {
- if ( field.isAnnotationPresent(Out.class) )
- {
- Out out = field.getAnnotation(Out.class);
- String name = toName( out.value(), field );
- outAttributes.add(new BijectedField(name, field, out, metaModel) );
- }
- }
-
- public void outject(Object instance)
- {
- for ( BijectedAttribute<Out> att: outAttributes )
- {
- outjectAttribute( att.getAnnotation(), att.getName(), instance, att.get(instance) );
- }
- }
-
- private void outjectAttribute(Out out, String name, Object bean, Object value)
- {
-
- if (value==null && out.required())
- {
- throw new RequiredException(
- "@Out attribute requires non-null value: " +
- metaModel.getAttributeMessage(name)
- );
- }
- else
- {
- if ( out.scope()==UNSPECIFIED )
- {
- throw new IllegalArgumentException(
- "Must specify a scope to outject to: " +
- metaModel.getAttributeMessage(name)
- );
- }
- else if ( out.scope()==STATELESS )
- {
- throw new IllegalArgumentException(
- "cannot specify explicit scope=STATELESS on @Out: " +
- metaModel.getAttributeMessage(name)
- );
- }
-
- if ( out.scope().isContextActive() )
- {
- if (value==null)
- {
- out.scope().getContext().remove(name);
- }
- else
- {
- out.scope().getContext().set(name, value);
- }
- }
- }
- }
-
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,13 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.io.Serializable;
+
+
+public abstract class RootInterceptor<T> implements Serializable
+{
+
+ public abstract void beforeInvoke(InvocationContext<T> invocationContext);
+
+ public abstract void afterInvoke(InvocationContext<T> invocationContext);
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,26 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.application.IComponentInstantiationListener;
-
-/**
- * Repsonsible for injecting dynamic proxies into Wicket classes
- *
- * @author Pete Muir
- */
-public class SeamInjectionListener implements IComponentInstantiationListener
-{
-
- public void onInstantiation(Component component)
- {
- WicketComponent wicketComponent = WicketComponent.forClass(component.getClass());
- try
- {
- wicketComponent.inject(component);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,45 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.util.List;
+
+import javassist.ClassPool;
+import javassist.Loader;
+
+public class WicketClassLoader extends Loader
+{
+
+ private List<String> classes;
+
+ public WicketClassLoader(List<String> classes)
+ {
+ super();
+ this.classes = classes;
+ }
+
+ public WicketClassLoader(ClassLoader parent, ClassPool cp, List<String> classes)
+ {
+ super(parent, cp);
+ this.classes = classes;
+ }
+
+ public WicketClassLoader(ClassPool cp, List<String> classes)
+ {
+ super(cp);
+ this.classes = classes;
+ }
+
+ @Override
+ protected Class loadClassByDelegation(String name) throws ClassNotFoundException
+ {
+ Class clazz = super.loadClassByDelegation(name);
+ if (clazz == null)
+ {
+ if (!classes.contains(name))
+ {
+ clazz = delegateToParent(name);
+ }
+ }
+ return clazz;
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,52 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import org.jboss.seam.contexts.Contexts;
-
-/**
- * MetaModel for Wicket components
- * @author pmuir
- *
- */
-public class WicketComponent extends MetaModel
-{
-
- public WicketComponent(Class<?> beanClass)
- {
- super(beanClass);
- }
-
- @Override
- protected String getMetaModelName()
- {
- return getComponentName(getBeanClass());
- }
-
- protected static String getComponentName(Class clazz)
- {
- return clazz.getName() + ".wicketComponent";
- }
-
- public static WicketComponent forClass(Class clazz)
- {
- if (Contexts.isApplicationContextActive())
- {
- String metaModelName = getComponentName(clazz);
- instantiate(metaModelName, clazz);
- return (WicketComponent) forName(metaModelName);
- }
- else
- {
- throw new IllegalStateException("Application context is not active");
- }
- }
-
- private static void instantiate(String componentName, Class clazz)
- {
- if (!Contexts.getApplicationContext().isSet(componentName))
- {
- WicketComponent component = new WicketComponent(clazz);
- Contexts.getApplicationContext().set(componentName, component);
- }
- }
-
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,92 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.wicket.WicketComponent;
+
+
+public class WicketHandler implements Serializable
+{
+
+ public static WicketHandler create(Object bean)
+ {
+ WicketHandler handler = new WicketHandler(bean.getClass());
+ return handler;
+ }
+
+ public WicketHandler(Class<?> type)
+ {
+ this.type = type;
+ }
+
+ private List<RootInterceptor> interceptors;
+ private Class<?> type;
+ private transient WicketComponent component;
+
+ public void init()
+ {
+
+
+ }
+
+ private WicketComponent getComponent()
+ {
+ if (component == null)
+ {
+ component = WicketComponent.getInstance(type);
+ }
+ return component;
+ }
+
+ private List<RootInterceptor> getInterceptors()
+ {
+ if (interceptors == null)
+ {
+ interceptors = new ArrayList<RootInterceptor>();
+ interceptors.add(new BijectionInterceptor());
+ }
+ return interceptors;
+ }
+
+ public void beforeInvoke(Object target, Method calledMethod)
+ {
+ beforeInvoke(new InvocationContext(calledMethod, target, getComponent()));
+ }
+
+ public void afterInvoke(Object target, Method calledMethod)
+ {
+ afterInvoke(new InvocationContext(calledMethod, target, getComponent()));
+ }
+
+ public void beforeInvoke(Object target, Constructor constructor)
+ {
+ beforeInvoke(new InvocationContext(constructor, target, getComponent()));
+ }
+
+ public void afterInvoke(Object target, Constructor constructor)
+ {
+ afterInvoke(new InvocationContext(constructor, target, getComponent()));
+ }
+
+ private void beforeInvoke(InvocationContext invocationContext)
+ {
+ for (RootInterceptor interceptor : getInterceptors())
+ {
+ interceptor.beforeInvoke(invocationContext);
+ }
+ }
+
+ private void afterInvoke(InvocationContext invocationContext)
+ {
+ invocationContext.getComponent().initialize(invocationContext.getBean());
+ for (RootInterceptor interceptor : getInterceptors())
+ {
+ interceptor.afterInvoke(invocationContext);
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -4,8 +4,12 @@
package org.jboss.seam.wicket.web;
import static org.jboss.seam.annotations.Install.BUILT_IN;
+import javassist.CannotCompileException;
+import javassist.NotFoundException;
import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
import org.apache.wicket.protocol.http.WicketFilter;
import org.jboss.seam.ScopeType;
@@ -14,6 +18,7 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Unwrap;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.wicket.ioc.JavassistInstrumentor;
@Name("org.jboss.seam.wicket.web.wicketFilterInstantiator")
@Install(precedence = BUILT_IN, classDependencies={"org.apache.wicket.Application"})
@@ -21,11 +26,46 @@
@Scope(ScopeType.STATELESS)
public class WicketFilterInstantiator
{
-
+
@Unwrap
public Filter unrwap()
{
- return new WicketFilter();
+ return new WicketFilter()
+ {
+
+ private ClassLoader classLoader;
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException
+ {
+ try
+ {
+ JavassistInstrumentor javassistInstrumentor = new JavassistInstrumentor(filterConfig.getServletContext());
+ javassistInstrumentor.instrument();
+ classLoader = javassistInstrumentor.getClassLoader();
+ }
+ catch (NotFoundException e)
+ {
+ throw new ServletException(e);
+ }
+ catch (CannotCompileException e)
+ {
+ throw new ServletException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ServletException(e);
+ }
+ super.init(filterConfig);
+ }
+
+ @Override
+ protected ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+
+ };
}
}
More information about the seam-commits
mailing list