[seam-commits] Seam SVN: r10147 - trunk/src/wicket/org/jboss/seam/wicket/ioc.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Mar 12 13:22:18 EDT 2009
Author: cpopetz
Date: 2009-03-12 13:22:18 -0400 (Thu, 12 Mar 2009)
New Revision: 10147
Added:
trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamWicketComponent.java
Modified:
trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketInstrumentationTask.java
Log:
JBSEAM-4001 Wicket Instrumentation Annotation
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2009-03-12 15:51:07 UTC (rev 10146)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2009-03-12 17:22:18 UTC (rev 10147)
@@ -116,10 +116,21 @@
*/
private CtClass instrumentedComponent;
+ /**
+ * If true, only instrument classes annotated with @WicketComponent and their non-static inner classes.
+ */
+ private boolean scanAnnotations;
public JavassistInstrumentor(ClassPool classPool)
{
+ this(classPool,false);
+ }
+
+ public JavassistInstrumentor(ClassPool classPool, boolean scanAnnotations)
+ {
this.classPool = classPool;
+ this.scanAnnotations = scanAnnotations;
+
try
{
instrumentedComponent = classPool.get(InstrumentedComponent.class.getName());
@@ -138,10 +149,11 @@
public CtClass instrumentClass(String className) throws NotFoundException, CannotCompileException
{
- log.debug("Instrumenting " + className);
+ log.debug("Examining " + className);
CtClass implementation = classPool.get(className);
if (isInstrumentable(implementation))
{
+ log.debug("Instrumenting " + className);
instrumentClass(implementation);
}
return implementation;
@@ -324,7 +336,7 @@
* @param clazz The class to check
* @return
*/
- private boolean isInstrumentable(CtClass clazz)
+ public boolean isInstrumentable(CtClass clazz)
{
int modifiers = clazz.getModifiers();
if (Modifier.isInterface(modifiers) || Modifier.isEnum(modifiers))
@@ -335,8 +347,9 @@
try
{
// do not instrument @Named components or nested non-static classes
- // inside named components
+ // inside named components.
CtClass checkName = clazz;
+ boolean hasWicketComponentAnnotation = false;
do
{
for (Object a : checkName.getAnnotations())
@@ -345,11 +358,20 @@
{
return false;
}
+ else if (scanAnnotations && a instanceof SeamWicketComponent)
+ {
+ hasWicketComponentAnnotation = true;
+ }
}
checkName = Modifier.isStatic(clazz.getModifiers()) ? null : checkName.getDeclaringClass();
}
while (checkName != null);
+ if (scanAnnotations && !hasWicketComponentAnnotation)
+ {
+ return false;
+ }
+
// do not instrument something we've already instrumented.
// can't use 'isSubtype' because the superclass may be instrumented
// while we are not
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamWicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamWicketComponent.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamWicketComponent.java 2009-03-12 17:22:18 UTC (rev 10147)
@@ -0,0 +1,22 @@
+package org.jboss.seam.wicket.ioc;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Specifies that a class should be instrumented to allow for use as a Seam Wicket component
+ * @author Clint Popetz
+ *
+ */
+ at Target(TYPE)
+ at Retention(RUNTIME)
+ at Documented
+public @interface SeamWicketComponent
+{
+}
+
+
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketInstrumentationTask.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketInstrumentationTask.java 2009-03-12 15:51:07 UTC (rev 10146)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketInstrumentationTask.java 2009-03-12 17:22:18 UTC (rev 10147)
@@ -49,7 +49,19 @@
{
this.fileset = fileset;
}
+
+ private boolean useAnnotations = false;
+ public boolean isUseAnnotations()
+ {
+ return useAnnotations;
+ }
+
+ public void setUseAnnotations(boolean useAnnotations)
+ {
+ this.useAnnotations = useAnnotations;
+ }
+
@Override
public void execute()
{
@@ -58,10 +70,10 @@
ClassPool classPool = new ClassPool();
classPool.insertClassPath(new LoaderClassPath(getProject().createClassLoader(buildPath)));
-
+
List<CtClass> instrumentedClasses = new ArrayList<CtClass>();
- JavassistInstrumentor instrumentor = new JavassistInstrumentor(classPool);
+ JavassistInstrumentor instrumentor = new JavassistInstrumentor(classPool,useAnnotations);
for (String file : fileset.getDirectoryScanner(getProject()).getIncludedFiles())
{
More information about the seam-commits
mailing list