Browse Source

Allow for ordering of mixed AspectJ before/after advices

Issue: SPR-9438
pull/230/head
Juergen Hoeller 12 years ago
parent
commit
2aaa66f86b
  1. 27
      spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java

27
spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,8 @@
package org.springframework.aop.aspectj.autoproxy; package org.springframework.aop.aspectj.autoproxy;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.aopalliance.aop.Advice; import org.aopalliance.aop.Advice;
@ -67,29 +67,24 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected List<Advisor> sortAdvisors(List<Advisor> advisors) { protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
// build list for sorting
List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors = List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors =
new LinkedList<PartiallyComparableAdvisorHolder>(); new ArrayList<PartiallyComparableAdvisorHolder>(advisors.size());
for (Advisor element : advisors) { for (Advisor element : advisors) {
partiallyComparableAdvisors.add( partiallyComparableAdvisors.add(
new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR)); new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
} }
// sort it
List<PartiallyComparableAdvisorHolder> sorted = List<PartiallyComparableAdvisorHolder> sorted =
PartialOrder.sort(partiallyComparableAdvisors); PartialOrder.sort(partiallyComparableAdvisors);
if (sorted == null) { if (sorted != null) {
// TODO: work harder to give a better error message here. List<Advisor> result = new ArrayList<Advisor>(advisors.size());
throw new IllegalArgumentException("Advice precedence circularity error"); for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
result.add(pcAdvisor.getAdvisor());
}
return result;
} }
else {
// extract results again return super.sortAdvisors(advisors);
List<Advisor> result = new LinkedList<Advisor>();
for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
result.add(pcAdvisor.getAdvisor());
} }
return result;
} }
/** /**

Loading…
Cancel
Save