001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.ametys.runtime.plugin; 018 019import java.util.HashMap; 020import java.util.Map; 021import java.util.Set; 022 023import org.apache.avalon.framework.activity.Initializable; 024import org.apache.avalon.framework.component.Component; 025 026import org.ametys.runtime.plugin.component.AbstractLogEnabled; 027 028/** 029 * Abstract implementation of an extension point.<br> 030 * Contains only helper methods. Tha actual job has to be done in the {@link #addExtension(String, String, String, org.apache.avalon.framework.configuration.Configuration)} 031 * @param <T> the type of the managed extensions 032 */ 033public abstract class AbstractExtensionPoint<T> extends AbstractLogEnabled implements ExtensionPoint<T>, Initializable, Component 034{ 035 /** 036 * Map containing the extensions.<br> 037 * The key is the unique id of the extension. 038 */ 039 protected Map<String, T> _extensions; 040 041 public void initialize() throws Exception 042 { 043 _extensions = new HashMap<>(); 044 } 045 046 public T getExtension(String id) 047 { 048 return _extensions.get(id); 049 } 050 051 public Set<String> getExtensionsIds() 052 { 053 return _extensions.keySet(); 054 } 055 056 public boolean hasExtension(String id) 057 { 058 return _extensions.containsKey(id); 059 } 060}