KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > entities > management > SystemUserVO


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.entities.management;
25
26
27 import java.util.Iterator JavaDoc;
28
29 import org.infoglue.cms.entities.kernel.BaseEntityVO;
30 import org.infoglue.cms.entities.kernel.ValidatableEntityVO;
31 import org.infoglue.cms.entities.management.impl.simple.SystemUserImpl;
32 import org.infoglue.cms.util.ConstraintExceptionBuffer;
33 import org.infoglue.cms.util.validators.Constants;
34 import org.infoglue.cms.util.validators.ConstraintRule;
35 import org.infoglue.cms.util.validators.EmailValidator;
36 import org.infoglue.cms.util.validators.Range;
37 import org.infoglue.cms.util.validators.StringValidator;
38
39
40 public class SystemUserVO extends ValidatableEntityVO implements BaseEntityVO
41 {
42
43     private long timeStamp = 0;
44     private java.lang.String JavaDoc userName;
45     private java.lang.String JavaDoc password;
46     private java.lang.String JavaDoc firstName;
47     private java.lang.String JavaDoc lastName;
48     private java.lang.String JavaDoc email;
49     
50     /**
51      * @see org.infoglue.cms.entities.kernel.BaseEntityVO#getId()
52      */

53     public Integer JavaDoc getId()
54     {
55         return null;
56     }
57
58     public String JavaDoc toString()
59     {
60         return getFirstName() + " " + getLastName();
61     }
62     
63     public java.lang.String JavaDoc getUserName()
64     {
65         return this.userName;
66     }
67                 
68     public void setUserName(java.lang.String JavaDoc userName)
69     {
70         this.userName = userName;
71     }
72     
73     public java.lang.String JavaDoc getPassword()
74     {
75         return this.password;
76     }
77                 
78     public void setPassword(java.lang.String JavaDoc password)
79     {
80         this.password = password;
81     }
82     
83     public java.lang.String JavaDoc getFirstName()
84     {
85         return this.firstName;
86     }
87                 
88     public void setFirstName(java.lang.String JavaDoc firstName)
89     {
90         this.firstName = firstName;
91     }
92     
93     public java.lang.String JavaDoc getLastName()
94     {
95         return this.lastName;
96     }
97                 
98     public void setLastName(java.lang.String JavaDoc lastName)
99     {
100         this.lastName = lastName;
101     }
102     
103     public java.lang.String JavaDoc getEmail()
104     {
105         return this.email;
106     }
107                 
108     public void setEmail(java.lang.String JavaDoc email)
109     {
110         this.email = email;
111
112     }
113
114     public void PrepareValidation()
115     {
116         // Define the constraint rules for this valueobject
117
// maybe this belongs in the setters of this object?.
118
// then this method would be obsolete, and the validation
119
// should be initiated through a controller from the
120
// action class??.
121
// -----------------------------------------
122

123         // On the rulelist set the class that holds this vo, the class
124
// that is known to castor. This is for unique validation and
125
// if possible should not be set in the valueobject, but preferably
126
// in the actual castor-entity class. (Im not to satisfied with this
127
// construction).
128
rules.setEntityClass(SystemUserImpl.class);
129         
130         // Create a new constraintrule, supply constraint type, and field that this rule
131
// applies to.
132
ConstraintRule cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.userName");
133         
134         // Set the constraints
135
cr.setValidRange(new Range(2, 20) );
136         cr.unique=true; // public variabel will be changed to setter later
137
cr.required=true; // public variabel will be changed to setter later
138
cr.setValue(userName);
139         
140         // Add this rule to the rulelist
141
rules.addRule(cr);
142
143         // Set the rest of the rules
144
cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.password");
145         cr.setValidRange(new Range(4, 15));
146         cr.required = true;
147         cr.setValue(password);
148         rules.addRule(cr);
149         
150         cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.firstName");
151         cr.setValidRange(new Range(1, 30));
152         cr.required = true;
153         cr.setValue(firstName);
154         rules.addRule(cr);
155         
156         cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.STRING, "SystemUser.lastName");
157         cr.setValidRange(new Range(1, 30));
158         cr.required = true;
159         cr.setValue(lastName);
160         rules.addRule(cr);
161
162         cr = new ConstraintRule(org.infoglue.cms.util.validators.Constants.EMAIL, "SystemUser.email");
163         cr.setValidRange(new Range(50));
164         cr.required = true;
165         cr.setValue(email);
166         rules.addRule(cr);
167     }
168     
169     
170     public ConstraintExceptionBuffer validate(ValidatableEntityVO vo)
171     {
172         // This method loops through the rulelist and creates
173
// validators according to the settings in each rule.
174
// The old validators are used to do the actual validation
175
// but I have changed them to use less constructor
176
// parameter passing in favour for setters.
177

178         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
179         
180         // Prepare the object for validation
181
vo.PrepareValidation();
182         
183         // Loop through rules and create validators
184
Iterator JavaDoc iterator = vo.getConstraintRules().iterator();
185         while (iterator.hasNext())
186         {
187             ConstraintRule cr = (ConstraintRule) iterator.next();
188             String JavaDoc userName = ((SystemUserVO)vo).getUserName();
189             
190             // an ugly switch for now.
191
switch (cr.getConstraintType())
192             {
193                 case Constants.EMAIL:
194                 {
195                     if (cr.getValue() != null)
196                     {
197                         // Create validator
198
EmailValidator v = new EmailValidator(cr.getFieldName());
199                         
200                         // Set properties
201
v.setObjectClass(vo.getConstraintRuleList().getEntityClass());
202                         v.setRange(cr.getValidRange());
203                         v.setIsRequired(cr.required);
204                         v.setMustBeUnique(cr.unique);
205                         v.setExcludeId(null);
206                         v.setExcludeObject(userName);
207
208                         // Do the limbo
209
v.validate((String JavaDoc) cr.getValue(), ceb);
210                         
211                         // <todo>
212
// Note: the actual value validated should be extracted
213
// from the vo using the fieldname with reflection.
214
// </todo>
215

216                     }
217                     break;
218                 }
219                 case Constants.STRING:
220                 {
221                     if (cr.getValue() != null)
222                     {
223                         StringValidator v = new StringValidator(cr.getFieldName());
224                         v.setObjectClass(vo.getConstraintRuleList().getEntityClass());
225                         v.setRange(cr.getValidRange());
226                         v.setIsRequired(cr.required);
227                         v.setMustBeUnique(cr.unique);
228                         v.setExcludeId(null);
229                         v.setExcludeObject(userName);
230
231                         v.validate((String JavaDoc) cr.getValue(), ceb);
232                     }
233                     break;
234                 }
235                 case Constants.FLOAT:
236                 {
237                     break;
238                 }
239                 case Constants.INTEGER:
240                 {
241                     break;
242                 }
243                 case Constants.PROPERNOUN:
244                 {
245                     break;
246                 }
247                 
248             } // switch
249

250         } // while
251

252         return ceb;
253     }
254 }
255
Popular Tags