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.runtime.model.ModelItemGroup;
027
028/**
029 * Class for modifiable model aware composites
030 */
031public class DefaultModifiableModelAwareComposite extends DefaultModelAwareComposite implements ModifiableIndexableComposite
032{
033    /** The modifiable repository data of this composite */
034    protected ModifiableRepositoryData _modifiableRepositoryData;
035    
036    /** the default implementation of a {@link ModifiableModelAwareDataHolder} to use */
037    protected ModifiableIndexableDataHolder _modifiableDefaultDataHolder;
038    
039    /**
040     * Creates a modifiable model aware composite
041     * @param repositoryData the repository data of the composite
042     * @param parent the parent of the created {@link DataHolder}
043     * @param root the root {@link DataHolder}
044     * @param definition the definition of the composite
045     */
046    public DefaultModifiableModelAwareComposite(ModifiableRepositoryData repositoryData, ModifiableIndexableDataHolder parent, ModifiableIndexableDataHolder root, ModelItemGroup definition)
047    {
048        super(repositoryData, parent, root, definition);
049        _modifiableDefaultDataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, Optional.of(parent), Optional.of(root), definition);
050        _modifiableRepositoryData = repositoryData;
051    }
052    
053    @Override
054    public ModifiableIndexableDataHolder getDefaultDataHolder()
055    {
056        return _modifiableDefaultDataHolder;
057    }
058    
059    @Override
060    public ModifiableRepositoryData getRepositoryData()
061    {
062        return _modifiableRepositoryData;
063    }
064}