diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index e4a55a067d..9cc93f3d28 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -681,6 +681,23 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence public boolean matches(Method method, Class targetClass) { return !this.adviceMethod.equals(method); } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof AdviceExcludingMethodMatcher)) { + return false; + } + AdviceExcludingMethodMatcher otherMm = (AdviceExcludingMethodMatcher) other; + return this.adviceMethod.equals(otherMm.adviceMethod); + } + + @Override + public int hashCode() { + return this.adviceMethod.hashCode(); + } } } diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java b/org.springframework.aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java index 0f1d1b4bec..4f4dd6c391 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,4 +56,21 @@ public class AnnotationMethodMatcher extends StaticMethodMatcher { return (specificMethod != method && specificMethod.isAnnotationPresent(this.annotationType)); } + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof AnnotationMethodMatcher)) { + return false; + } + AnnotationMethodMatcher otherMm = (AnnotationMethodMatcher) other; + return this.annotationType.equals(otherMm.annotationType); + } + + @Override + public int hashCode() { + return this.annotationType.hashCode(); + } + } diff --git a/org.springframework.context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java b/org.springframework.context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java index 413a9c1dcd..f910e812b5 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import org.springframework.util.Assert; * {@code CacheOperationSource}. * * @author Costin Leau + * @author Juergen Hoeller * @since 3.1 */ @SuppressWarnings("serial") @@ -71,6 +72,16 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati this.annotationParsers.add(new SpringCacheAnnotationParser()); } + /** + * Create a custom AnnotationCacheOperationSource. + * @param annotationParser the CacheAnnotationParser to use + */ + public AnnotationCacheOperationSource(CacheAnnotationParser annotationParser) { + this.publicMethodsOnly = true; + Assert.notNull(annotationParser, "CacheAnnotationParser must not be null"); + this.annotationParsers = Collections.singleton(annotationParser); + } + /** * Create a custom AnnotationCacheOperationSource. * @param annotationParsers the CacheAnnotationParser to use @@ -83,6 +94,16 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati this.annotationParsers = parsers; } + /** + * Create a custom AnnotationCacheOperationSource. + * @param annotationParsers the CacheAnnotationParser to use + */ + public AnnotationCacheOperationSource(Set annotationParsers) { + this.publicMethodsOnly = true; + Assert.notEmpty(annotationParsers, "At least one CacheAnnotationParser needs to be specified"); + this.annotationParsers = annotationParsers; + } + @Override protected Collection findCacheOperations(Class clazz) { @@ -106,7 +127,6 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati */ protected Collection determineCacheOperations(AnnotatedElement ae) { Collection ops = null; - for (CacheAnnotationParser annotationParser : this.annotationParsers) { Collection annOps = annotationParser.parseCacheAnnotations(ae); if (annOps != null) { @@ -126,4 +146,24 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati protected boolean allowPublicMethodsOnly() { return this.publicMethodsOnly; } + + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof AnnotationCacheOperationSource)) { + return false; + } + AnnotationCacheOperationSource otherCos = (AnnotationCacheOperationSource) other; + return (this.annotationParsers.equals(otherCos.annotationParsers) && + this.publicMethodsOnly == otherCos.publicMethodsOnly); + } + + @Override + public int hashCode() { + return this.annotationParsers.hashCode(); + } + } diff --git a/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java b/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java index 07280ead2b..9114dfc633 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -135,7 +135,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria return ops; } - private static Collection getAnnotations(AnnotatedElement ae, Class annotationType) { + private Collection getAnnotations(AnnotatedElement ae, Class annotationType) { Collection anns = new ArrayList(2); // look at raw annotation @@ -154,4 +154,15 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria return (anns.isEmpty() ? null : anns); } -} \ No newline at end of file + + @Override + public boolean equals(Object other) { + return (this == other || other instanceof SpringCacheAnnotationParser); + } + + @Override + public int hashCode() { + return SpringCacheAnnotationParser.class.hashCode(); + } + +} diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java index ffebe02a1b..f30ebe7de0 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -147,4 +147,23 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa return this.publicMethodsOnly; } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof AnnotationTransactionAttributeSource)) { + return false; + } + AnnotationTransactionAttributeSource otherTas = (AnnotationTransactionAttributeSource) other; + return (this.annotationParsers.equals(otherTas.annotationParsers) && + this.publicMethodsOnly == otherTas.publicMethodsOnly); + } + + @Override + public int hashCode() { + return this.annotationParsers.hashCode(); + } + } diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java index bb0f960a03..7171b5318b 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,16 @@ public class Ejb3TransactionAnnotationParser implements TransactionAnnotationPar return new Ejb3TransactionAttribute(ann.value()); } + @Override + public boolean equals(Object other) { + return (this == other || other instanceof Ejb3TransactionAnnotationParser); + } + + @Override + public int hashCode() { + return Ejb3TransactionAnnotationParser.class.hashCode(); + } + /** * EJB3-specific TransactionAttribute, implementing EJB3's rollback rules @@ -58,6 +68,7 @@ public class Ejb3TransactionAnnotationParser implements TransactionAnnotationPar setPropagationBehaviorName(PREFIX_PROPAGATION + type.name()); } + @Override public boolean rollbackOn(Throwable ex) { ApplicationException ann = ex.getClass().getAnnotation(ApplicationException.class); return (ann != null ? ann.rollback() : super.rollbackOn(ex)); diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java index 3468c2dc28..4e9db4f3f7 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,4 +76,14 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP return rbta; } + @Override + public boolean equals(Object other) { + return (this == other || other instanceof SpringTransactionAnnotationParser); + } + + @Override + public int hashCode() { + return SpringTransactionAnnotationParser.class.hashCode(); + } + }