KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > LockType


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;
17
18 /**
19  * Enumeration of the available lock types.
20  */

21 public class LockType {
22     private final String JavaDoc name;
23     private final String JavaDoc code;
24
25     private LockType(String JavaDoc name, String JavaDoc code) {
26         this.name = name;
27         this.code = code;
28     }
29
30     public String JavaDoc toString() {
31         return name;
32     }
33
34     /**
35      * A short (one-letter) unique code representing this lock type.
36      */

37     public String JavaDoc getCode() {
38         return code;
39     }
40
41     public static LockType getByCode(String JavaDoc code) {
42         if (code.equals("W")) {
43             return WARN;
44         } else if (code.equals("P")) {
45             return PESSIMISTIC;
46         } else {
47             throw new RuntimeException JavaDoc("Invalid LockType code: " + code);
48         }
49     }
50
51     public static LockType fromString(String JavaDoc lockTypeString) {
52         if (lockTypeString.equals("warn"))
53             return WARN;
54         else if (lockTypeString.equals("pessimistic"))
55             return PESSIMISTIC;
56         else
57             throw new RuntimeException JavaDoc("Invalid LockType string: " + lockTypeString);
58     }
59
60     public static final LockType WARN = new LockType("warn", "W");
61     public static final LockType PESSIMISTIC = new LockType("pessimistic", "P");
62 }
63
Popular Tags