Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

DemoRole.java

00001 package edu.virtualschool.jwaa.bean;
00002 
00003 import java.util.ArrayList;
00004 import java.util.HashMap;
00005 import java.util.Iterator;
00006 import java.util.List;
00007 
00008 import edu.virtualschool.jwaa.GenericRole;
00009 import edu.virtualschool.jwaa.RoleAbstraction;
00010 import edu.virtualschool.jwaa.field.CommaSeparatedField;
00011 import edu.virtualschool.jwaa.xml.ValidationFault;
00012 
00013 
00028 public class DemoRole 
00029   extends GenericRole 
00030   implements RoleAbstraction
00031 {
00032   final String description;
00033   
00034   public final static DemoRole 
00035     PERSON = new DemoRole("person", "Logged In", null),
00036     STUDENT = new DemoRole("student", "Students", PERSON),
00037     FACULTY = new DemoRole("faculty", "Faculty", STUDENT),
00038     ADMINISTRATOR = new DemoRole("admin", "Administrators", FACULTY);
00039   final static DemoRole[] roles = new DemoRole[] 
00040   {
00041     PERSON,
00042     STUDENT,
00043     FACULTY,
00044     ADMINISTRATOR 
00045   };
00046   public final static String sqlType = "varchar(255)";
00047   final static HashMap roleMap = new HashMap();
00048   static 
00049   {
00050     for (int i = 0; i < roles.length; i++)
00051       roleMap.put(roles[i].toString(), roles[i]);
00052   }
00053 
00054   private DemoRole(String id, String description, RoleAbstraction parent)
00055   {
00056     super(id, parent);
00057     this.description = description;
00058   }
00059   public String getDescription()
00060   {
00061     return description;
00062   }
00063   public static DemoRole findRole(String roleID)
00064     throws ValidationFault
00065   {
00066     Object o = roleMap.get(roleID);
00067     return (DemoRole)o;
00068   }
00069   public static List createRoleList(CommaSeparatedField field)
00070     throws ValidationFault
00071   {
00072     List list = new ArrayList();
00073     for (Iterator i = field.arrayValue.iterator(); i.hasNext(); )
00074     {
00075       String name = (String)i.next();
00076       list.add(findRole(name));
00077     }
00078     return list;
00079   }
00080 }