1 20 package org.enhydra.barracuda.contrib.sam.examples.data; 21 22 import org.enhydra.barracuda.contrib.sam.data.*; 23 import org.enhydra.barracuda.core.comp.*; 24 import java.util.*; 25 import org.apache.log4j.*; 26 27 30 public class User implements DataObject { 31 protected static Map USERS = new HashMap(); 32 protected static int maxOid = 0; 33 34 protected static Logger logger = Logger.getLogger(User.class.getName()); 35 36 protected String oid; 37 protected String login; 38 protected String password; 39 protected String email; 40 protected List roles; 41 42 public User() 43 throws DataObjectException { 44 oid = Integer.toString(maxOid++); 45 logger.debug("consturcting new USER"); 46 } 47 48 public Object get(String field) 49 throws DataObjectException { 50 field = field.toLowerCase(); 51 if (field.equals("login")) return login; 52 if (field.equals("password")) return password; 53 if (field.equals("email")) return email; 54 if (field.equals("oid")) return oid; 55 if (field.equals("fk_roles")) return roles; 56 throw new DataObjectException("invalid field " + field); 58 } 59 60 public void set(String field, Object value) 61 throws DataObjectException { 62 field = field.toLowerCase(); 63 if (field.equals("login")) { login = (String )value; return; } 64 if (field.equals("password")) { password = (String )value; return; } 65 if (field.equals("email")) { email=(String )value; return; } 66 if (field.equals("fk_roles")) { 67 if (value instanceof List) { 68 roles = (List)value; 69 } else if (value instanceof String ) { 70 roles = new ArrayList(); 71 roles.add(value); 72 } 73 return; 74 } 75 if (field.equals("oid")) { 76 return; 78 } 79 throw new DataObjectException("invalid (oid is " + this.oid + ") field " + field + " " + value); 80 } 81 82 83 86 public void save(Object dbt) 87 throws DataObjectException { 88 USERS.put(this.oid, this); 89 } 90 91 94 public void delete(Object dbt) 95 throws DataObjectException { 96 USERS.remove(this.oid); 97 } 98 99 public boolean equals(User cmp) { 100 return (this.oid == cmp.oid); 101 } 102 103 public static User getUser(String oid) throws DataObjectException { 104 User ret = (User) USERS.get(oid); 105 if (ret == null) { 106 ret = new User(); 107 } 108 return ret; 109 } 110 111 public static Collection getAll() { 112 return USERS.values(); 113 } 114 115 public static List getFormMapRoles() { 116 List result = new ArrayList(); 117 result.add(new DefaultItemMap("1","Admin")); 118 result.add(new DefaultItemMap("2", "Poweruser")); 119 result.add(new DefaultItemMap("3", "regular User")); 120 result.add(new DefaultItemMap("4", "DAU")); 121 return result; 122 } 123 124 125 } 126 | Popular Tags |