Here you can find the source of allocateReadOnlyI18nDictionary(final Attributes attributes, final ResourceBundle resourceBundle)
public static Dictionary allocateReadOnlyI18nDictionary(final Attributes attributes, final ResourceBundle resourceBundle)
//package com.java2s; /**/*from www .j a v a 2s. com*/ * * Copyright 2008-2009 (C) The original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; import java.util.HashSet; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; import java.util.jar.Attributes; public class Main { public static Dictionary allocateReadOnlyI18nDictionary(final Attributes attributes, final ResourceBundle resourceBundle) { return new Dictionary() { public int size() { return attributes.size(); } public boolean isEmpty() { return attributes.isEmpty(); } public Enumeration keys() { Set<String> set = new HashSet<String>(); for (Object key : attributes.keySet()) set.add(key.toString()); return Collections.enumeration(set); } public Enumeration elements() { return new Enumeration() { final Enumeration enumeration = Collections.enumeration(attributes.values()); public boolean hasMoreElements() { return enumeration.hasMoreElements(); } public Object nextElement() { return localize(enumeration.nextElement().toString()); } }; } public Object get(Object key) { return localize(attributes.getValue((String) key)); } protected Object localize(String result) { if (result != null && result.length() > 0 && result.charAt(0) == '%') { result = result.substring(1); if (resourceBundle != null) try { result = resourceBundle.getString(result); } catch (MissingResourceException ignore) { } } return result; } public Object put(Object key, Object value) { throw new UnsupportedOperationException("Read-only dictionary"); } public Object remove(Object key) { throw new UnsupportedOperationException("Read-only dictionary"); } }; } }