1 /**
2 *
3 * Copyright 2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.kernel.config;
19
20 import java.io.Serializable;
21 import java.util.Map;
22 import java.util.LinkedHashMap;
23
24 /**
25 * Configuration types.
26 *
27 * @version $Rev: 390312 $ $Date: 2006-03-30 19:48:25 -0800 (Thu, 30 Mar 2006) $
28 */
29 public class ConfigurationModuleType implements Serializable {
30 private static final long serialVersionUID = -4121586344416418391L;
31
32 private static final Map typesByName = new LinkedHashMap();
33
34 public static final ConfigurationModuleType EAR = new ConfigurationModuleType("EAR", 0);
35
36 public static final ConfigurationModuleType EJB = new ConfigurationModuleType("EJB", 1);
37
38 public static final ConfigurationModuleType CAR = new ConfigurationModuleType("CAR", 2);
39
40 public static final ConfigurationModuleType RAR = new ConfigurationModuleType("RAR", 3);
41
42 public static final ConfigurationModuleType WAR = new ConfigurationModuleType("WAR", 4);
43
44 public static final ConfigurationModuleType SERVICE = new ConfigurationModuleType("SERVICE", 5);
45
46 public static final ConfigurationModuleType SPR = new ConfigurationModuleType("SPR", 6);
47
48 private static final ConfigurationModuleType[] fromInt = {EAR, EJB, CAR, RAR, WAR, SERVICE, SPR};
49
50 private final String name;
51
52 private final int value;
53
54 public static ConfigurationModuleType getFromValue(int index) {
55 if (index < 0 || index >= fromInt.length) {
56 return null;
57 }
58 return fromInt[index];
59 }
60
61 public static ConfigurationModuleType getFromValue(Integer index) {
62 return getFromValue(index.intValue());
63 }
64
65 public static ConfigurationModuleType getByName(String name) {
66 return (ConfigurationModuleType) typesByName.get(name);
67 }
68
69
70 /**
71 * This constructor is intentionally public: this class is not a type-safe
72 * enumeration.
73 */
74 public ConfigurationModuleType(String name, int value) {
75 this.name = name;
76 this.value = value;
77 typesByName.put(name, this);
78 }
79
80 public String getName() {
81 return name;
82 }
83
84 /**
85 * Gets the identifier of this type. For a configuration associated to
86 * a J2EE ModuleType, this value MUST be equal to ModuleType.getValue().
87 *
88 * @return the index
89 */
90 public int getValue() {
91 return value;
92 }
93
94 public String toString() {
95 return name;
96 }
97
98 protected Object readResolve() {
99 return fromInt[value];
100 }
101
102 }