001/*
002 *  Copyright 2018 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.data.holder.group.impl;
017
018import java.util.Optional;
019
020import org.ametys.cms.data.holder.ModifiableIndexableDataHolder;
021import org.ametys.cms.data.holder.group.ModifiableIndexableComposite;
022import org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder;
023import org.ametys.plugins.repository.data.holder.DataHolder;
024import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder;
025import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
026import org.ametys.plugins.repository.lock.LockableAmetysObject;
027import org.ametys.runtime.model.ModelItemGroup;
028
029/**
030 * Class for modifiable model aware composites
031 */
032public class DefaultModifiableModelAwareComposite extends DefaultModelAwareComposite implements ModifiableIndexableComposite
033{
034    /** The modifiable repository data of this composite */
035    protected ModifiableRepositoryData _modifiableRepositoryData;
036    
037    /** the default implementation of a {@link ModifiableModelAwareDataHolder} to use */
038    protected ModifiableIndexableDataHolder _modifiableDefaultDataHolder;
039    
040    /**
041     * Creates a modifiable model aware composite
042     * @param repositoryData the repository data of the composite
043     * @param definition the definition of the composite
044     * @param lockableAmetysObject the ametys object that can be locked on data modification
045     * @param parent the parent of the created {@link DataHolder}
046     * @param root the root {@link DataHolder}
047     */
048    public DefaultModifiableModelAwareComposite(ModifiableRepositoryData repositoryData, ModelItemGroup definition, Optional<LockableAmetysObject> lockableAmetysObject, ModifiableIndexableDataHolder parent, ModifiableIndexableDataHolder root)
049    {
050        super(repositoryData, definition, parent, root);
051        _modifiableDefaultDataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, definition, lockableAmetysObject, Optional.of(parent), Optional.of(root));
052        _modifiableRepositoryData = repositoryData;
053    }
054    
055    @Override
056    public ModifiableIndexableDataHolder getDefaultDataHolder()
057    {
058        return _modifiableDefaultDataHolder;
059    }
060    
061    @Override
062    public ModifiableRepositoryData getRepositoryData()
063    {
064        return _modifiableRepositoryData;
065    }
066}