Package org.apache.agila.impl.jdbc

Source Code of org.apache.agila.impl.jdbc.NotificationServiceImpl

/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.agila.impl.jdbc;

import org.apache.agila.services.notification.AbstractNotificationService;
import org.apache.agila.services.notification.Notification;
import org.apache.agila.services.notification.NotificationID;
import org.apache.agila.services.user.UserID;
import org.apache.agila.impl.NotificationImpl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;

/**
*
* @author <a href="mailto:geir@gluecode.com">Geir Magnusson Jr.</a>
* @version $Id: NotificationServiceImpl.java 38 2005-06-01 19:39:54Z chirino $
*/
public class NotificationServiceImpl extends AbstractNotificationService {

    private Map userMap = new HashMap();
    private Map notificationMap = new HashMap();

    private int counter = 0;

    protected NotificationImpl createNew(UserID userID, String msg) {

        NotificationID id = new NotificationID(++counter);

        NotificationImpl ni = new NotificationImpl(id, userID, msg);

        List l = (List) userMap.get(userID);

        if (l == null) {

            l = new ArrayList();
            userMap.put(userID, l);
        }

        l.add(ni);

        notificationMap.put(id, ni);

        return ni;
    }

    protected boolean save(Notification notification) {

        // no op
        return true;
    }

    protected NotificationImpl get(NotificationID id) {

        return (NotificationImpl) notificationMap.get(id);
    }

    protected List getForUserID(UserID id) {

        List l = (List) userMap.get(id);

        List flist = new ArrayList();

        if (l != null) {

            Iterator it = l.iterator();

            while(it.hasNext()) {
                NotificationImpl ni = (NotificationImpl) it.next();

                if  (ni.getStatus() == 0) {
                    flist.add(ni);
                }
            }
        }

        return flist;
    }
}
TOP

Related Classes of org.apache.agila.impl.jdbc.NotificationServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.