KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > container > persistence > TimestampDOListener


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: TimestampDOListener.java,v $
31  * Revision 1.2 2005/04/09 17:19:58 colinmacleod
32  * Changed copyright text to GPL v2 explicitly.
33  *
34  * Revision 1.1.1.1 2005/03/10 17:51:32 colinmacleod
35  * Restructured ivata op around Hibernate/PicoContainer.
36  * Renamed ivata groupware.
37  *
38  * -----------------------------------------------------------------------------
39  */

40 package com.ivata.groupware.container.persistence;
41
42 import org.apache.log4j.Logger;
43
44 import com.ivata.groupware.admin.security.server.SecuritySession;
45 import com.ivata.groupware.container.persistence.listener.AddPersistenceListener;
46 import com.ivata.groupware.container.persistence.listener.AmendPersistenceListener;
47 import com.ivata.mask.persistence.PersistenceException;
48 import com.ivata.mask.persistence.PersistenceSession;
49 import com.ivata.mask.valueobject.ValueObject;
50
51 /**
52  * This class handles the timestamp properties when objects are added to or
53  * amended in the store.
54  * @since ivata groupware 0.10 (2005-01-17)
55  * @author Colin MacLeod
56  * <a HREF="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
57  * @version $Revision: 1.2 $
58  */

59 public class TimestampDOListener implements AddPersistenceListener,
60         AmendPersistenceListener {
61     /**
62      * Refer to {@link Logger}.
63      */

64     private Logger log = Logger.getLogger(TimestampDOListener.class);
65     /**
66      * Constructor. Registers this listener with the persistence manager.
67      * @param persistenceManager used to register this listener against
68      * subclasses of <code>TimestampDO</code>.
69      */

70     public TimestampDOListener(QueryPersistenceManager persistenceManager) {
71         persistenceManager.addAddListener(TimestampDO.class,
72                 this);
73         persistenceManager.addAmendListener(TimestampDO.class,
74                 this);
75     }
76
77     /**
78      * Refer to {@link AddPersistenceListener#onAdd}.
79      *
80      * @param session Refer to {@link AddPersistenceListener#onAdd}.
81      * @param valueObject Refer to {@link AddPersistenceListener#onAdd}.
82      * @throws PersistenceException Refer to {@link
83      * AddPersistenceListener#onAdd}.
84      */

85     public void onAdd(PersistenceSession session, ValueObject valueObject)
86             throws PersistenceException {
87         if (log.isDebugEnabled()) {
88             log.debug("onAdd: before: "
89                     + valueObject);
90         }
91         TimestampDO timestampDO = (TimestampDO)valueObject;
92         SecuritySession securitySession = (SecuritySession)
93             session.getSystemSession();
94         assert (securitySession != null);
95         TimestampDOHandling.add(securitySession, timestampDO);
96         if (log.isDebugEnabled()) {
97             log.debug("onAdd: after: "
98                     + valueObject);
99         }
100     }
101
102     /**
103      * Refer to {@link AmendPersistenceListener#onAmend}.
104      *
105      * @param session Refer to {@link AmendPersistenceListener#onAmend}.
106      * @param valueObject Refer to {@link AmendPersistenceListener#onAmend}.
107      * @throws PersistenceException Refer to {@link
108      * AmendPersistenceListener#onAmend}.
109      */

110     public void onAmend(PersistenceSession session, ValueObject valueObject)
111             throws PersistenceException {
112         if (log.isDebugEnabled()) {
113             log.debug("onAmend: before: "
114                     + valueObject);
115         }
116         TimestampDO timestampDO = (TimestampDO)valueObject;
117         SecuritySession securitySession = (SecuritySession)
118             session.getSystemSession();
119         assert (securitySession != null);
120         TimestampDOHandling.amend(securitySession, timestampDO);
121         if (log.isDebugEnabled()) {
122             log.debug("onAmend: after: "
123                     + valueObject);
124         }
125     }
126 }
127
Popular Tags