KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > vlib > ejb > Person


1 // Copyright 2004 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.vlib.ejb;
16
17 import java.io.Serializable JavaDoc;
18 import java.sql.Timestamp JavaDoc;
19
20 /**
21  * A light-weight version of the {@link IPerson} bean.
22  *
23  * @version $Id: Person.java,v 1.4 2004/02/19 17:37:39 hlship Exp $
24  * @author Howard Lewis Ship
25  *
26  **/

27
28 public class Person implements Serializable JavaDoc
29 {
30     private static final long serialVersionUID = 37148852625594728L;
31
32     private Object JavaDoc[] 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 JavaDoc[] columns)
45     {
46         if (columns == null)
47             throw new IllegalArgumentException JavaDoc("Must provide a non-null columns.");
48
49         if (columns.length != N_COLUMNS)
50             throw new IllegalArgumentException JavaDoc("Wrong number of columns for a Person.");
51
52         this.columns = new Object JavaDoc[N_COLUMNS];
53         System.arraycopy(columns, 0, this.columns, 0, N_COLUMNS);
54     }
55
56     public Integer JavaDoc getId()
57     {
58         return (Integer JavaDoc) columns[ID_COLUMN];
59     }
60
61     public String JavaDoc getFirstName()
62     {
63         return (String JavaDoc) columns[FIRST_NAME_COLUMN];
64     }
65
66     public String JavaDoc getLastName()
67     {
68         return (String JavaDoc) columns[LAST_NAME_COLUMN];
69     }
70
71     public String JavaDoc getEmail()
72     {
73         return (String JavaDoc) columns[EMAIL_COLUMN];
74     }
75
76     public String JavaDoc getNaturalName()
77     {
78         if (columns[FIRST_NAME_COLUMN] == null)
79             return (String JavaDoc) columns[LAST_NAME_COLUMN];
80
81         return (String JavaDoc) columns[FIRST_NAME_COLUMN] + " " + (String JavaDoc) columns[LAST_NAME_COLUMN];
82     }
83
84     public Timestamp JavaDoc getLastAccess()
85     {
86         return (Timestamp JavaDoc) columns[LAST_ACCESS_COLUMN];
87     }
88
89     public String JavaDoc toString()
90     {
91         StringBuffer JavaDoc buffer;
92
93         buffer = new StringBuffer JavaDoc("Person[");
94
95         if (columns[FIRST_NAME_COLUMN] != null)
96         {
97             buffer.append((String JavaDoc) columns[FIRST_NAME_COLUMN]);
98             buffer.append(' ');
99         }
100
101         buffer.append((String JavaDoc) 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 JavaDoc b = (Boolean JavaDoc) columns[column];
135
136         return b.booleanValue();
137     }
138
139 }
Popular Tags