001/*
002 *  Copyright 2025 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.trash.element;
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.trash.model.TrashElementModel;
024import org.ametys.plugins.repository.AmetysObjectFactory;
025import org.ametys.plugins.repository.AmetysObjectResolver;
026import org.ametys.plugins.repository.AmetysRepositoryException;
027import org.ametys.plugins.repository.RepositoryConstants;
028import org.ametys.plugins.repository.jcr.DefaultTraversableAmetysObjectFactory;
029import org.ametys.runtime.model.Model;
030
031/**
032 * {@link AmetysObjectFactory} handling {@link DefaultTrashElement}.
033 */
034public class TrashElementFactory extends DefaultTraversableAmetysObjectFactory
035{
036    /** {@link DefaultTrashElement} nodetype for resources collection */
037    public static final String TRASH_ELEMENT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":trashElement";
038
039    /** The trash root node name */
040    public static final String ROOT_NODE_NAME = RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":trash";
041
042    private Model _model;
043
044    @Override
045    public void service(ServiceManager manager) throws ServiceException
046    {
047        super.service(manager);
048        _model = (TrashElementModel) manager.lookup(TrashElementModel.ROLE);
049    }
050    
051    @Override
052    public DefaultTrashElement getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
053    {
054        return new DefaultTrashElement(node, parentPath, this);
055    }
056    
057    /**
058     * Retrieves the model
059     * @return the model
060     */
061    public Model getModel()
062    {
063        return _model;
064    }
065    
066    AmetysObjectResolver _getResolver()
067    {
068        return _resolver;
069    }
070}