[jboss-cvs] JBossAS SVN: r61142 - in projects/aop/trunk/aop: src/main/org/jboss/aop and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Mar 6 07:37:58 EST 2007
Author: kabir.khan at jboss.com
Date: 2007-03-06 07:37:58 -0500 (Tue, 06 Mar 2007)
New Revision: 61142
Added:
projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/
projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/
projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleCallbackBinding.java
projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleManager.java
Modified:
projects/aop/trunk/aop/
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java
Log:
[JBAOP-372] AOP support for lifecycle callbacks needed by the microcontainer
Property changes on: projects/aop/trunk/aop
___________________________________________________________________
Name: svn:ignore
- output
build.log
TEST-org.jboss.test.aop.*.txt
junit*.properties
comments.txt
jbossAgent.dll
jboss-aop-dist.zip
local.properties
org
*.class
+ output
build.log
TEST-org.jboss.test.aop.*.txt
junit*.properties
comments.txt
jbossAgent.dll
jboss-aop-dist.zip
local.properties
org
*.class
aopc.tmpdir
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2007-03-06 12:33:42 UTC (rev 61141)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2007-03-06 12:37:58 UTC (rev 61142)
@@ -42,7 +42,6 @@
import org.jboss.aop.advice.AdviceBinding;
import org.jboss.aop.advice.AdviceStack;
import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.AspectFactory;
import org.jboss.aop.advice.AspectFactoryWithClassLoader;
import org.jboss.aop.advice.DynamicCFlowDefinition;
import org.jboss.aop.advice.InterceptorFactory;
@@ -61,6 +60,8 @@
import org.jboss.aop.metadata.ClassMetaDataBinding;
import org.jboss.aop.metadata.ClassMetaDataLoader;
import org.jboss.aop.metadata.SimpleClassMetaDataLoader;
+import org.jboss.aop.microcontainer.lifecycle.LifecycleCallbackBinding;
+import org.jboss.aop.microcontainer.lifecycle.LifecycleManager;
import org.jboss.aop.pointcut.CFlowStack;
import org.jboss.aop.pointcut.DeclareDef;
import org.jboss.aop.pointcut.DynamicCFlow;
@@ -170,7 +171,7 @@
//Keeps track of if we need to convert references etc for a given class. Domains for scoped classloaders will have their own version of this
protected static InterceptionMarkers interceptionMarkers = new InterceptionMarkers();
-
+
// Static -------------------------------------------------------
protected static AspectManager manager;
@@ -178,6 +179,9 @@
public static boolean debugClasses;//If true, the generated advisor instrumentor will output the generated classes
public static ClassLoaderValidation classLoaderValidator;
+ //Keep track of the microcontainer lifecycle callbacks
+ public LifecycleManager lifecycleManager = new LifecycleManager(this);
+
/**
* logging switch. We don't use log4j to avoid another heavy library
*/
@@ -1940,6 +1944,32 @@
return copied;
}
+ public void addLifecycleDefinition(AspectDefinition def)
+ {
+ lifecycleManager.addLifecycleDefinition(def);
+ }
+
+ public void removeLifecycleDefinition(String name)
+ {
+ lifecycleManager.removeLifecycleDefinition(name);
+ }
+
+ public void addLifecycleBinding(LifecycleCallbackBinding lifecycleBinding)
+ {
+ lifecycleManager.addLifecycleBinding(lifecycleBinding);
+ }
+
+ public Map<String, LifecycleCallbackBinding> getLifecycleBindings()
+ {
+ return lifecycleManager.getLifecycleBindings();
+ }
+
+ public void removeLifecycleBinding(String name)
+ {
+ lifecycleManager.removeLifecycleBinding(name);
+ }
+
+
/*
public void dumpSubDomainsAndAdvisors(int indent)
{
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java 2007-03-06 12:33:42 UTC (rev 61141)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java 2007-03-06 12:37:58 UTC (rev 61142)
@@ -24,6 +24,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -33,6 +34,7 @@
import org.jboss.aop.advice.AspectDefinition;
import org.jboss.aop.advice.InterceptorFactory;
import org.jboss.aop.metadata.ClassMetaDataLoader;
+import org.jboss.aop.microcontainer.lifecycle.LifecycleCallbackBinding;
import org.jboss.aop.pointcut.CFlowStack;
import org.jboss.aop.pointcut.DynamicCFlow;
import org.jboss.aop.pointcut.Pointcut;
@@ -706,7 +708,29 @@
return super.findClassMetaDataLoader(group);
}
+
+ public Map<String, LifecycleCallbackBinding> getLifecycleBindings()
+ {
+ if (inheritsBindings)
+ {
+ if (!parentFirst)
+ {
+ // when child first, parent bindings go in first so that they can be overridden by child.
+ LinkedHashMap map = new LinkedHashMap(parent.getLifecycleBindings());
+ map.putAll(super.getLifecycleBindings());
+ return map;
+ }
+ else
+ {
+ LinkedHashMap map = new LinkedHashMap(super.getLifecycleBindings());
+ map.putAll(parent.getLifecycleBindings());
+ return map;
+ }
+ }
+ return super.getLifecycleBindings();
+ }
+
//////////////////////////////////////////////////////////////////////////
//Methods that should delegate to the top AspectManager
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java 2007-03-06 12:33:42 UTC (rev 61141)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java 2007-03-06 12:37:58 UTC (rev 61142)
@@ -35,9 +35,13 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
+
import org.jboss.aop.advice.AdviceBinding;
import org.jboss.aop.introduction.AnnotationIntroduction;
+import org.jboss.aop.microcontainer.lifecycle.LifecycleCallbackBinding;
import org.jboss.aop.pointcut.AnnotationMatcher;
import org.jboss.aop.pointcut.PointcutMethodMatch;
import org.jboss.aop.proxy.container.InstanceProxyContainer;
@@ -60,16 +64,17 @@
protected Advisor advisor;
protected boolean isInstanceContainer;
TLongObjectHashMap methodMap = new TLongObjectHashMap();
+
+ //Lifecycle callbacks are a microcontainer thing
+ protected Map<Object, Set<String>> lifecycleCallbacks = new HashMap<Object, Set<String>>();
+ boolean initialisedAspects;
+ boolean intitialisedLifecycleCallbacks;
-
public ReflectiveAspectBinder(Class clazz, Advisor advisor)
{
this.clazz = clazz;
this.advisor = advisor;
isInstanceContainer = InstanceProxyContainer.class == advisor.getClass();
- bindMethodAdvices(clazz);
- bindConstructorAdvices();
- bindFieldAdvices();
}
public Class getClazz()
@@ -79,9 +84,24 @@
public HashSet getAspects()
{
+ if (!initialisedAspects)
+ {
+ bindMethodAdvices(clazz);
+ bindConstructorAdvices();
+ bindFieldAdvices();
+ }
return aspects;
}
+ public Map<Object, Set<String>> getLifecycleCallbacks()
+ {
+ if (!intitialisedLifecycleCallbacks)
+ {
+ bindLifecycles();
+ }
+ return lifecycleCallbacks;
+ }
+
public HashMap getMethodAdvices()
{
return methodAdvices;
@@ -291,4 +311,28 @@
}
}
}
+
+ protected void bindLifecycles()
+ {
+ for (LifecycleCallbackBinding binding : advisor.getManager().getLifecycleBindings().values())
+ {
+ if (binding.matches(advisor, clazz))
+ {
+ final Object state = binding.getControllerState();
+ Set<String> callbacks = lifecycleCallbacks.get(state);
+ if (callbacks == null)
+ {
+ callbacks = new HashSet<String>();
+ lifecycleCallbacks.put(state, callbacks);
+ }
+
+ List<String> boundCallbacks = binding.getLifecycleCallbacks();
+ for (String callback : boundCallbacks)
+ {
+ System.out.println("=====> Adding lifecycle " + callback + ":" + state);
+ callbacks.add(callback);
+ }
+ }
+ }
+ }
}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleCallbackBinding.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleCallbackBinding.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleCallbackBinding.java 2007-03-06 12:37:58 UTC (rev 61142)
@@ -0,0 +1,137 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.microcontainer.lifecycle;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.pointcut.TypeMatcher;
+import org.jboss.aop.pointcut.Util;
+import org.jboss.aop.pointcut.ast.ASTStart;
+import org.jboss.aop.pointcut.ast.ClassExpression;
+import org.jboss.aop.pointcut.ast.TypeExpressionParser;
+
+/**
+ * A binding for callbacks for when a MC bean reaches a certain state
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LifecycleCallbackBinding
+{
+ /**
+ * The name of this binding
+ */
+ protected String name;
+
+ /**
+ * The class to match
+ */
+ protected ClassExpression classes;
+
+ /**
+ * A type expression picking out the classes to apply this to
+ */
+ protected ASTStart ast;
+
+ /**
+ * A list of beans
+ */
+ List<String> lifecycleCallbacks = new ArrayList();
+
+ /**
+ * This will be an instance of org.jboss.dependency.spi.ControllerState from the MC project
+ */
+ Object controllerState;
+
+ public LifecycleCallbackBinding(String name, String classString, String typeExpression, Object controllerState) throws Exception
+ {
+ this.name = name;
+
+ if (classString == null && typeExpression == null)
+ {
+ throw new RuntimeException("Need either classString or typeExpression");
+ }
+ if (classString != null && typeExpression != null)
+ {
+ throw new RuntimeException("Should not use both classString and typeExpression");
+ }
+
+ if (classString != null)
+ {
+ this.classes = new ClassExpression(classString);
+ }
+ else if (typeExpression != null)
+ {
+ this.ast = new TypeExpressionParser(new StringReader(typeExpression)).Start();
+ }
+
+ this.controllerState = controllerState;
+ }
+ public String getName()
+ {
+ return name;
+ }
+
+ public void addLifecycleCallback(String name)
+ {
+ lifecycleCallbacks.add(name);
+ }
+
+ public List<String> getLifecycleCallbacks()
+ {
+ return lifecycleCallbacks;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this) return true;
+ if (!(obj instanceof LifecycleCallbackBinding)) return false;
+ return ((LifecycleCallbackBinding) obj).getName().equals(name);
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ public boolean matches(Advisor advisor, Class clazz)
+ {
+ if (classes != null)
+ {
+ return Util.matchesClassExpr(classes, clazz, advisor);
+ }
+ else
+ {
+ TypeMatcher matcher = new TypeMatcher(advisor, clazz);
+ return ((Boolean) ast.jjtAccept(matcher, null)).booleanValue();
+ }
+ }
+
+ public Object getControllerState()
+ {
+ return controllerState;
+ }
+
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleManager.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/microcontainer/lifecycle/LifecycleManager.java 2007-03-06 12:37:58 UTC (rev 61142)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.microcontainer.lifecycle;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AspectDefinition;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LifecycleManager
+{
+ AspectManager manager;
+ Map<String, AspectDefinition> lifecycles = new LinkedHashMap<String, AspectDefinition>();
+ Map<String, LifecycleCallbackBinding> lifecycleBindings = new LinkedHashMap<String, LifecycleCallbackBinding>();
+
+ public LifecycleManager(AspectManager manager)
+ {
+ this.manager = manager;
+ }
+
+ public void addLifecycleDefinition(AspectDefinition def)
+ {
+ AspectDefinition old = lifecycles.put(def.getName(), def);
+ if (old != null)
+ {
+ old.undeploy();
+ }
+ }
+
+ public void removeLifecycleDefinition(String name)
+ {
+ lifecycles.remove(name);
+ }
+
+ public void addLifecycleBinding(LifecycleCallbackBinding lifecycleBinding)
+ {
+ lifecycleBindings.put(lifecycleBinding.getName(), lifecycleBinding);
+ }
+
+ public void removeLifecycleBinding(String name)
+ {
+ lifecycleBindings.remove(name);
+ }
+
+ public Map<String, LifecycleCallbackBinding> getLifecycleBindings()
+ {
+ return lifecycleBindings;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list