[jboss-cvs] JBossAS SVN: r75344 - projects/aop/trunk/aop/src/main/org/jboss/aop.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 3 07:30:46 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-07-03 07:30:46 -0400 (Thu, 03 Jul 2008)
New Revision: 75344
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
Log:
[JBAOP-607] Make what is done once we have read the annotations pluggable. In AOP we still install things directly into the AspectManager.
(When running in MC/AS5 we need to create AspectManagerAwareBeanMetaDataFactories and install those in the MC)
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java 2008-07-03 11:28:02 UTC (rev 75343)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java 2008-07-03 11:30:46 UTC (rev 75344)
@@ -41,31 +41,15 @@
import javassist.bytecode.annotation.MemberValue;
import javassist.bytecode.annotation.StringMemberValue;
-import org.jboss.aop.advice.AdviceBinding;
-import org.jboss.aop.advice.AdviceFactory;
-import org.jboss.aop.advice.AspectDefinition;
import org.jboss.aop.advice.AspectFactory;
-import org.jboss.aop.advice.AspectFactoryDelegator;
-import org.jboss.aop.advice.AspectFactoryWithClassLoader;
-import org.jboss.aop.advice.DynamicCFlowDefinition;
-import org.jboss.aop.advice.GenericAspectFactory;
import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.advice.InterceptorFactory;
-import org.jboss.aop.advice.PrecedenceDef;
import org.jboss.aop.advice.PrecedenceDefEntry;
import org.jboss.aop.advice.Scope;
-import org.jboss.aop.advice.ScopedInterceptorFactory;
import org.jboss.annotation.factory.javassist.AnnotationProxy;
-import org.jboss.aop.introduction.AnnotationIntroduction;
import org.jboss.aop.introduction.InterfaceIntroduction;
import org.jboss.aop.pointcut.CFlow;
import org.jboss.aop.pointcut.CFlowStack;
-import org.jboss.aop.pointcut.DeclareDef;
import org.jboss.aop.pointcut.DynamicCFlow;
-import org.jboss.aop.pointcut.Pointcut;
-import org.jboss.aop.pointcut.PointcutExpression;
-import org.jboss.aop.pointcut.Typedef;
-import org.jboss.aop.pointcut.TypedefExpression;
import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
import org.jboss.aop.pointcut.ast.ASTStart;
import org.jboss.aop.pointcut.ast.PointcutExpressionParser;
@@ -88,17 +72,35 @@
protected AspectManager manager;
private ClassLoader cl;
+ private final AspectAnnotationLoaderStrategy loaderStrategy;
public AspectAnnotationLoader(AspectManager manager)
{
this.manager = manager;
+ loaderStrategy = new AspectManagerAnnotationLoaderStrategy();
}
+
+ public AspectAnnotationLoader(AspectManager manager, AspectManagerAnnotationLoaderStrategy loaderStrategy)
+ {
+ this.manager = manager;
+ this.loaderStrategy = this.loaderStrategy;
+ }
public void setClassLoader(ClassLoader cl)
{
this.cl = cl;
}
+ public AspectManager getAspectManager()
+ {
+ return manager;
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return cl;
+ }
+
public void deployInputStreamIterator(Iterator<InputStream> it) throws Exception
{
while (it.hasNext())
@@ -125,19 +127,19 @@
AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
if (visible != null)
{
- AspectDefinition def = deployAspect(visible, cf);
+ boolean deployed = deployAspect(visible, cf);
- if (def == null)
+ if (!deployed)
{
- def = deployInterceptor(visible, cf);
+ deployed = deployInterceptor(visible, cf);
}
- if (def == null)
+ if (!deployed)
{
deployDynamicCFlow(visible, cf);
}
- if (def == null)
+ if (!deployed)
{
if (!deployPreparedClass(visible, cf))
{
@@ -199,7 +201,7 @@
}
}
- private AspectDefinition deployAspect(AnnotationsAttribute visible, ClassFile cf) throws Exception
+ private boolean deployAspect(AnnotationsAttribute visible, ClassFile cf) throws Exception
{
//Check for Aspect
javassist.bytecode.annotation.Annotation info = visible.getAnnotation(Aspect.class.getName());
@@ -219,27 +221,16 @@
break;
}
}
- AspectFactory factory = null;
- if (isFactory)
- {
- factory = new AspectFactoryDelegator(cf.getName(), null);
- ((AspectFactoryWithClassLoader)factory).setClassLoader(cl);
- }
- else
- {
- factory = new GenericAspectFactory(cf.getName(), null);
- ((AspectFactoryWithClassLoader)factory).setClassLoader(cl);
- }
- AspectDefinition def = new AspectDefinition(cf.getName(), scope, factory);
- manager.addAspectDefinition(def);
+
+ loaderStrategy.deployAspect(this, isFactory, cf.getName(), scope);
if (!isFactory)
{
- deployAspectMethodBindings(cf, def);
+ deployAspectMethodBindings(cf, cf.getName());
}
- return def;
+ return true;
}
- return null;
+ return false;
}
private void undeployAspect(AnnotationsAttribute visible, ClassFile cf) throws Exception
@@ -249,13 +240,13 @@
if (info != null)
{
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Undeploying @Aspect in: " + cf.getName());
- manager.removeAspectDefinition(cf.getName());
+ loaderStrategy.undeployAspect(this, cf.getName());
undeployAspectMethodBindings(cf);
}
}
- private AspectDefinition deployInterceptor(AnnotationsAttribute visible, ClassFile cf) throws Exception
+ private boolean deployInterceptor(AnnotationsAttribute visible, ClassFile cf) throws Exception
{
//Check for InterceptorDef
javassist.bytecode.annotation.Annotation info = visible.getAnnotation(InterceptorDef.class.getName());
@@ -280,29 +271,14 @@
}
}
- AspectFactory aspectFactory;
- if (isFactory)
- {
- aspectFactory = new AspectFactoryDelegator(cf.getName(), null);
- ((AspectFactoryWithClassLoader)aspectFactory).setClassLoader(cl);
- }
- else
- {
- aspectFactory = new GenericAspectFactory(cf.getName(), null);
- ((AspectFactoryWithClassLoader)aspectFactory).setClassLoader(cl);
- }
+ loaderStrategy.deployInterceptor(this, isFactory, cf.getName(), scope);
- AspectDefinition def = new AspectDefinition(cf.getName(), scope, aspectFactory);
- manager.addAspectDefinition(def);
- ScopedInterceptorFactory factory = new ScopedInterceptorFactory(def);
- manager.addInterceptorFactory(factory.getName(), factory);
+ deployInterceptorBindings(visible, cf, cf.getName());
- deployInterceptorBindings(visible, cf, factory);
-
- return def;
+ return true;
}
- return null;
+ return false;
}
private void undeployInterceptor(AnnotationsAttribute visible, ClassFile cf) throws Exception
@@ -314,11 +290,10 @@
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Undeploying @InterceptorDef in: " + cf.getName());
AnnotationProxy.createProxy(info, Aspect.class);
- manager.removeAspectDefinition(cf.getName());
- manager.removeInterceptorFactory(cf.getName());
+ loaderStrategy.undeployInterceptor(this, cf.getName());
+
undeployInterceptorBindings(visible, cf);
}
-
}
private void deployDynamicCFlow(AnnotationsAttribute visible, ClassFile cf) throws Exception
@@ -344,7 +319,7 @@
}
if (!foundDCFlow) throw new RuntimeException("@DynamicCFlow annotated class: " + clazz + " must implement " + DynamicCFlow.class.getName());
- manager.addDynamicCFlow(name, new DynamicCFlowDefinition(null, clazz, name));
+ loaderStrategy.deployDynamicCFlow(this, clazz, name);
}
}
@@ -355,7 +330,7 @@
{
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Undeploying @DynamicCFlowDef in: " + cf.getName());
String name = cf.getName();
- manager.removeDynamicCFlow(name);
+ loaderStrategy.undeployDynamicCFlow(this, name);
}
}
@@ -370,8 +345,7 @@
String name = cf.getName() + "." + visible.getName();
String expr = replaceThisInExpr(prepare.value(), cf.getName());
- Pointcut p = new PointcutExpression(name, expr);
- manager.addPointcut(p);
+ loaderStrategy.deployPointcut(this, name, expr);
return true;
}
@@ -385,7 +359,7 @@
if (info != null)
{
String name = cf.getName() + "." + visible.getName();
- manager.removePointcut(name);
+ loaderStrategy.undeployPointcut(this, name);
}
}
@@ -421,8 +395,7 @@
}
}
PrecedenceDefEntry[] pentries = entries.toArray(new PrecedenceDefEntry[entries.size()]);
- PrecedenceDef precedenceDef = new PrecedenceDef(cf.getName(), pentries);
- manager.addPrecedence(precedenceDef);
+ loaderStrategy.deployPrecedence(this, cf.getName(), pentries);
}
}
@@ -431,11 +404,11 @@
javassist.bytecode.annotation.Annotation info = visible.getAnnotation(Precedence.class.getName());
if (info != null)
{
- manager.removePrecedence(cf.getName());
+ loaderStrategy.undeployPrecedence(this, cf.getName());
}
}
- private void deployAspectMethodBindings(ClassFile cf, AspectDefinition def)
+ private void deployAspectMethodBindings(ClassFile cf, String aspectDefName/*, AspectDefinition def*/)
throws Exception
{
Iterator<MethodInfo> methods = cf.getMethods().iterator();
@@ -458,22 +431,8 @@
}
org.jboss.aop.advice.AdviceType internalAdviceType = getInternalAdviceType(binding.type());
- AdviceFactory factory = null;
- if (internalAdviceType == org.jboss.aop.advice.AdviceType.AROUND)
- {
- factory = new AdviceFactory(def, minfo.getName());
- }
- else
- {
- factory = new AdviceFactory(def, minfo.getName(), internalAdviceType);
- }
-
- manager.addInterceptorFactory(factory.getName(), factory);
- InterceptorFactory[] fact = {factory};
- String name = getAspectMethodBindingName(cf, minfo);
- PointcutExpression pointcut = new PointcutExpression(name, pointcutString);
- AdviceBinding abinding = new AdviceBinding(name, pointcut, cflowExpression, cflow, fact);
- manager.addBinding(abinding);
+ String bindingName = getAspectMethodBindingName(cf, minfo);
+ loaderStrategy.deployAspectMethodBinding(this, internalAdviceType, aspectDefName, minfo.getName(), bindingName, pointcutString, cflow, cflowExpression);
}
}
@@ -515,11 +474,8 @@
javassist.bytecode.annotation.Annotation binfo = mgroup.getAnnotation(Bind.class.getName());
if (binfo == null) continue;
- String adviceName = cf.getName() + "." + minfo.getName();
- manager.removeInterceptorFactory(adviceName);
- String name = getAspectMethodBindingName(cf, minfo);
- manager.removePointcut(name);
- manager.removeBinding(name);
+ String bindingName = getAspectMethodBindingName(cf, minfo);
+ loaderStrategy.undeployAspectMethodBinding(this, bindingName, cf.getName(), minfo.getName());
}
}
@@ -530,7 +486,7 @@
return method + " " + MethodHashing.createHash(fullMethod);
}
- private void deployInterceptorBindings(AnnotationsAttribute visible, ClassFile cf, InterceptorFactory factory)
+ private void deployInterceptorBindings(AnnotationsAttribute visible, ClassFile cf, String name)
throws Exception
{
javassist.bytecode.annotation.Annotation binfo = visible.getAnnotation(Bind.class.getName());
@@ -546,12 +502,7 @@
}
- String name = cf.getName();
- InterceptorFactory[] inters = {factory};
- Pointcut p = null;
- p = new PointcutExpression(name, pointcutString);
- AdviceBinding binding = new AdviceBinding(name, p, cflowExpression, cflow, inters);
- manager.addBinding(binding);
+ loaderStrategy.deployInterceptorBinding(this, name, pointcutString, cflow, cflowExpression);
}
private void undeployInterceptorBindings(AnnotationsAttribute visible, ClassFile cf)
@@ -560,9 +511,7 @@
javassist.bytecode.annotation.Annotation binfo = visible.getAnnotation(Bind.class.getName());
if (binfo == null) return;
- String name = cf.getName();
- manager.removePointcut(name);
- manager.removeBinding(name);
+ loaderStrategy.undeployInterceptorBinding(this, cf.getName());
}
@@ -579,9 +528,7 @@
if (binfo == null) continue;
PointcutDef pdef = (PointcutDef) AnnotationProxy.createProxy(binfo, PointcutDef.class);
- PointcutExpression pointcut = new PointcutExpression(getPointcutName(cf, finfo), pdef.value());
-
- manager.addPointcut(pointcut);
+ loaderStrategy.deployPointcut(this, getPointcutName(cf, finfo), pdef.value());
}
}
@@ -596,7 +543,7 @@
if (mgroup == null) continue;
javassist.bytecode.annotation.Annotation binfo = mgroup.getAnnotation(PointcutDef.class.getName());
if (binfo == null) continue;
- manager.removePointcut(getPointcutName(cf, finfo));
+ loaderStrategy.undeployPointcut(this, getPointcutName(cf, finfo));
}
}
@@ -720,7 +667,7 @@
intro.getMixins().add(new InterfaceIntroduction.Mixin(classname, interfaces, construction, isTransient));
- manager.addInterfaceIntroduction(intro);
+ loaderStrategy.deployInterfaceIntroduction(this, intro);
}
}
@@ -737,7 +684,7 @@
if (binfo == null) continue;
String name = cf.getName() + "." + minfo.getName(); //Name of the method defined on
- manager.removeInterfaceIntroduction(name);
+ loaderStrategy.undeployInterfaceIntroduction(this, name);
}
}
@@ -777,7 +724,7 @@
String name = cf.getName() + "." + finfo.getName(); //Name of the field defined on
InterfaceIntroduction interfaceIntro = createIntroduction(name, target, typeExpression, interfaces, null, null);
- manager.addInterfaceIntroduction(interfaceIntro);
+ loaderStrategy.deployInterfaceIntroduction(this, interfaceIntro);
}
}
@@ -795,7 +742,7 @@
String name = cf.getName() + "." + finfo.getName(); //Name of the field defined on
- manager.removeInterfaceIntroduction(name);
+ loaderStrategy.undeployInterfaceIntroduction(this, name);
}
}
@@ -813,9 +760,8 @@
String name = getTypedefName(cf, finfo);
String expr = typeDefinition.value();
- Typedef typedef = new TypedefExpression(name, expr);
- manager.addTypedef(typedef);
-
+
+ loaderStrategy.deployTypedef(this, name, expr);
}
}
@@ -832,8 +778,7 @@
AnnotationProxy.createProxy(binfo, TypeDef.class);
- manager.removeTypedef(getTypedefName(cf, finfo));
-
+ loaderStrategy.undeployTypedef(this, getTypedefName(cf, finfo));
}
}
@@ -865,7 +810,7 @@
stack.addCFlow(new CFlow(cflow.expr(), not));
}
- manager.addCFlowStack(stack);
+ loaderStrategy.deployCFlow(this, stack);
}
}
@@ -881,7 +826,7 @@
if (binfo == null) continue;
AnnotationProxy.createProxy(binfo, CFlowStackDef.class);
- manager.removeCFlowStack(getStackDefName(cf, finfo));
+ loaderStrategy.undeployCFlow(this, getStackDefName(cf, finfo));
}
}
@@ -904,8 +849,7 @@
String name = getPrepareName(cf, finfo);
String expr = prepare.value();
- Pointcut p = new PointcutExpression(name, expr);
- manager.addPointcut(p);
+ loaderStrategy.deployPointcut(this, name, expr);
}
}
@@ -921,7 +865,7 @@
if (binfo == null) continue;
AnnotationProxy.createProxy(binfo, Prepare.class);
- manager.removePointcut(getPrepareName(cf, finfo));
+ loaderStrategy.undeployPointcut(this, getPrepareName(cf, finfo));
}
}
@@ -948,8 +892,7 @@
annotation = annotation.replace('\'', '"');
- AnnotationIntroduction annIntro = AnnotationIntroduction.createComplexAnnotationIntroduction(expr, annotation, invisible);
- manager.addAnnotationIntroduction(annIntro);
+ loaderStrategy.deployAnnotationIntroduction(this, expr, annotation, invisible);
}
}
@@ -971,8 +914,7 @@
annotation = annotation.replace('\'', '"');
- AnnotationIntroduction annIntro = AnnotationIntroduction.createComplexAnnotationIntroduction(expr, annotation, invisible);
- manager.removeAnnotationIntroduction(annIntro);
+ loaderStrategy.undeployAnnotationIntroduction(this, expr, annotation, invisible);
}
}
@@ -1007,9 +949,8 @@
msg = dwarning.msg();
warning = true;
}
- DeclareDef def = new DeclareDef(name, expr, warning, msg);
-
- manager.addDeclare(def);
+
+ loaderStrategy.deployDeclare(this, name, expr, warning, msg);
}
}
More information about the jboss-cvs-commits
mailing list