@@ -0,0 +1,1808 @@
+/*%0A * Copyright (C) 2012-present the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.pf4j;%0A%0Aimport java.util.Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A/**%0A * An %7B@link ExtensionFactory%7D that always returns a specific instance.%0A * Optional, you can specify the extension classes for which you want singletons.%0A *%0A * @author Decebal Suiu%0A */%0Apublic class SingletonExtensionFactory extends DefaultExtensionFactory %7B%0A%0A    private final List%3CString%3E extensionClassNames;%0A%0A    private Map%3CString, Object%3E cache;%0A%0A    public SingletonExtensionFactory(String... extensionClassNames) %7B%0A        this.extensionClassNames = Arrays.asList(extensionClassNames);%0A%0A        cache = new HashMap%3C%3E(); // simple cache implementation%0A    %7D%0A%0A    @Override%0A    public Object create(Class%3C?%3E extensionClass) %7B%0A        String extensionClassName = extensionClass.getName();%0A        if (cache.containsKey(extensionClassName)) %7B%0A            return cache.get(extensionClassName);%0A        %7D%0A%0A        Object extension = super.create(extensionClass);%0A        if (extensionClassNames.isEmpty() %7C%7C extensionClassNames.contains(extensionClassName)) %7B%0A            cache.put(extensionClassName, extension);%0A        %7D%0A%0A        return extension;%0A    %7D%0A%0A%7D%0A

Add SingletonExtensionFactory (see #232)