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.cart;
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.cms.contenttype.ContentTypesHelper;
025import org.ametys.core.group.GroupManager;
026import org.ametys.plugins.repository.AmetysObjectFactory;
027import org.ametys.plugins.repository.AmetysObjectResolver;
028import org.ametys.plugins.repository.AmetysRepositoryException;
029import org.ametys.plugins.repository.RepositoryConstants;
030import org.ametys.plugins.repository.jcr.DefaultAmetysObjectFactory;
031
032/**
033 * {@link AmetysObjectFactory} for handling {@link Cart}s.
034 */
035public class CartFactory extends DefaultAmetysObjectFactory
036{
037    /** JCR nodetype for cart */
038    public static final String CART_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":cart";
039    
040    /** Group manager */
041    protected GroupManager _groupManager;
042    
043    /** Content type extension point */
044    protected ContentTypeExtensionPoint _cTypeEP;
045    /** Helper for content types */
046    protected ContentTypesHelper _contentTypesHelper;
047    /** Extension point for content types */
048    protected ContentTypeExtensionPoint _contentTypeEP;
049    
050    @Override
051    public void service(ServiceManager manager) throws ServiceException
052    {
053        super.service(manager);
054        _cTypeEP = (ContentTypeExtensionPoint) manager.lookup(ContentTypeExtensionPoint.ROLE);
055        _contentTypesHelper = (ContentTypesHelper) manager.lookup(ContentTypesHelper.ROLE);
056        _contentTypeEP = (ContentTypeExtensionPoint) manager.lookup(ContentTypeExtensionPoint.ROLE);
057        _groupManager = (GroupManager) manager.lookup(GroupManager.ROLE);
058    }
059    
060    @Override
061    public Cart getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
062    {
063        return new Cart(node, parentPath, this);
064    }
065    
066    AmetysObjectResolver getResolver()
067    {
068        return _resolver;
069    }
070    
071    /**
072     * Group manager getter.
073     * @return The group manager
074     */
075    GroupManager _getGroupsManager()
076    {
077        return _groupManager;
078    }
079    
080    /**
081     * Getter for the content types helper
082     * @return The helper for content types
083     */
084    ContentTypesHelper _getContentTypesHelper()
085    {
086        return _contentTypesHelper;
087    }
088    
089    /**
090     * Getter for the content types helper
091     * @return The helper for content types
092     */
093    ContentTypeExtensionPoint _getContentTypeEP()
094    {
095        return _contentTypeEP;
096    }
097}