1 15 package org.apache.tapestry.vlib.ejb; 16 17 import java.io.Serializable ; 18 import java.sql.Timestamp ; 19 20 27 28 public class Person implements Serializable 29 { 30 private static final long serialVersionUID = 37148852625594728L; 31 32 private Object [] columns; 33 34 public static final int ID_COLUMN = 0; 35 public static final int FIRST_NAME_COLUMN = 1; 36 public static final int LAST_NAME_COLUMN = 2; 37 public static final int EMAIL_COLUMN = 3; 38 public static final int LOCKED_OUT_COLUMN = 4; 39 public static final int ADMIN_COLUMN = 5; 40 public static final int LAST_ACCESS_COLUMN = 6; 41 42 public static final int N_COLUMNS = 7; 43 44 public Person(Object [] columns) 45 { 46 if (columns == null) 47 throw new IllegalArgumentException ("Must provide a non-null columns."); 48 49 if (columns.length != N_COLUMNS) 50 throw new IllegalArgumentException ("Wrong number of columns for a Person."); 51 52 this.columns = new Object [N_COLUMNS]; 53 System.arraycopy(columns, 0, this.columns, 0, N_COLUMNS); 54 } 55 56 public Integer getId() 57 { 58 return (Integer ) columns[ID_COLUMN]; 59 } 60 61 public String getFirstName() 62 { 63 return (String ) columns[FIRST_NAME_COLUMN]; 64 } 65 66 public String getLastName() 67 { 68 return (String ) columns[LAST_NAME_COLUMN]; 69 } 70 71 public String getEmail() 72 { 73 return (String ) columns[EMAIL_COLUMN]; 74 } 75 76 public String getNaturalName() 77 { 78 if (columns[FIRST_NAME_COLUMN] == null) 79 return (String ) columns[LAST_NAME_COLUMN]; 80 81 return (String ) columns[FIRST_NAME_COLUMN] + " " + (String ) columns[LAST_NAME_COLUMN]; 82 } 83 84 public Timestamp getLastAccess() 85 { 86 return (Timestamp ) columns[LAST_ACCESS_COLUMN]; 87 } 88 89 public String toString() 90 { 91 StringBuffer buffer; 92 93 buffer = new StringBuffer ("Person["); 94 95 if (columns[FIRST_NAME_COLUMN] != null) 96 { 97 buffer.append((String ) columns[FIRST_NAME_COLUMN]); 98 buffer.append(' '); 99 } 100 101 buffer.append((String ) columns[LAST_NAME_COLUMN]); 102 buffer.append(']'); 103 104 return buffer.toString(); 105 } 106 107 public boolean isAdmin() 108 { 109 return getBit(ADMIN_COLUMN); 110 } 111 112 public void setAdmin(boolean value) 113 { 114 setBit(ADMIN_COLUMN, value); 115 } 116 117 public boolean isLockedOut() 118 { 119 return getBit(LOCKED_OUT_COLUMN); 120 } 121 122 public void setLockedOut(boolean value) 123 { 124 setBit(LOCKED_OUT_COLUMN, value); 125 } 126 127 private void setBit(int column, boolean value) 128 { 129 columns[column] = value ? Boolean.TRUE : Boolean.FALSE; 130 } 131 132 private boolean getBit(int column) 133 { 134 Boolean b = (Boolean ) columns[column]; 135 136 return b.booleanValue(); 137 } 138 139 } | Popular Tags |