001/*
002 *  Copyright 2010 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.plugins.repository;
017
018import java.util.Collection;
019import java.util.HashMap;
020import java.util.Map;
021import java.util.Set;
022
023import org.apache.avalon.framework.component.Component;
024import org.apache.avalon.framework.configuration.Configuration;
025/*
026 *  Copyright 2010 Anyware Services
027 *
028 *  Licensed under the Apache License, Version 2.0 (the "License");
029 *  you may not use this file except in compliance with the License.
030 *  You may obtain a copy of the License at
031 *
032 *      http://www.apache.org/licenses/LICENSE-2.0
033 *
034 *  Unless required by applicable law or agreed to in writing, software
035 *  distributed under the License is distributed on an "AS IS" BASIS,
036 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
037 *  See the License for the specific language governing permissions and
038 *  limitations under the License.
039 */
040import org.apache.avalon.framework.configuration.ConfigurationException;
041
042import org.ametys.runtime.plugin.ExtensionPoint;
043import org.ametys.runtime.plugin.component.AbstractLogEnabled;
044
045/**
046 * {@link ExtensionPoint} hosting the nodetype definitions
047 */
048public class NodeTypeDefinitionsExtensionPoint extends AbstractLogEnabled implements ExtensionPoint<String>, Component
049{
050    /** Avalon Role */
051    public static final String ROLE = NodeTypeDefinitionsExtensionPoint.class.getName();
052    
053    private Map<String, String> _nodetypeDefinitions = new HashMap<>();
054    
055    public void addExtension(String id, String pluginName, String featureName, Configuration configuration) throws ConfigurationException
056    {
057        String nodetypeDef = configuration.getChild("nodetype-definition", true).getValue(null);
058        
059        // Add the nodetype definition 
060        if (nodetypeDef != null)
061        {
062            if (_nodetypeDefinitions.containsKey(id))
063            {
064                getLogger().error("The nodetype definition of id " + id + " is already defined. It will be ignored");
065            }
066            else
067            {
068                _nodetypeDefinitions.put(id, "plugin:" + pluginName + "://" + nodetypeDef);
069            }
070        }
071    }
072
073    public void initializeExtensions() throws Exception
074    {
075        // Empty
076    }
077
078    @Override
079    public boolean hasExtension(String id)
080    {
081        return _nodetypeDefinitions.containsKey(id);
082    }
083
084    @Override
085    public String getExtension(String id)
086    {
087        if (hasExtension(id))
088        {
089            return _nodetypeDefinitions.get(id);
090        }
091        return null;
092    }
093
094    @Override
095    public Set<String> getExtensionsIds()
096    {
097        return _nodetypeDefinitions.keySet();
098    }
099    
100    /**
101     * Returns the declared nodetypes definitions.
102     * @return the declared nodetypes definitions.
103     */
104    public Collection<String> getNodeTypeDefinitions()
105    {
106        return _nodetypeDefinitions.values();
107    }
108    
109}