KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example > memory > TestUserDatabase


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

16 package org.apache.struts.webapp.example.memory;
17
18 import org.apache.struts.webapp.example.User;
19 import org.apache.struts.webapp.example.ExpiredPasswordException;
20
21 /**
22  * <p>Help test exception handling by throwing exceptions when "magic" user names are requested.</p>
23  */

24 public final class TestUserDatabase extends MemoryUserDatabase {
25
26
27     /**
28      * If the username is "expired" throw an ExpiredPasswordException
29      * to simulate a business exception.
30      * If the username is "arithmetic" throw an Aritmetic exception to
31      * simulate a system exception.
32      * Otherwise, delegate to MemoryDatabase.
33      * @param username
34      * @return
35      */

36     public User findUser(String JavaDoc username) throws ExpiredPasswordException {
37
38         if ("expired".equals(username)) throw new ExpiredPasswordException("Testing ExpiredPasswordException ...");
39         if ("arithmetic".equals(username)) throw new ArithmeticException JavaDoc();
40         return super.findUser(username);
41     }
42
43 }
44
Popular Tags