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