KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > jpa > conf > EntityCallbackAnnotationProcessorFactory


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20
21 package org.apache.cayenne.jpa.conf;
22
23 import java.lang.reflect.AnnotatedElement JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25
26 import org.apache.cayenne.jpa.map.JpaAbstractEntity;
27 import org.apache.cayenne.jpa.map.JpaLifecycleCallback;
28
29 class EntityCallbackAnnotationProcessorFactory extends AnnotationProcessorFactory {
30
31     static abstract class AbstractCallbackAnnotationProcessor implements
32             AnnotationProcessor {
33
34         public void onStartElement(
35                 AnnotatedElement JavaDoc element,
36                 AnnotationProcessorStack context) {
37
38             Method JavaDoc m = (Method JavaDoc) element;
39             updateEntity((JpaAbstractEntity) context.peek(), new JpaLifecycleCallback(m
40                     .getName()));
41         }
42
43         public void onFinishElement(
44                 AnnotatedElement JavaDoc element,
45                 AnnotationProcessorStack context) {
46             // noop...
47
}
48
49         abstract void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback);
50     }
51
52     static final class PrePersistProcessor extends AbstractCallbackAnnotationProcessor {
53
54         @Override JavaDoc
55         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
56             entity.setPrePersist(callback);
57         }
58     }
59
60     static final class PostPersistProcessor extends AbstractCallbackAnnotationProcessor {
61
62         @Override JavaDoc
63         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
64             entity.setPostPersist(callback);
65         }
66     }
67
68     static final class PreRemoveProcessor extends AbstractCallbackAnnotationProcessor {
69
70         @Override JavaDoc
71         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
72             entity.setPreRemove(callback);
73         }
74     }
75
76     static final class PostRemoveProcessor extends AbstractCallbackAnnotationProcessor {
77
78         @Override JavaDoc
79         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
80             entity.setPostRemove(callback);
81         }
82     }
83
84     static final class PreUpdateProcessor extends AbstractCallbackAnnotationProcessor {
85
86         @Override JavaDoc
87         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
88             entity.setPreUpdate(callback);
89         }
90     }
91
92     static final class PostUpdateProcessor extends AbstractCallbackAnnotationProcessor {
93
94         @Override JavaDoc
95         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
96             entity.setPostUpdate(callback);
97         }
98     }
99
100     static final class PostLoadProcessor extends AbstractCallbackAnnotationProcessor {
101
102         @Override JavaDoc
103         void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) {
104             entity.setPostLoad(callback);
105         }
106     }
107 }
108
Popular Tags