001/*
002 *  Copyright 2019 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.odfweb.repository;
017
018import org.apache.avalon.framework.service.ServiceException;
019import org.apache.avalon.framework.service.ServiceManager;
020import org.apache.avalon.framework.service.Serviceable;
021
022import org.ametys.plugins.repository.AmetysObjectFactoryExtensionPoint;
023import org.ametys.plugins.repository.AmetysObjectResolver;
024import org.ametys.runtime.plugin.component.AbstractLogEnabled;
025import org.ametys.web.data.type.ModelItemTypeExtensionPoint;
026import org.ametys.web.service.ServiceExtensionPoint;
027
028/**
029 * Common class for factories of ODF virtual pages
030 *
031 */
032public abstract class AbstractOdfPageFactory extends AbstractLogEnabled implements Serviceable
033{
034    AmetysObjectResolver _resolver;
035    OdfPageHandler _odfPageHandler;
036    ODFPageCache _pageCache;
037    ModelItemTypeExtensionPoint _pageDataTypeExtensionPoint;
038    ServiceExtensionPoint _serviceExtensionPoint;
039    ServiceManager _manager;
040    AmetysObjectFactoryExtensionPoint _ametysObjectFactoryEP;
041    
042    @Override
043    public void service(ServiceManager manager) throws ServiceException
044    {
045        _manager = manager;
046        _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE);
047        _odfPageHandler = (OdfPageHandler) manager.lookup(OdfPageHandler.ROLE);
048        _pageCache = (ODFPageCache) manager.lookup(ODFPageCache.ROLE);
049        _pageDataTypeExtensionPoint = (ModelItemTypeExtensionPoint) manager.lookup(ModelItemTypeExtensionPoint.ROLE_PAGE_DATA);
050        _serviceExtensionPoint = (ServiceExtensionPoint) manager.lookup(ServiceExtensionPoint.ROLE);
051        _ametysObjectFactoryEP = (AmetysObjectFactoryExtensionPoint) manager.lookup(AmetysObjectFactoryExtensionPoint.ROLE);
052    }
053    
054    AmetysObjectResolver getResolver()
055    {
056        return _resolver;
057    }
058    
059    ODFPageCache getODFPageCache()
060    {
061        return _pageCache;
062    }
063    
064    OdfPageHandler getODFPageHandler()
065    {
066        return _odfPageHandler;
067    }
068    
069    ModelItemTypeExtensionPoint getPageDataTypeEP()
070    {
071        return _pageDataTypeExtensionPoint;
072    }
073    
074    ModelItemTypeExtensionPoint getZoneDataTypeEP()
075    {
076        return _pageDataTypeExtensionPoint;
077    }
078    
079    ModelItemTypeExtensionPoint getZoneItemDataTypeEP()
080    {
081        return _pageDataTypeExtensionPoint;
082    }
083    
084    ServiceExtensionPoint getServiceEP()
085    {
086        return _serviceExtensionPoint;
087    }
088    
089    FirstLevelPageFactory getFirstLevelPageFactory()
090    {
091        return (FirstLevelPageFactory) _ametysObjectFactoryEP.getExtension(FirstLevelPageFactory.class.getName());
092    }
093    
094    SecondLevelPageFactory getSecondLevelPageFactory()
095    {
096        return (SecondLevelPageFactory) _ametysObjectFactoryEP.getExtension(SecondLevelPageFactory.class.getName());
097    }
098    
099    ProgramPageFactory getProgramPageFactory()
100    {
101        return (ProgramPageFactory) _ametysObjectFactoryEP.getExtension(ProgramPageFactory.class.getName());
102    }
103    
104    CoursePageFactory getCoursePageFactory()
105    {
106        return (CoursePageFactory) _ametysObjectFactoryEP.getExtension(CoursePageFactory.class.getName());
107    }
108    
109}