001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.kernel.config;
017:
018: import java.io.Serializable;
019: import java.util.Map;
020: import java.util.LinkedHashMap;
021:
022: /**
023: * Configuration types.
024: *
025: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
026: */
027: public class ConfigurationModuleType implements Serializable {
028: private static final long serialVersionUID = -4121586344416418391L;
029:
030: private static final Map typesByName = new LinkedHashMap();
031:
032: public static final ConfigurationModuleType EAR = new ConfigurationModuleType(
033: "EAR", 0);
034:
035: public static final ConfigurationModuleType EJB = new ConfigurationModuleType(
036: "EJB", 1);
037:
038: public static final ConfigurationModuleType CAR = new ConfigurationModuleType(
039: "CAR", 2); // app client
040:
041: public static final ConfigurationModuleType RAR = new ConfigurationModuleType(
042: "RAR", 3);
043:
044: public static final ConfigurationModuleType WAR = new ConfigurationModuleType(
045: "WAR", 4);
046:
047: public static final ConfigurationModuleType SERVICE = new ConfigurationModuleType(
048: "SERVICE", 5);
049:
050: public static final ConfigurationModuleType SPR = new ConfigurationModuleType(
051: "SPR", 6);
052:
053: private static final ConfigurationModuleType[] fromInt = { EAR,
054: EJB, CAR, RAR, WAR, SERVICE, SPR };
055:
056: private final String name;
057:
058: private final int value;
059:
060: public static ConfigurationModuleType getFromValue(int index) {
061: if (index < 0 || index >= fromInt.length) {
062: return null;
063: }
064: return fromInt[index];
065: }
066:
067: public static ConfigurationModuleType getFromValue(Integer index) {
068: return getFromValue(index.intValue());
069: }
070:
071: public static ConfigurationModuleType getByName(String name) {
072: return (ConfigurationModuleType) typesByName.get(name);
073: }
074:
075: /**
076: * This constructor is intentionally public: this class is not a type-safe
077: * enumeration.
078: */
079: public ConfigurationModuleType(String name, int value) {
080: this .name = name;
081: this .value = value;
082: typesByName.put(name, this );
083: }
084:
085: public String getName() {
086: return name;
087: }
088:
089: /**
090: * Gets the identifier of this type. For a configuration associated to
091: * a J2EE ModuleType, this value MUST be equal to ModuleType.getValue().
092: *
093: * @return the index
094: */
095: public int getValue() {
096: return value;
097: }
098:
099: public String toString() {
100: return name;
101: }
102:
103: protected Object readResolve() {
104: return fromInt[value];
105: }
106:
107: }
|