KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > user > RoleNotFoundException


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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.outerj.daisy.repository.user;
17
18 import java.util.Map JavaDoc;
19 import java.util.HashMap JavaDoc;
20
21 public class RoleNotFoundException extends UserManagementException {
22     private long id;
23     private String JavaDoc name;
24
25     private static final String JavaDoc ID_KEY = "id";
26     private static final String JavaDoc NAME_KEY = "name";
27
28     public RoleNotFoundException(long id) {
29         this.id = id;
30     }
31
32     public RoleNotFoundException(String JavaDoc name) {
33         this.name = name;
34     }
35
36     public RoleNotFoundException(Map JavaDoc params) {
37         if (params.containsKey(ID_KEY)) {
38             this.id = Long.parseLong((String JavaDoc)params.get(ID_KEY));
39         } else {
40             this.name = (String JavaDoc)params.get(NAME_KEY);
41         }
42     }
43
44     public Map JavaDoc getState() {
45         HashMap JavaDoc map = new HashMap JavaDoc(1);
46         if (name == null)
47             map.put(ID_KEY, String.valueOf(id));
48         else
49             map.put(NAME_KEY, name);
50         return map;
51     }
52
53     public String JavaDoc getMessage() {
54         if (name != null)
55             return "The role named \"" + name + "\" does not exist";
56         else
57             return "The role with ID " + id + " does not exist.";
58     }
59 }
60
Popular Tags