package es.ejie.frmk.presentacion.iu.taglib.html.menu.base;

import java.util.ArrayList;
import java.util.List;

import es.ejie.frmk.control.excepciones.Q70FrameworkException;
import es.ejie.frmk.infraestructura.traza.Q70TraceLevel;
import es.ejie.frmk.infraestructura.traza.Q70Traza;

/**
 * Clase que contiene los componentes del arbol de menus
 * @version 1.0
 */
public class Q70MenuComponentEstatico extends Q70MenuComponent {
	
	protected ArrayList menuComponents = new ArrayList();
	Q70MenuComponent menuClase = null;

	public Q70MenuComponentEstatico() {
		super();
	}

	/**
	 * @see es.ejie.frmk.presentacion.iu.taglib.html.menu.base.Q70MenuComponent#addMenuComponent(es.ejie.frmk.presentacion.iu.taglib.html.menu.base.Q70MenuComponent)
	 */
	public void addMenuComponent(Q70MenuComponent menuComponent) {
		menuComponents.add(menuComponent);
		menuComponent.setParent(this);

		if ((menuComponent.getName() == null) || (menuComponent.getName().equals(""))) {
			menuComponent.setName(this.name + menuComponents.size());
		}
	}

	/**
	 * @see es.ejie.frmk.presentacion.iu.taglib.html.menu.base.Q70MenuComponent#getMenuComponents()
	 */
	public Q70MenuComponent[] getMenuComponents() throws Q70FrameworkException
	{
		Q70Traza tr = Q70Traza.getSingleton();
		Q70MenuComponent[] lista = null;
		try {
			if (null != menuClase) {
				return menuClase.getMenuComponents();
			}
			if (null != getClase() && !"".equals(getClase())) {
				if (null == menuClase) {
					menuClase = (Q70MenuComponent) Class.forName(getClase()).newInstance();
				}
				return menuClase.getMenuComponents();
			}
			lista = super.getMenuComponents();
		} catch (Exception e) {
			if (tr.isTraceActive())
			{
				tr.trace(COMPONENTE, Q70TraceLevel.ERROR, "Error en la obtención de los menus. Q70TabbedMenuDisplayer");
			}
			throw new Q70FrameworkException(COMPONENTE,this.getClass().toString(),"getMenuComponents","Ha ocurrido un error en la obtencion de Menus",e);
		}
		return lista;
	}
	
	/**
	 * @see es.ejie.frmk.presentacion.iu.taglib.html.menu.base.Q70MenuComponent#doGetMenuComponents()
	 */
	protected List doGetMenuComponents() throws Exception {
		return menuComponents;
	}
}
