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 package org.apache.geronimo.kernel.repository;
018
019 import java.io.Serializable;
020 import java.util.Map;
021 import java.util.HashMap;
022
023 /**
024 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
025 */
026 public class ImportType implements Serializable {
027 private static final long serialVersionUID = 9084371394522950958L;
028
029 private static final Map typesByName = new HashMap();
030
031 // todo this class imples that there are only classes and services... is that true?
032 public static final ImportType ALL = new ImportType("ALL");
033 public static final ImportType CLASSES = new ImportType("CLASSES");
034 public static final ImportType SERVICES = new ImportType("SERVICES");
035
036 public static Object getByName(String name) {
037 ImportType type = (ImportType) typesByName.get(name);
038 if (type == null) throw new IllegalStateException("Unknown import type: " + name);
039 return type;
040 }
041
042 private final String name;
043
044 private ImportType(String name) {
045 this.name = name;
046 typesByName.put(name, this);
047 }
048
049 public String getName() {
050 return name;
051 }
052
053 public String toString() {
054 return name;
055 }
056
057 protected Object readResolve() {
058 String name = this.name;
059 return getByName(name);
060 }
061 }