001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.felix.framework.util;
020
021 import java.util.*;
022
023
024 /**
025 * This is a simple class that implements a <tt>Dictionary</tt>
026 * from a <tt>Map</tt>. The resulting dictionary is immutable.
027 **/
028 public class MapToDictionary extends Dictionary
029 {
030 /**
031 * Map source.
032 **/
033 private Map m_map = null;
034
035 public MapToDictionary(Map map)
036 {
037 if (map == null)
038 {
039 throw new IllegalArgumentException("Source map cannot be null.");
040 }
041 m_map = map;
042 }
043
044 public Enumeration elements()
045 {
046 return new IteratorToEnumeration(m_map.values().iterator());
047 }
048
049 public Object get(Object key)
050 {
051 return m_map.get(key);
052 }
053
054 public boolean isEmpty()
055 {
056 return m_map.isEmpty();
057 }
058
059 public Enumeration keys()
060 {
061 return new IteratorToEnumeration(m_map.keySet().iterator());
062 }
063
064 public Object put(Object key, Object value)
065 {
066 throw new UnsupportedOperationException();
067 }
068
069 public Object remove(Object key)
070 {
071 throw new UnsupportedOperationException();
072 }
073
074 public int size()
075 {
076 return m_map.size();
077 }
078
079 public String toString()
080 {
081 return m_map.toString();
082 }
083 }