001/*
002 *  Copyright 2016 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.search.solr.schema;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.List;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024import org.apache.avalon.framework.service.Serviceable;
025
026import org.ametys.cms.search.model.SystemProperty;
027import org.ametys.cms.search.model.SystemPropertyExtensionPoint;
028import org.ametys.runtime.plugin.component.AbstractLogEnabled;
029
030/**
031 * Provides all the schema elements defined by system properties.
032 */
033public class SystemPropertySchemaDefinitionProvider extends AbstractLogEnabled implements SchemaDefinitionProvider, Serviceable
034{
035    
036    /** The system property extension point. */
037    protected SystemPropertyExtensionPoint _sysPropEP;
038    
039    @Override
040    public void service(ServiceManager manager) throws ServiceException
041    {
042        _sysPropEP = (SystemPropertyExtensionPoint) manager.lookup(SystemPropertyExtensionPoint.ROLE);
043    }
044    
045    @Override
046    public Collection<SchemaDefinition> getDefinitions()
047    {
048        List<SchemaDefinition> definitions = new ArrayList<>();
049        
050        for (String id : _sysPropEP.getExtensionsIds())
051        {
052            SystemProperty property = _sysPropEP.getExtension(id);
053            
054            definitions.addAll(property.getSchemaDefinitions());
055        }
056        
057        return definitions;
058    }
059
060}