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.web.frontoffice.search.metamodel.impl;
017
018import java.util.Arrays;
019import java.util.Collection;
020
021import org.apache.avalon.framework.configuration.Configurable;
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024import org.apache.avalon.framework.service.ServiceException;
025import org.apache.avalon.framework.service.ServiceManager;
026import org.apache.avalon.framework.service.Serviceable;
027
028import org.ametys.runtime.plugin.component.AbstractLogEnabled;
029import org.ametys.runtime.plugin.component.PluginAware;
030import org.ametys.web.frontoffice.search.metamodel.Returnable;
031import org.ametys.web.frontoffice.search.metamodel.Searchable;
032
033/**
034 * {@link Returnable} or {@link Searchable} which adds some parameters to the search service.
035 * <br>Declared this way:<br>
036 * <pre>
037 * &lt;extension point="org.ametys.web.frontoffice.search.metamodel.Returnable/SearchableExtensionPoint"
038 * &nbsp;&nbsp;&nbsp;&nbsp;&#032;&#032;&#032;&#032;id="..."
039 * &nbsp;&nbsp;&nbsp;&nbsp;&#032;&#032;&#032;&#032;class="..."&gt;
040 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;parameters&gt;
041 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;parameter name="..." reloadCriteriaOnChange="true"&gt;
042 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...
043 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/parameter&gt;
044 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;/parameters&gt;
045 * &lt;/extension&gt;
046 * </pre>
047 */
048public abstract class AbstractParameterAdder extends AbstractLogEnabled implements Configurable, Serviceable, PluginAware
049{
050    /** The service manager */
051    protected ServiceManager _manager;
052    /** The plugin of the extension */
053    protected String _pluginName;
054    private Configuration[] _additionalParameterConfigs;
055    
056    @Override
057    public void configure(Configuration configuration) throws ConfigurationException
058    {
059        _additionalParameterConfigs = configuration.getChild("parameters").getChildren("parameter");
060    }
061    
062    @Override
063    public void service(ServiceManager manager) throws ServiceException
064    {
065        _manager = manager;
066    }
067    
068    @Override
069    public void setPluginInfo(String pluginName, String featureName, String id)
070    {
071        _pluginName = pluginName;
072    }
073    
074    /**
075     * Retrieves the additional parameters to add to the search service
076     * <br>The ids of the parameters must be unique across all {@link Returnable}s and {@link Searchable}s
077     * <br>Implementation for {@link Searchable#additionalServiceParameters()} and {@link Returnable#additionalServiceParameters()}
078     * 
079     * @return some additional parameters to add to the search service
080     */
081    public Collection<Configuration> additionalServiceParameters()
082    {
083        return Arrays.asList(_additionalParameterConfigs);
084    }
085}