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.plugins.repository.data.holder;
017
018import java.util.Optional;
019
020import org.ametys.plugins.repository.data.holder.group.ModifiableComposite;
021import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
022import org.ametys.runtime.model.exception.BadItemTypeException;
023
024/**
025 * Interface for modifiable data containers
026 */
027public interface ModifiableDataHolder extends DataHolder
028{
029    @Override
030    public ModifiableComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException;
031    
032    /**
033     * Retrieves the composite at the given path
034     * @param compositePath path of the composite to retrieve
035     * @param createNew <code>true</code> to create the composite if it does not exist, <code>false</code> otherwise
036     * @return the composite or <code>null</code> if createNew is <code>false</code> and value not exists or is empty
037     * @throws IllegalArgumentException if the given composite path is null or empty
038     * @throws BadItemTypeException if the stored value at the given path is not a composite
039     */
040    public ModifiableComposite getComposite(String compositePath, boolean createNew) throws IllegalArgumentException, BadItemTypeException;
041    
042    /**
043     * Removes the stored value of the data at the given path
044     * @param dataPath path of the data
045     * @throws IllegalArgumentException if the given data path is null or empty
046     * @throws BadItemTypeException if the value of the parent of the given path is not an item container
047     */
048    public void removeValue(String dataPath) throws IllegalArgumentException, BadItemTypeException;
049    
050    @Override
051    public ModifiableRepositoryData getRepositoryData();
052    
053    @Override
054    public Optional<? extends ModifiableDataHolder> getParentDataHolder();
055    
056    @Override
057    public ModifiableDataHolder getRootDataHolder();
058}