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

org.directwebremoting.datasync.PerScriptSessionStoreProvider Maven / Gradle / Ivy

Go to download

DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript. It gets rid of almost all the boilerplate code between the web browser and your Java code. This version 4.0.2 works with Jakarta Servlet 4.0.2.

The newest version!
package org.directwebremoting.datasync;

import org.directwebremoting.ScriptSession;
import org.directwebremoting.WebContextFactory;

/**
 * A StoreProvider that allows us to have a number of StoreProviders for each
 * {@link ScriptSession}. New {@link StoreProvider}s are created by a
 * {@link StoreProviderFactory} and stored in the ScriptSession under a given
 * attribute name.
 * @author Joe Walker [joe at getahead dot ltd dot uk]
 */
public class PerScriptSessionStoreProvider extends AbstractPerXStoreProvider
{
    public PerScriptSessionStoreProvider(StoreProviderFactory factory, String attributeName)
    {
        this.factory = factory;
        this.attributeName = attributeName;
    }

    /**
     * Internal method to find or create a StoreProvider for a given user.
     */
    @Override
    protected StoreProvider getStoreProvider()
    {
        ScriptSession session = WebContextFactory.get().getScriptSession();

        @SuppressWarnings("unchecked")
        StoreProvider storeProvider = (StoreProvider) session.getAttribute(attributeName);

        if (storeProvider == null)
        {
            storeProvider = factory.create(session);
            session.setAttribute(attributeName, storeProvider);
        }

        return storeProvider;
    }

    /**
     * The attribute name that we are storing created StoreProviders under in
     * the ScriptSession
     */
    private final String attributeName;

    /**
     * The factory to enable us to create factories per ScriptSession
     */
    private final StoreProviderFactory factory;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy