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

br.gov.frameworkdemoiselle.internal.context.SessionBeanStore Maven / Gradle / Ivy

There is a newer version: 2.5.4
Show newest version
package br.gov.frameworkdemoiselle.internal.context;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;

@SessionScoped
public class SessionBeanStore implements Serializable {

	private static final long serialVersionUID = -8265458933971929432L;

	private Long lastViewId = null;

	private BeanStore store;

	synchronized BeanStore getStore(Long viewId, AbstractCustomContext context) {
		if (lastViewId == null || !lastViewId.equals(viewId)) {
			clear(context);
			lastViewId = viewId;
			store = AbstractCustomContext.createStore();
		}

		return store;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void clear(AbstractCustomContext context) {
		if (store != null) {
			for (String id : store) {
				Contextual contextual = context.getContextualStore().getContextual(id);
				Object instance = store.getInstance(id);
				CreationalContext creationalContext = store.getCreationalContext(id);

				if (contextual != null && instance != null) {
					contextual.destroy(instance, creationalContext);
				}
			}
			store.clear();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy