KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > dao > annotation > PersistenceExceptionTranslationAdvisor


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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 AbstractPointcutAdvisor {
42
43     private final PersistenceExceptionTranslationInterceptor advice;
44
45     private final AnnotationMatchingPointcut pointcut;
46
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 JavaDoc<? extends Annotation JavaDoc> repositoryAnnotationType) {
56
57         this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator);
58         this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType);
59     }
60
61     /**
62      * Create a new PersistenceExceptionTranslationAdvisor.
63      * @param beanFactory the ListableBeanFactory to obtaining all
64      * PersistenceExceptionTranslators from
65      * @param repositoryAnnotationType the annotation type to check for
66      */

67     PersistenceExceptionTranslationAdvisor(
68             ListableBeanFactory beanFactory, Class JavaDoc<? extends Annotation JavaDoc> repositoryAnnotationType) {
69
70         this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory);
71         this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType);
72     }
73
74
75     public Advice getAdvice() {
76         return this.advice;
77     }
78
79     public Pointcut getPointcut() {
80         return this.pointcut;
81     }
82
83 }
84
Popular Tags