View Javadoc
1   // license-header java merge-point
2   // Generated by andromda-jsf cartridge (utils\NavigationItem.java.vsl) DO NOT EDIT!
3   package org.andromda.presentation.jsf;
4   
5   import java.io.Serializable;
6   import java.util.List;
7   import javax.faces.context.ExternalContext;
8   import javax.faces.context.FacesContext;
9   import org.apache.commons.beanutils.MethodUtils;
10  
11  /**
12   * @author Leif Johansson
13   */
14  public class NavigationItem
15      implements Serializable
16  {
17      /** */
18      private static final long serialVersionUID = 7916439134289358617L;
19      private String label = null;
20      private String outcome = null;
21      private String viewId = null;
22      private String icon = null;
23      private List children = null;
24      private Object controllerBean = null;
25      private String controllerAction = null;
26      private String roles = null;
27      private String[] _roles = null;
28  
29      /**
30       *
31       */
32      public NavigationItem()
33      {
34          // Documented empty block
35      }
36  
37      /**
38       * @return label
39       */
40      public String getLabel()
41      {
42          return this.label;
43      }
44  
45      /**
46       * @param labelIn
47       */
48      public void setLabel(String labelIn)
49      {
50          this.label = labelIn;
51      }
52  
53      /**
54       * @return outcome
55       */
56      public String getOutcome()
57      {
58          return this.outcome;
59      }
60  
61      /**
62       * @param outcomeIn
63       */
64      public void setOutcome(String outcomeIn)
65      {
66          this.outcome = outcomeIn;
67      }
68  
69      /**
70       * @return viewId
71       */
72      public String getViewId()
73      {
74          return this.viewId;
75      }
76  
77      /**
78       * @param viewIdIn
79       */
80      public void setViewId(String viewIdIn)
81      {
82          this.viewId = viewIdIn;
83      }
84  
85      /**
86       * @return children
87       */
88      public List getChildren()
89      {
90          return this.children;
91      }
92  
93      /**
94       * @param childrenIn
95       */
96      public void setChildren(List childrenIn)
97      {
98          this.children = childrenIn;
99      }
100 
101     /**
102      * @return icon
103      */
104     public String getIco()
105     {
106         return this.icon;
107     }
108 
109     /**
110      * @param iconIn
111      */
112     public void setIco(String iconIn)
113     {
114         this.icon = iconIn;
115     }
116 
117     /**
118      * @return roles
119      */
120     public String getRoles()
121     {
122         return this.roles;
123     }
124 
125     private void _updateRoles()
126     {
127         if (this.roles != null && this.roles.length() > 0)
128         {
129             this._roles = this.roles.split(",");
130         }
131         else
132         {
133             this._roles = null;
134         }
135     }
136 
137     /**
138      * @param rolesIn
139      */
140     public void setRoles(String rolesIn)
141     {
142         this.roles = rolesIn;
143         _updateRoles();
144     }
145 
146     /**
147      * @return AssociatedRoles
148      */
149     public String[] getAssociatedRoles()
150     {
151         return this._roles;
152     }
153 
154     /**
155      * @return isUserInItemRoles
156      */
157     public boolean isRendered()
158     {
159         return this.isUserInItemRoles();
160     }
161 
162     /**
163      * @return isUserInItemRoles
164      */
165     public boolean isUserInItemRoles()
166     {
167         String[] associatedRoles = this.getAssociatedRoles();
168 
169         if (associatedRoles == null || associatedRoles.length == 0)
170         { // no constraints at all
171 
172             return true;
173         }
174 
175         ExternalContext ctx =
176             FacesContext.getCurrentInstance().getExternalContext();
177 
178         if (ctx.getUserPrincipal() == null)
179         { // not logged in
180 
181             return false;
182         }
183 
184         for (String role : associatedRoles)
185         {
186             if (ctx.isUserInRole(role))
187             {
188                 return true;
189             }
190         }
191         return false;
192     }
193 
194     /**
195      * @return ControllerAction
196      */
197     public String getAction()
198     {
199         try
200         {
201             return (String)MethodUtils.invokeMethod(
202                 getControllerBean(),
203                 getControllerAction(),
204                 null);
205         }
206         catch (Exception ex)
207         {
208             ex.printStackTrace();
209             return null;
210         }
211     }
212 
213     /**
214      * @param controllerBeanIn
215      */
216     public void setControllerBean(Object controllerBeanIn)
217     {
218         this.controllerBean = controllerBeanIn;
219     }
220 
221     /**
222      * @return controllerBean
223      */
224     public Object getControllerBean()
225     {
226         return this.controllerBean;
227     }
228 
229     /**
230      * @param controllerActionIn
231      */
232     public void setControllerAction(String controllerActionIn)
233     {
234         this.controllerAction = controllerActionIn;
235     }
236 
237     /**
238      * @return controllerAction
239      */
240     public String getControllerAction()
241     {
242         return this.controllerAction;
243     }
244 
245     /**
246      * @see Object#toString()
247      */
248     @Override
249     public String toString()
250     {
251         StringBuilder buf = new StringBuilder();
252         buf.append(this.getClass().getName()  + "[");
253         buf.append("label=").append(this.label);
254         buf.append(",outcome=").append(this.outcome);
255         buf.append(",viewId=").append(this.viewId);
256         buf.append(",roles=").append(this.roles);
257         if (this.children != null)
258             buf.append(",children=").append(this.children);
259         buf.append("]");
260         return buf.toString();
261     }
262 }