01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 enum LockType {
22: WARN("warn", "W"), PESSIMISTIC("pessimistic", "P");
23:
24: private final String name;
25: private final String code;
26:
27: private LockType(String name, String code) {
28: this .name = name;
29: this .code = code;
30: }
31:
32: public String toString() {
33: return name;
34: }
35:
36: /**
37: * A short (one-letter) unique code representing this lock type.
38: */
39: public String getCode() {
40: return code;
41: }
42:
43: public static LockType getByCode(String code) {
44: if (code.equals("W")) {
45: return WARN;
46: } else if (code.equals("P")) {
47: return PESSIMISTIC;
48: } else {
49: throw new RuntimeException("Invalid LockType code: " + code);
50: }
51: }
52:
53: public static LockType fromString(String lockTypeString) {
54: if (lockTypeString.equals("warn"))
55: return WARN;
56: else if (lockTypeString.equals("pessimistic"))
57: return PESSIMISTIC;
58: else
59: throw new RuntimeException("Invalid LockType string: "
60: + lockTypeString);
61: }
62: }
|