01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.dao.annotation;
18:
19: import java.lang.annotation.Annotation;
20:
21: import org.aopalliance.aop.Advice;
22:
23: import org.springframework.aop.Pointcut;
24: import org.springframework.aop.support.AbstractPointcutAdvisor;
25: import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
26: import org.springframework.beans.factory.ListableBeanFactory;
27: import org.springframework.dao.support.PersistenceExceptionTranslationInterceptor;
28: import org.springframework.dao.support.PersistenceExceptionTranslator;
29:
30: /**
31: * Spring AOP exception translation aspect for use at Repository or DAO layer level.
32: * Translates native persistence exceptions into Spring's DataAccessException hierarchy,
33: * based on a given PersistenceExceptionTranslator.
34: *
35: * @author Rod Johnson
36: * @author Juergen Hoeller
37: * @since 2.0
38: * @see org.springframework.dao.DataAccessException
39: * @see org.springframework.dao.support.PersistenceExceptionTranslator
40: */
41: public class PersistenceExceptionTranslationAdvisor extends
42: AbstractPointcutAdvisor {
43:
44: private final PersistenceExceptionTranslationInterceptor advice;
45:
46: private final AnnotationMatchingPointcut pointcut;
47:
48: /**
49: * Create a new PersistenceExceptionTranslationAdvisor.
50: * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use
51: * @param repositoryAnnotationType the annotation type to check for
52: */
53: public PersistenceExceptionTranslationAdvisor(
54: PersistenceExceptionTranslator persistenceExceptionTranslator,
55: Class<? extends Annotation> repositoryAnnotationType) {
56:
57: this .advice = new PersistenceExceptionTranslationInterceptor(
58: persistenceExceptionTranslator);
59: this .pointcut = new AnnotationMatchingPointcut(
60: repositoryAnnotationType);
61: }
62:
63: /**
64: * Create a new PersistenceExceptionTranslationAdvisor.
65: * @param beanFactory the ListableBeanFactory to obtaining all
66: * PersistenceExceptionTranslators from
67: * @param repositoryAnnotationType the annotation type to check for
68: */
69: PersistenceExceptionTranslationAdvisor(
70: ListableBeanFactory beanFactory,
71: Class<? extends Annotation> repositoryAnnotationType) {
72:
73: this .advice = new PersistenceExceptionTranslationInterceptor(
74: beanFactory);
75: this .pointcut = new AnnotationMatchingPointcut(
76: repositoryAnnotationType);
77: }
78:
79: public Advice getAdvice() {
80: return this .advice;
81: }
82:
83: public Pointcut getPointcut() {
84: return this.pointcut;
85: }
86:
87: }
|