001/*
002 *  Copyright 2018 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 */
016package org.ametys.cms.workflow.extensions;
017
018import java.util.HashMap;
019import java.util.Map;
020import java.util.Set;
021
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024import org.apache.commons.lang3.StringUtils;
025
026import org.ametys.runtime.plugin.ExtensionPoint;
027
028/**
029 * Abstract extension point for workflow functions  
030 */
031public abstract class AbstractFunctionsExtensionPoint implements ExtensionPoint<String>
032{
033    private Map<String, String> _extensions = new HashMap<>();
034    
035    public void addExtension(String id, String pluginName, String featureName, Configuration configuration) throws ConfigurationException
036    {
037        String componentRole = configuration.getChild("component").getValue(null);
038        if (StringUtils.isBlank(componentRole))
039        {
040            throw new ConfigurationException("No 'component' attribute found to denote the component to call", configuration);
041        }
042        
043        _extensions.put(id, componentRole);
044    }
045
046    public void initializeExtensions() throws Exception
047    {
048        // Nothing
049    }
050
051    public boolean hasExtension(String id)
052    {
053        return _extensions.containsKey(id);
054    }
055
056    public String getExtension(String id)
057    {
058        return _extensions.get(id);
059    }
060
061    public Set<String> getExtensionsIds()
062    {
063        return _extensions.keySet();
064    }
065}