NavigationItem.java
// license-header java merge-point
// Generated by andromda-jsf cartridge (utils\NavigationItem.java.vsl) DO NOT EDIT!
package org.andromda.presentation.jsf;
import java.io.Serializable;
import java.util.List;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.apache.commons.beanutils.MethodUtils;
/**
* @author Leif Johansson
*/
public class NavigationItem
implements Serializable
{
/** */
private static final long serialVersionUID = 7916439134289358617L;
private String label = null;
private String outcome = null;
private String viewId = null;
private String icon = null;
private List children = null;
private Object controllerBean = null;
private String controllerAction = null;
private String roles = null;
private String[] _roles = null;
/**
*
*/
public NavigationItem()
{
// Documented empty block
}
/**
* @return label
*/
public String getLabel()
{
return this.label;
}
/**
* @param labelIn
*/
public void setLabel(String labelIn)
{
this.label = labelIn;
}
/**
* @return outcome
*/
public String getOutcome()
{
return this.outcome;
}
/**
* @param outcomeIn
*/
public void setOutcome(String outcomeIn)
{
this.outcome = outcomeIn;
}
/**
* @return viewId
*/
public String getViewId()
{
return this.viewId;
}
/**
* @param viewIdIn
*/
public void setViewId(String viewIdIn)
{
this.viewId = viewIdIn;
}
/**
* @return children
*/
public List getChildren()
{
return this.children;
}
/**
* @param childrenIn
*/
public void setChildren(List childrenIn)
{
this.children = childrenIn;
}
/**
* @return icon
*/
public String getIco()
{
return this.icon;
}
/**
* @param iconIn
*/
public void setIco(String iconIn)
{
this.icon = iconIn;
}
/**
* @return roles
*/
public String getRoles()
{
return this.roles;
}
private void _updateRoles()
{
if (this.roles != null && this.roles.length() > 0)
{
this._roles = this.roles.split(",");
}
else
{
this._roles = null;
}
}
/**
* @param rolesIn
*/
public void setRoles(String rolesIn)
{
this.roles = rolesIn;
_updateRoles();
}
/**
* @return AssociatedRoles
*/
public String[] getAssociatedRoles()
{
return this._roles;
}
/**
* @return isUserInItemRoles
*/
public boolean isRendered()
{
return this.isUserInItemRoles();
}
/**
* @return isUserInItemRoles
*/
public boolean isUserInItemRoles()
{
String[] associatedRoles = this.getAssociatedRoles();
if (associatedRoles == null || associatedRoles.length == 0)
{ // no constraints at all
return true;
}
ExternalContext ctx =
FacesContext.getCurrentInstance().getExternalContext();
if (ctx.getUserPrincipal() == null)
{ // not logged in
return false;
}
for (String role : associatedRoles)
{
if (ctx.isUserInRole(role))
{
return true;
}
}
return false;
}
/**
* @return ControllerAction
*/
public String getAction()
{
try
{
return (String)MethodUtils.invokeMethod(
getControllerBean(),
getControllerAction(),
null);
}
catch (Exception ex)
{
ex.printStackTrace();
return null;
}
}
/**
* @param controllerBeanIn
*/
public void setControllerBean(Object controllerBeanIn)
{
this.controllerBean = controllerBeanIn;
}
/**
* @return controllerBean
*/
public Object getControllerBean()
{
return this.controllerBean;
}
/**
* @param controllerActionIn
*/
public void setControllerAction(String controllerActionIn)
{
this.controllerAction = controllerActionIn;
}
/**
* @return controllerAction
*/
public String getControllerAction()
{
return this.controllerAction;
}
/**
* @see Object#toString()
*/
@Override
public String toString()
{
StringBuilder buf = new StringBuilder();
buf.append(this.getClass().getName() + "[");
buf.append("label=").append(this.label);
buf.append(",outcome=").append(this.outcome);
buf.append(",viewId=").append(this.viewId);
buf.append(",roles=").append(this.roles);
if (this.children != null)
buf.append(",children=").append(this.children);
buf.append("]");
return buf.toString();
}
}