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.ametysobject;
017
018import java.io.IOException;
019import java.util.Collection;
020import java.util.Optional;
021
022import org.xml.sax.ContentHandler;
023import org.xml.sax.SAXException;
024
025import org.ametys.plugins.repository.AmetysObject;
026import org.ametys.plugins.repository.data.holder.DataHolder;
027import org.ametys.plugins.repository.data.holder.ModifiableDataHolder;
028import org.ametys.plugins.repository.data.holder.group.Composite;
029import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
030import org.ametys.runtime.model.exception.BadItemTypeException;
031import org.ametys.runtime.model.exception.NotUniqueTypeException;
032import org.ametys.runtime.model.exception.UndefinedItemPathException;
033import org.ametys.runtime.model.exception.UnknownTypeException;
034import org.ametys.runtime.model.type.DataContext;
035
036/**
037 * {@link AmetysObject} that can handle data.
038 */
039public interface DataAwareAmetysObject extends AmetysObject, DataHolder
040{
041    /**
042     * Returns the {@link DataHolder} of this {@link AmetysObject}.
043     * @return the {@link DataHolder} of this {@link AmetysObject}
044     */
045    public DataHolder getDataHolder();
046    
047    public default Composite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException
048    {
049        return getDataHolder().getComposite(compositePath);
050    }
051    
052    public default boolean hasValue(String dataPath) throws IllegalArgumentException
053    {
054        return getDataHolder().hasValue(dataPath);
055    }
056    
057    public default boolean hasNonEmptyValue(String dataPath) throws IllegalArgumentException
058    {
059        return getDataHolder().hasNonEmptyValue(dataPath);
060    }
061
062    public default Collection<String> getDataNames()
063    {
064        return getDataHolder().getDataNames();
065    }
066    
067    public default void copyTo(ModifiableDataHolder dataHolder) throws UndefinedItemPathException, BadItemTypeException, UnknownTypeException, NotUniqueTypeException
068    {
069        getDataHolder().copyTo(dataHolder);
070    }
071    
072    public default void dataToSAX(ContentHandler contentHandler, String dataPath) throws SAXException, IOException
073    {
074        getDataHolder().dataToSAX(contentHandler, dataPath);
075    }
076    
077    public default void dataToSAX(ContentHandler contentHandler, String dataPath, DataContext context) throws SAXException, IOException
078    {
079        getDataHolder().dataToSAX(contentHandler, dataPath, context);
080    }
081    
082    public default RepositoryData getRepositoryData()
083    {
084        return getDataHolder().getRepositoryData();
085    }
086    
087    public default Optional<? extends DataHolder> getParentDataHolder()
088    {
089        return getDataHolder().getParentDataHolder();
090    }
091    
092    public default DataHolder getRootDataHolder()
093    {
094        return getDataHolder().getRootDataHolder();
095    }
096}