KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > appmappersistence > AppMappingsInterceptor


1 /*
2  * Shark Hibernate AppMapPersistence - Open Wide
3  */

4
5 package org.enhydra.shark.appmappersistence;
6
7 import java.io.Serializable JavaDoc;
8 import java.util.Iterator JavaDoc;
9
10 import net.sf.hibernate.CallbackException;
11 import net.sf.hibernate.Interceptor;
12 import net.sf.hibernate.type.Type;
13
14 import org.enhydra.shark.utilities.hibernate.HibernateUtilities;
15
16
17 /**
18  * Class that allow to intercept entities and in this case to replace null value
19  * by an precise value.
20  * @author Vladislav Pernin
21  *
22  */

23 public class AppMappingsInterceptor implements Interceptor, Serializable JavaDoc {
24
25     public boolean onLoad(Object JavaDoc entity,Serializable JavaDoc id,Object JavaDoc[] state,String JavaDoc[] propertyNames,Type[] types) throws CallbackException {
26         if ( entity instanceof HibernateApplicationMap ) {
27             for ( int i=0; i<propertyNames.length; i++ ) {
28                 if (("processDefId".equals( propertyNames[i])) && (((String JavaDoc)state[i]).equals(HibernateUtilities.NULL_VALUE_FOR_PROCID))) {
29                     state[i] = null;
30                     return true;
31                 }
32             }
33         }
34         return false;
35     }
36
37     public boolean onFlushDirty(Object JavaDoc entity,Serializable JavaDoc id,Object JavaDoc[] currentState,Object JavaDoc[] previousState,String JavaDoc[] propertyNames,Type[] types) throws CallbackException {
38         if ( entity instanceof HibernateApplicationMap ) {
39             for ( int i=0; i<propertyNames.length; i++ ) {
40                 if (("processDefId".equals( propertyNames[i])) && (((String JavaDoc)currentState[i] == null) || ((String JavaDoc)currentState[i]).trim().equals("")) ) {
41                     currentState[i] = HibernateUtilities.NULL_VALUE_FOR_PROCID;
42                     return true;
43                 }
44             }
45         }
46         return false;
47     }
48
49     
50     public boolean onSave(Object JavaDoc entity,Serializable JavaDoc id,Object JavaDoc[] state,String JavaDoc[] propertyNames,Type[] types) throws CallbackException {
51         if ( entity instanceof HibernateApplicationMap ) {
52             for ( int i=0; i<propertyNames.length; i++ ) {
53                 if (("processDefId".equals( propertyNames[i])) && (((String JavaDoc)state[i] == null) || ((String JavaDoc)state[i]).trim().equals("")) ) {
54                     state[i] = HibernateUtilities.NULL_VALUE_FOR_PROCID;
55                     return true;
56                 }
57             }
58         }
59         return false;
60     }
61
62
63     public void onDelete(Object JavaDoc arg0, Serializable JavaDoc arg1, Object JavaDoc[] arg2, String JavaDoc[] arg3, Type[] arg4) throws CallbackException {
64     }
65
66     
67     public Boolean JavaDoc isUnsaved(Object JavaDoc arg0) {
68         return null;
69     }
70
71     
72     public int[] findDirty(Object JavaDoc arg0, Serializable JavaDoc arg1, Object JavaDoc[] arg2, Object JavaDoc[] arg3, String JavaDoc[] arg4, Type[] arg5) {
73         return null;
74     }
75
76
77     public Object JavaDoc instantiate(Class JavaDoc arg0, Serializable JavaDoc arg1) throws CallbackException {
78         return null;
79     }
80
81     
82     public void preFlush(Iterator JavaDoc arg0) throws CallbackException {
83     }
84
85     public void postFlush(Iterator JavaDoc arg0) throws CallbackException {
86     }
87
88 }
89
Popular Tags