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 */ 017 018 package org.apache.geronimo.kernel.config; 019 020 import java.io.Serializable; 021 import java.util.Map; 022 import java.util.LinkedHashMap; 023 024 /** 025 * Configuration types. 026 * 027 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $ 028 */ 029 public class ConfigurationModuleType implements Serializable { 030 private static final long serialVersionUID = -4121586344416418391L; 031 032 private static final Map typesByName = new LinkedHashMap(); 033 034 public static final ConfigurationModuleType EAR = new ConfigurationModuleType("EAR", 0); 035 036 public static final ConfigurationModuleType EJB = new ConfigurationModuleType("EJB", 1); 037 038 public static final ConfigurationModuleType CAR = new ConfigurationModuleType("CAR", 2); // app client 039 040 public static final ConfigurationModuleType RAR = new ConfigurationModuleType("RAR", 3); 041 042 public static final ConfigurationModuleType WAR = new ConfigurationModuleType("WAR", 4); 043 044 public static final ConfigurationModuleType SERVICE = new ConfigurationModuleType("SERVICE", 5); 045 046 public static final ConfigurationModuleType SPR = new ConfigurationModuleType("SPR", 6); 047 048 private static final ConfigurationModuleType[] fromInt = {EAR, EJB, CAR, RAR, WAR, SERVICE, SPR}; 049 050 private final String name; 051 052 private final int value; 053 054 public static ConfigurationModuleType getFromValue(int index) { 055 if (index < 0 || index >= fromInt.length) { 056 return null; 057 } 058 return fromInt[index]; 059 } 060 061 public static ConfigurationModuleType getFromValue(Integer index) { 062 return getFromValue(index.intValue()); 063 } 064 065 public static ConfigurationModuleType getByName(String name) { 066 return (ConfigurationModuleType) typesByName.get(name); 067 } 068 069 070 /** 071 * This constructor is intentionally public: this class is not a type-safe 072 * enumeration. 073 */ 074 public ConfigurationModuleType(String name, int value) { 075 this.name = name; 076 this.value = value; 077 typesByName.put(name, this); 078 } 079 080 public String getName() { 081 return name; 082 } 083 084 /** 085 * Gets the identifier of this type. For a configuration associated to 086 * a J2EE ModuleType, this value MUST be equal to ModuleType.getValue(). 087 * 088 * @return the index 089 */ 090 public int getValue() { 091 return value; 092 } 093 094 public String toString() { 095 return name; 096 } 097 098 protected Object readResolve() { 099 return fromInt[value]; 100 } 101 102 }