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

net.sf.ahtutils.web.mbean.util.AbstractMenuBean Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
package net.sf.ahtutils.web.mbean.util;

import java.io.FileNotFoundException;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import net.sf.ahtutils.jsf.menu.MenuFactory;
import net.sf.ahtutils.xml.navigation.Menu;
import net.sf.ahtutils.xml.navigation.MenuItem;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AbstractMenuBean implements Serializable
{
	final static Logger logger = LoggerFactory.getLogger(AbstractMenuBean.class);
	private static final long serialVersionUID = 1L;
	
	protected static final String rootMain = "root";
	protected Map mapMenu;
	protected Map mapSub;
	protected Map> mapBreadcrumb;
	
	protected Map mapViewAllowed;

    public void initMaps() throws FileNotFoundException
    {
		mapMenu = new Hashtable();
		mapSub = new Hashtable();
		mapBreadcrumb = new Hashtable>();
    }
    
	public void clear()
	{
		mapMenu.clear();
		mapSub.clear();
		mapBreadcrumb.clear();
		mapViewAllowed = null;
	}
	
	protected void buildViewAllowedMap()
	{
		logger.error("This should never been called here. A @Override in extended class is required");
	}
		
	// ******************************************
	// Menu
	public Menu menu(MenuFactory mf, String code)
	{
		buildViewAllowedMap();
		synchronized(mf)
		{
			if(!mapMenu.containsKey(code))
			{
				mapMenu.put(code, mf.build(code));
			}
			return mapMenu.get(code);
		}
	}
	public Menu menu(MenuFactory mf, String code, boolean loggedIn)
	{
		buildViewAllowedMap();
		if(code.length()==0){code=rootMain;}
		if(!mapMenu.containsKey(code))
		{
			synchronized(mf)
			{
				mapMenu.put(code, mf.build(mapViewAllowed,code,loggedIn));
			}
		}
		return mapMenu.get(code);
	}
	
	
	// ******************************************
	// Breadcrumb
	public List breadcrumb(MenuFactory mf,String code)
	{
		synchronized(mf)
		{
			if(!mapBreadcrumb.containsKey(code))
			{
				if(!mapMenu.containsKey(code)){menu(mf,code);}
				mapBreadcrumb.put(code,mf.breadcrumb(code));
			}
			return mapBreadcrumb.get(code);
		}
	}
	
	// ******************************************
	// SubMenu
	public MenuItem sub(MenuFactory mf, String code)
	{
		synchronized(mf)
		{
			if(!mapSub.containsKey(code))
			{
				if(!mapMenu.containsKey(code)){menu(mf,code);}
				Menu m = mapMenu.get(code);
				mapSub.put(code,mf.subMenu(m,code));
			}
			return mapSub.get(code);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy