[jboss-cvs] JBossAS SVN: r72423 - in projects/aop/trunk/aop/src/main/org/jboss/aop: util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 18 04:46:41 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-04-18 04:46:41 -0400 (Fri, 18 Apr 2008)
New Revision: 72423
Added:
projects/aop/trunk/aop/src/main/org/jboss/aop/util/JoinPointComparator.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
Log:
Add methods to compare chains of JoinPointInfos
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java 2008-04-18 08:38:37 UTC (rev 72422)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java 2008-04-18 08:46:41 UTC (rev 72423)
@@ -69,6 +69,7 @@
import org.jboss.aop.metadata.MethodMetaData;
import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.aop.pointcut.PointcutMethodMatch;
+import org.jboss.aop.util.JoinPointComparator;
import org.jboss.aop.util.UnmodifiableEmptyCollections;
import org.jboss.metadata.spi.MetaData;
import org.jboss.metadata.spi.signature.ConstructorSignature;
@@ -347,7 +348,7 @@
{
return resolveTypedAnnotation(annotation);
}
-
+
public <T extends Annotation> T resolveTypedAnnotation(Class<T> annotation)
{
if (metadata != null)
@@ -421,7 +422,7 @@
{
return resolveTypedAnnotation(0, m, annotation);
}
-
+
public <T extends Annotation> T resolveTypedAnnotation(Method m, Class<T> annotation)
{
return resolveTypedAnnotation(0, m, annotation);
@@ -431,7 +432,7 @@
{
return resolveTypedAnnotation(hash, m, annotation);
}
-
+
public <T extends Annotation> T resolveTypedAnnotation(long hash, Method m, Class<T> annotation)
{
if (metadata != null)
@@ -450,7 +451,7 @@
//MUST call this instead of AR.resolveTypedClassAnnotation since EJB3 overrides AR.resolveClassAnnotation
T value = (T)annotations.resolveAnnotation(m, annotation);
- if (value == null && metadata == null)
+ if (value == null && metadata == null)
{
value = AnnotationElement.getVisibleAnnotation(m, annotation);
}
@@ -482,7 +483,7 @@
{
return resolveTypedAnnotation(f, annotation);
}
-
+
public <T extends Annotation> T resolveTypedAnnotation(Field f, Class<T> annotation)
{
T value = null;
@@ -496,7 +497,7 @@
if (value != null) return value;
}
}
-
+
//MUST call this instead of AR.resolveTypedClassAnnotation since EJB3 overrides AR.resolveClassAnnotation
value = (T)annotations.resolveAnnotation(f, annotation);
if (value == null && metadata == null)
@@ -510,7 +511,7 @@
{
return resolveTypedAnnotation(c, annotation);
}
-
+
public <T extends Annotation> T resolveTypedAnnotation(Constructor<?> c, Class<T> annotation)
{
T value = null;
@@ -524,7 +525,7 @@
if (value != null) return value;
}
}
-
+
//MUST call this instead of AR.resolveTypedClassAnnotation since EJB3 overrides AR.resolveClassAnnotation
value = (T)annotations.resolveAnnotation(c, annotation);
if (value == null && metadata == null)
@@ -582,7 +583,7 @@
{
return hasAnnotation(m, annotation.getName());
}
-
+
public boolean hasAnnotation(Field m, String annotation)
{
if (metadata != null)
@@ -647,7 +648,7 @@
}
return false;
}
-
+
public boolean hasAnnotation(CtClass clazz, String annotation)
{
if (annotations.hasClassAnnotation(annotation)) return true;
@@ -684,7 +685,7 @@
/**
* Get the metadata
- *
+ *
* @return the metadata
*/
public MetaData getMetadata()
@@ -694,7 +695,7 @@
/**
* Set the metadata
- *
+ *
* FIXME why does this have java.lang.Object signature?
* @param metadata the metadata
*/
@@ -743,7 +744,7 @@
public synchronized void addInterfaceIntroduction(InterfaceIntroduction pointcut)
{
- initInterfaceIntroductionsList();
+ initInterfaceIntroductionsList();
interfaceIntroductions.add(pointcut);
}
@@ -763,12 +764,12 @@
public abstract void removeClassMetaData(ClassMetaDataBinding data);
// This is aspect stuff. Aspect again, is a class that encapsulates advices
-
+
public Object getPerVMAspect(AspectDefinition def)
{
return getManager().getPerVMAspect(def);
}
-
+
public void addPerInstanceAspect(AspectDefinition def)
{
initPerInstanceAspectDefinitionsSet();
@@ -813,7 +814,7 @@
}
setJoinpoints.addAll(joinpoints);
}
-
+
public void removePerInstanceJoinpointAspect(AspectDefinition def)
{
perInstanceJoinpointAspectDefinitions.remove(def);
@@ -896,7 +897,7 @@
{
Method method = (Method) advisedMethods.get(keys[i]);
PointcutMethodMatch match = binding.getPointcut().matchesExecution(this, method);
-
+
if (match != null && match.isMatch())
{
adviceBindings.add(binding);
@@ -931,7 +932,7 @@
methodMatchInfo.getInfo().getInterceptorChainReadWriteLock().writeLock().lock();
}
}
-
+
protected void unlockWriteChain(MethodInterceptors methodInterceptors)
{
Object[] methodMatchInfos = methodInterceptors.infos.getValues();
@@ -941,7 +942,7 @@
methodMatchInfo.getInfo().getInterceptorChainReadWriteLock().writeLock().unlock();
}
}
-
+
protected void resetChain(MethodInterceptors methodInterceptors)
{
Object[] methodMatchInfos = methodInterceptors.infos.getValues();
@@ -959,12 +960,12 @@
methodMatchInfo.getInfo().clear();
}
}
-
+
protected void finalizeMethodChain()
{
boolean maintain = AspectManager.maintainAdvisorMethodInterceptors;
TLongObjectHashMap newMethodInfos = (maintain) ? new TLongObjectHashMap() : null;
-
+
long[] keys = methodInfos.keys();
for (int i = 0; i < keys.length; i++)
{
@@ -978,7 +979,7 @@
interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()]));
}
info.setInterceptors(interceptors);
-
+
if (maintain)
{
newMethodInfos.put(keys[i], info);
@@ -1146,7 +1147,7 @@
info.setInterceptors(interceptors);
}
}
-
+
protected void lockWriteChain(JoinPointInfo[] infos)
{
for (int i = 0; i < infos.length; i++)
@@ -1154,7 +1155,7 @@
infos[i].getInterceptorChainReadWriteLock().writeLock().lock();
}
}
-
+
protected void unlockWriteChain(JoinPointInfo[] infos)
{
for (int i = 0; i < infos.length; i++)
@@ -1162,7 +1163,7 @@
infos[i].getInterceptorChainReadWriteLock().writeLock().unlock();
}
}
-
+
protected void resetChain(JoinPointInfo[] infos)
{
for (int i = 0; i < infos.length; i++)
@@ -1170,9 +1171,9 @@
infos[i].clear();
}
}
+
+
-
-
// protected void finalizeConstructionChain(ArrayList newConstructionInfos)
// {
// for (int i = 0; i < newConstructionInfos.size(); i++)
@@ -1296,7 +1297,7 @@
//Implemented by base-classes
throw new NotImplementedException("Not a legal operation for Advisor");
}
-
+
interface DeployAnnotationOverrideAction
{
void deploy(Advisor advisor, AnnotationIntroduction introduction);
@@ -1336,7 +1337,7 @@
}
};
}
-
+
public void cleanup()
{
//AspectDefinitions have strong links back to us
@@ -1345,7 +1346,7 @@
removePerInstanceAspect(def);
def.unregisterAdvisor(this);
}
-
+
for(AspectDefinition def : perInstanceJoinpointAspectDefinitions.keySet())
{
removePerInstanceJoinpointAspect(def);
@@ -1361,13 +1362,13 @@
defs[i].unregisterAdvisor(this);
}
}
-
+
if (methodInfos != null)
{
methodInfos. clear();
}
}
-
+
protected void initInterfaceIntroductionsList()
{
if (interfaceIntroductions == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
@@ -1381,7 +1382,7 @@
}
}
}
-
+
protected void initClassMetaDataBindingsList()
{
if (classMetaDataBindings == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
@@ -1395,7 +1396,7 @@
}
}
}
-
+
protected void initPerInstanceAspectDefinitionsSet()
{
if (perInstanceAspectDefinitions == UnmodifiableEmptyCollections.EMPTY_COPYONWRITE_ARRAYSET)
@@ -1409,7 +1410,7 @@
}
}
}
-
+
protected void initPerInstanceJoinpointAspectDefinitionsMap()
{
if (perInstanceJoinpointAspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
@@ -1437,5 +1438,22 @@
}
}
}
+
+ public boolean hasSameMethodAspects(Advisor other)
+ {
+ long[] keys = this.methodInfos.infos.keys();
+ for (int i = 0 ; i < keys.length ; i++)
+ {
+ MethodInfo myInfo = this.getMethodInfo(keys[i]);
+ MethodInfo otherInfo = other.getMethodInfo(keys[i]);
+
+ if (!JoinPointComparator.hasSameChains(myInfo, otherInfo))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/util/JoinPointComparator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/util/JoinPointComparator.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/util/JoinPointComparator.java 2008-04-18 08:46:41 UTC (rev 72423)
@@ -0,0 +1,98 @@
+/*
+* 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.util;
+
+import org.jboss.aop.JoinPointInfo;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JoinPointComparator
+{
+ public static boolean hasSameChains(JoinPointInfo myInfo, JoinPointInfo otherInfo)
+ {
+ if (myInfo != null && otherInfo != null)
+ {
+ if (!hasSameInterceptors(myInfo, otherInfo))
+ {
+ return false;
+ }
+ if (!hasSameInterceptorChains(myInfo, otherInfo))
+ {
+ return false;
+ }
+ }
+ else if (myInfo == null && otherInfo == null)
+ {
+ //same
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public static boolean hasSameInterceptors(JoinPointInfo myInfo, JoinPointInfo otherInfo)
+ {
+ if (myInfo.getInterceptors() != null && otherInfo.getInterceptors() != null)
+ {
+ if (myInfo.getInterceptors().length != otherInfo.getInterceptors().length)
+ {
+ return false;
+ }
+ else if (myInfo.getInterceptors() == null && otherInfo.getInterceptors() == null)
+ {
+ //same
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean hasSameInterceptorChains(JoinPointInfo myInfo, JoinPointInfo otherInfo)
+ {
+ if (myInfo.getInterceptorChain() != null && otherInfo.getInterceptorChain() != null)
+ {
+ if (myInfo.getInterceptorChain().size() != otherInfo.getInterceptorChain().size())
+ {
+ return false;
+ }
+ else if (myInfo.getInterceptorChain() == null && otherInfo.getInterceptorChain() == null)
+ {
+ //same
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list