001/*
002 *  Copyright 2013 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.queriesdirectory;
017
018import javax.jcr.Node;
019
020import org.apache.avalon.framework.service.ServiceException;
021import org.apache.avalon.framework.service.ServiceManager;
022
023import org.ametys.cms.contenttype.ContentTypeExtensionPoint;
024import org.ametys.core.group.GroupManager;
025import org.ametys.plugins.repository.AmetysObjectFactory;
026import org.ametys.plugins.repository.AmetysRepositoryException;
027import org.ametys.plugins.repository.RepositoryConstants;
028import org.ametys.plugins.repository.jcr.DefaultAmetysObjectFactory;
029
030
031/**
032 * {@link AmetysObjectFactory} for handling {@link Query}s.
033 */
034public class QueryFactory extends DefaultAmetysObjectFactory
035{
036    
037    /** JCR nodetype for query */
038    public static final String QUERY_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":query";
039    
040    /** Group manager */
041    protected GroupManager _groupManager;
042    
043    /** Content type extension point */
044    protected ContentTypeExtensionPoint _cTypeEP;
045
046    /** The Query DAO */
047    protected QueryDAO _queryDAO;
048    
049    @Override
050    public void service(ServiceManager manager) throws ServiceException
051    {
052        super.service(manager);
053        _cTypeEP = (ContentTypeExtensionPoint) manager.lookup(ContentTypeExtensionPoint.ROLE);
054        _groupManager = (GroupManager) manager.lookup(GroupManager.ROLE);
055        _queryDAO = (QueryDAO) manager.lookup(QueryDAO.ROLE);
056    }
057    
058    @Override
059    public Query getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
060    {
061        return new Query(node, parentPath, this);
062    }
063    
064    /**
065     * Group manager getter.
066     * @return The group manager
067     */
068    GroupManager _getGroupManager()
069    {
070        return _groupManager;
071    }
072    
073    /**
074     * Getter for the content type extension point
075     * @return The content type EP.
076     */
077    ContentTypeExtensionPoint _getContentTypeExtensionPoint()
078    {
079        return _cTypeEP;
080    }
081    
082    QueryDAO getQueryDAO()
083    {
084        return _queryDAO;
085    }
086    
087}