All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mockrunner.example.struts.MemoryBasedRepository Maven / Gradle / Ivy

There is a newer version: 2.0.7
Show newest version
package com.mockrunner.example.struts;

import java.util.HashMap;

import javax.servlet.ServletContext;

/**
 * A simple data repository stored in the .
 * The implementation is not thread safe. Used by
 * {@link StoreDataActionTest}.
 */
public class MemoryBasedRepository
{
    private HashMap dataStore;
    
    private MemoryBasedRepository()
    {
        dataStore = new HashMap();
    }
    
    public static MemoryBasedRepository instance(ServletContext context)
    {
        MemoryBasedRepository instance = (MemoryBasedRepository)context.getAttribute(MemoryBasedRepository.class.getName());
        if(null != instance) return instance;
        instance = new MemoryBasedRepository();
        context.setAttribute(MemoryBasedRepository.class.getName(), instance);
        return instance;
    }
    
    public void set(String id, Object data)
    {
        dataStore.put(id, data);
    }
    
    public Object get(String id)
    {
        return dataStore.get(id);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy