KickJava   Java API By Example, From Geeks To Geeks.

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


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 states a {@link Version} can be in.
20  */

21 public class VersionState {
22     public static final VersionState DRAFT = new VersionState("draft", "D");
23     public static final VersionState PUBLISH = new VersionState("publish", "P");
24
25     private final String JavaDoc name;
26     private final String JavaDoc code;
27
28     private VersionState(String JavaDoc name, String JavaDoc code) {
29         this.name = name;
30         this.code = code;
31     }
32
33     public String JavaDoc toString() {
34         return name;
35     }
36
37     public String JavaDoc getCode() {
38         return code;
39     }
40
41     public static VersionState getByCode(String JavaDoc code) {
42         if (code.equals("D")) {
43             return VersionState.DRAFT;
44         } else if (code.equals("P")) {
45             return VersionState.PUBLISH;
46         } else {
47             throw new RuntimeException JavaDoc("Invalid VersionState code: " + code);
48         }
49     }
50
51     public static VersionState fromString(String JavaDoc name) {
52         if (name.equals("draft"))
53             return VersionState.DRAFT;
54         else if (name.equals("publish"))
55             return VersionState.PUBLISH;
56         else
57             throw new RuntimeException JavaDoc("Invalid VersionState name: " + name);
58     }
59 }
60
Popular Tags