KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > comment > CommentVisibility


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.comment;
17
18 public class CommentVisibility {
19     private final String JavaDoc name;
20     private final String JavaDoc code;
21
22     private CommentVisibility(String JavaDoc name, String JavaDoc code) {
23         this.name = name;
24         this.code = code;
25     }
26
27     public String JavaDoc toString() {
28         return name;
29     }
30
31     public static CommentVisibility fromString(String JavaDoc name) {
32         if (name.equals("public")) {
33             return PUBLIC;
34         } else if (name.equals("editors")) {
35             return EDITORS;
36         } else if (name.equals("private")) {
37             return PRIVATE;
38         } else {
39             throw new RuntimeException JavaDoc("Invalid CommentVisiblity name: " + name);
40         }
41     }
42
43     public String JavaDoc getCode() {
44         return code;
45     }
46
47     public static CommentVisibility getByCode(String JavaDoc code) {
48         if (code.equals("U")) {
49             return PUBLIC;
50         } else if (code.equals("E")) {
51             return EDITORS;
52         } else if (code.equals("P")) {
53             return PRIVATE;
54         } else {
55             throw new RuntimeException JavaDoc("Invalid CommentVisibility code: " + code);
56         }
57     }
58
59     public static final CommentVisibility PUBLIC = new CommentVisibility("public", "U");
60     public static final CommentVisibility EDITORS = new CommentVisibility("editors", "E");
61     public static final CommentVisibility PRIVATE = new CommentVisibility("private", "P");
62 }
63
Popular Tags