001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: TimestampDOListener.java,v $
031: * Revision 1.7 2005/10/12 18:36:50 colinmacleod
032: * Standardized format of Logger declaration - to make it easier to find instances
033: * which are not both static and final.
034: *
035: * Revision 1.6 2005/10/11 18:56:19 colinmacleod
036: * Fixed some checkstyle and javadoc issues.
037: *
038: * Revision 1.5 2005/10/03 10:21:15 colinmacleod
039: * Fixed some style and javadoc issues.
040: *
041: * Revision 1.4 2005/10/02 14:08:58 colinmacleod
042: * Added/improved log4j logging.
043: *
044: * Revision 1.3 2005/09/29 12:50:40 colinmacleod
045: * Restructured NamedDO and TimestampDO classes based around interfaces.
046: *
047: * Revision 1.2 2005/04/09 17:19:58 colinmacleod
048: * Changed copyright text to GPL v2 explicitly.
049: *
050: * Revision 1.1.1.1 2005/03/10 17:51:32 colinmacleod
051: * Restructured ivata op around Hibernate/PicoContainer.
052: * Renamed ivata groupware.
053: *
054: * -----------------------------------------------------------------------------
055: */
056: package com.ivata.groupware.container.persistence;
057:
058: import org.apache.log4j.Logger;
059:
060: import com.ivata.groupware.admin.security.server.SecuritySession;
061: import com.ivata.mask.persistence.PersistenceException;
062: import com.ivata.mask.persistence.PersistenceSession;
063: import com.ivata.mask.persistence.QueryPersistenceManager;
064: import com.ivata.mask.persistence.listener.AddPersistenceListener;
065: import com.ivata.mask.persistence.listener.AmendPersistenceListener;
066: import com.ivata.mask.valueobject.ValueObject;
067:
068: /**
069: * This class handles the timestamp properties when objects are added to or
070: * amended in the store.
071: * @since ivata groupware 0.10 (2005-01-17)
072: * @author Colin MacLeod
073: * <a href="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
074: * @version $Revision: 1.7 $
075: */
076: public class TimestampDOListener implements AddPersistenceListener,
077: AmendPersistenceListener {
078: /**
079: * Logger for this class.
080: */
081: private static final Logger logger = Logger
082: .getLogger(TimestampDOListener.class);
083:
084: /**
085: * Constructor. Registers this listener with the persistence manager.
086: * @param persistenceManager used to register this listener against
087: * subclasses of <code>AuthorTimestampDO</code>.
088: */
089: public TimestampDOListener(
090: final QueryPersistenceManager persistenceManager) {
091: persistenceManager
092: .addAddListener(AuthorTimestampDO.class, this );
093: persistenceManager.addAmendListener(AuthorTimestampDO.class,
094: this );
095: }
096:
097: /**
098: * <copyDoc>Refer to {@link AddPersistenceListener#onAdd}.</copyDoc>
099: *
100: * @param session
101: * <copyDoc>Refer to {@link AddPersistenceListener#onAdd}.</copyDoc>
102: * @param valueObject
103: * <copyDoc>Refer to {@link AddPersistenceListener#onAdd}.</copyDoc>
104: * @throws PersistenceException Refer to {@link
105: * AddPersistenceListener#onAdd}.
106: */
107: public void onAdd(final PersistenceSession session,
108: final ValueObject valueObject) throws PersistenceException {
109: if (logger.isDebugEnabled()) {
110: logger.debug("onAdd: before: " + valueObject);
111: }
112: AuthorTimestampDO timestampDO = (AuthorTimestampDO) valueObject;
113: SecuritySession securitySession = (SecuritySession) session
114: .getSystemSession();
115: assert (securitySession != null);
116: TimestampDOHandling.add(securitySession, timestampDO);
117: if (logger.isDebugEnabled()) {
118: logger.debug("onAdd: after: " + valueObject);
119: }
120: }
121:
122: /**
123: * <copyDoc>Refer to {@link AmendPersistenceListener#onAmend}.</copyDoc>
124: *
125: * @param session
126: * <copyDoc>Refer to {@link AmendPersistenceListener#onAmend}.</copyDoc>
127: * @param valueObject
128: * <copyDoc>Refer to {@link AmendPersistenceListener#onAmend}.</copyDoc>
129: * @throws PersistenceException Refer to {@link
130: * AmendPersistenceListener#onAmend}.
131: */
132: public void onAmend(final PersistenceSession session,
133: final ValueObject valueObject) throws PersistenceException {
134: if (logger.isDebugEnabled()) {
135: logger.debug("onAmend: before: " + valueObject);
136: }
137: AuthorDO timestampDO = (AuthorDO) valueObject;
138: SecuritySession securitySession = (SecuritySession) session
139: .getSystemSession();
140: assert (securitySession != null);
141: TimestampDOHandling.amend(securitySession, timestampDO);
142: if (logger.isDebugEnabled()) {
143: logger.debug("onAmend: after: " + valueObject);
144: }
145: }
146: }
|