KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > containers > FieldsChangeEventListener


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
//
15

16
17
18 package org.jahia.services.containers;
19
20 import org.jahia.data.fields.JahiaField;
21 import org.jahia.data.events.JahiaEvent;
22 import org.jahia.data.events.JahiaEventListener;
23 import org.jahia.exceptions.*;
24 import org.jahia.services.fields.ContentField;
25
26 /**
27  * Listener for fields change events.
28  * Used mainly for cache synchronization
29  *
30  * You must access this Singleton through JahiaListenersRegistry
31  *
32  * @see JahiaListenersRegistry
33  * @author Khue Nguyen <a HREF="mailto:khue@jahia.org">khue@jahia.org</a>
34  */

35 public class FieldsChangeEventListener extends JahiaEventListener
36 {
37
38     private static org.apache.log4j.Logger logger =
39             org.apache.log4j.Logger.getLogger (FieldsChangeEventListener.class);
40
41     private static final String JavaDoc CLASS_NAME = FieldsChangeEventListener.class.getName();
42
43     public static final String JavaDoc FIELD_ADDED = "fieldAdded";
44     public static final String JavaDoc FIELD_UPDATED = "fieldUpdated";
45     public static final String JavaDoc FIELD_DELETED = "fieldDeleted";
46
47     public FieldsChangeEventListener() throws JahiaException {
48     }
49
50     //--------------------------------------------------------------------------
51
/**
52      * triggered when Jahia adds a field
53      *
54      * @param je the associated JahiaEvent
55      */

56     public void fieldAdded( JahiaEvent je ) {
57         JahiaField theField = (JahiaField) je.getObject();
58         if ( theField != null ){
59             notifyChange(theField.getID());
60         }
61     }
62
63     //--------------------------------------------------------------------------
64
/**
65      * triggered when Jahia updates a field
66      *
67      * @param je the associated JahiaEvent
68      */

69     public void fieldUpdated( JahiaEvent je ) {
70         JahiaField theField = (JahiaField) je.getObject();
71         if ( theField != null ){
72             notifyChange(theField.getID());
73         }
74     }
75
76     //--------------------------------------------------------------------------
77
/**
78      * triggered when Jahia deletes a field
79      *
80      * @param je the associated JahiaEvent
81      */

82     public void fieldDeleted( JahiaEvent je ) {
83         JahiaField theField = (JahiaField) je.getObject();
84         if ( theField != null ){
85             notifyChange(theField.getID());
86         }
87     }
88
89     //--------------------------------------------------------------------------
90
/**
91      * Update related caches :
92      * - field IDs by container cache
93      *
94      * @param fieldId
95      */

96     public synchronized void notifyChange( int fieldId ) {
97         try {
98             ContentField contentField = ContentField.getField(fieldId);
99             notifyChange(contentField);
100         } catch ( JahiaException je ){
101             logger.debug("Exception looking for field " + fieldId, je);
102         }
103     }
104
105     //--------------------------------------------------------------------------
106
/**
107      * Update related caches :
108      * - field IDs by container cache
109      *
110      * @param ContentField contentField
111      */

112     public synchronized void notifyChange( ContentField contentField ) {
113
114         if ( contentField == null ){
115             return;
116         }
117         ContentContainerTools.getInstance()
118             .invalidateFieldIDsByContainerFromCache(contentField.getContainerID());
119     }
120
121 }
122
Popular Tags