head	1.7;
access;
symbols;
locks; strict;
comment	@# @;


1.7
date	2001.08.11.09.08.03;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.05.23.01.50.13;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.23.00.35.00;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2001.04.18.22.39.19;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2001.04.17.00.19.40;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.04.16.23.53.41;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.04.16.20.50.29;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@/* ================================================================
 * Copyright (c) 2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.om;

import java.util.*;

import org.apache.torque.util.Criteria;
import org.apache.commons.util.BufferCache;
import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;
import org.apache.commons.util.exception.NestableException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.tool.*;
import org.tigris.helm.tool.cache.SimpleRegisterableCache;

/**
 * Extension of generated Peer BaseMessagePeer.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: MessagePeer.java,v 1.6 2001/05/23 01:50:13 dlr Exp $
 */
public class MessagePeer extends BaseMessagePeer
{
    /**
     * Flag indicating whether in debug mode.
     */
    private static final boolean DEBUG = true;

    /**
     * Flag indicating the message key for the broadcast message.
     */
    private static final String BROADCAST_MESSAGE_KEY = "BCST";

    /**
     * Object cache for this peer.
     */
    private static SimpleRegisterableCache messagesByKey;

    static
    {
        messagesByKey = new SimpleRegisterableCache
            ("Message cache", Message.class, new BufferCache(1));
    }

    /**
     * Retrieves the message with a given key.
     */
    public static Message getInstance(String key)
        throws Exception
    {
        Map cache = messagesByKey.getCache();
        Message message = (Message)cache.get(key);
        if (message == null)
        {
            synchronized (cache)
            {
                Criteria c = new Criteria().add(MESSAGE_ID, key);
                try
                {
                    message = (Message)PeerTool.getFirstBO
                        (doSelect(c), "Message for key " + key);
                }
                catch (DoesNotExist ignore)
                {
                }
                if (message != null)
                {
                    cache.put(message.getID(), message);
                }
            }
        }
        return message;
    }

    public static Message getBroadcastMessage()
        throws Exception
    {
        Message m = getInstance(BROADCAST_MESSAGE_KEY);
        if (m == null)
        {
            clearBroadcastMessage();
        }
        return m;
    }

    public static void setBroadcastMessage(String newMessage)
        throws Exception
    {
        Message m = getInstance(BROADCAST_MESSAGE_KEY);
        if (m == null)
        {
            m = new Message();            
            m.setMessageId(BROADCAST_MESSAGE_KEY);
        }        
        m.setMessageText(newMessage);
        m.save();       
    }

    public static void clearBroadcastMessage()
        throws Exception
    {
        setBroadcastMessage(null);
    }
}
@


1.6
log
@Ported Helm from WebMacro to Velocity.
@
text
@d51 2
a52 3
import org.apache.turbine.om.*;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.BufferCache;
d54 2
a55 2
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
d65 1
a65 1
 * @@version $Id: MessagePeer.java,v 1.5 2001/05/23 00:35:00 leonardr Exp $
@


1.5
log
@Cleanup of caching and cache invalidation.
@
text
@d55 2
d66 1
a66 1
 * @@version $Id: MessagePeer.java,v 1.4 2001/04/18 22:39:19 dlr Exp $
@


1.4
log
@SequencedHashtable, BufferCache, and BaseUnicastRemoteService have been moved into Turbine.  Changed references accordingly.
@
text
@a49 1
import java.rmi.RemoteException;
d64 1
a64 1
 * @@version $Id: MessagePeer.java,v 1.3 2001/04/17 00:19:40 leonardr Exp $
d85 2
a86 10
        try
        {
            messagesByKey = new SimpleRegisterableCache
                (MessagePeer.class, new BufferCache(1));
        }
        catch (RemoteException e)
        {
            throw new RuntimeException("Unable to create message cache: " +
                                       e.getMessage());
        }
@


1.3
log
@Moved from Message, the last of the Joist tables, to HELM_MESSAGE. A few minor problems with Joist servlets remain.
@
text
@d54 1
d65 1
a65 1
 * @@version $Id: MessagePeer.java,v 1.2 2001/04/16 23:53:41 dlr Exp $
@


1.2
log
@extra whitespace banished
@
text
@d57 1
a57 2
import org.tigris.helm.om.Action;
import org.tigris.helm.tool.BufferCache;
d64 1
a64 1
 * @@version $Id: MessagePeer.java,v 1.1 2001/04/16 20:50:29 leonardr Exp $
d74 5
d109 13
a121 2
                message = retrieveByPK(new StringKey(key));
                cache.put(message.getID(), message);
d125 30
@


1.1
log
@Added Helm/Torque capability equivalent to Joist's Message capability.
@
text
@d65 1
a65 1
 * @@version $Id: ActionPeer.java,v 1.8 2001/04/12 04:41:05 leonardr Exp $
a92 1
    
@

