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.Locale;
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.repositorydata.RepositoryData;
029import org.ametys.runtime.model.exception.BadItemTypeException;
030import org.ametys.runtime.model.exception.NotUniqueTypeException;
031import org.ametys.runtime.model.exception.UndefinedItemPathException;
032import org.ametys.runtime.model.exception.UnknownTypeException;
033
034/**
035 * {@link AmetysObject} that can handle data.
036 */
037public interface DataAwareAmetysObject extends AmetysObject, DataHolder
038{
039    /**
040     * Returns the {@link DataHolder} of this {@link AmetysObject}.
041     * @return the {@link DataHolder} of this {@link AmetysObject}
042     */
043    public DataHolder getDataHolder();
044    
045    public default boolean hasValue(String dataPath) throws IllegalArgumentException
046    {
047        return getDataHolder().hasValue(dataPath);
048    }
049
050    public default Collection<String> getDataNames()
051    {
052        return getDataHolder().getDataNames();
053    }
054    
055    public default void copyTo(ModifiableDataHolder dataHolder) throws UndefinedItemPathException, BadItemTypeException, UnknownTypeException, NotUniqueTypeException
056    {
057        getDataHolder().copyTo(dataHolder);
058    }
059    
060    public default void dataToSAX(ContentHandler contentHandler, String dataPath, Locale locale) throws SAXException, IOException
061    {
062        getDataHolder().dataToSAX(contentHandler, dataPath, locale);
063    }
064    
065    public default RepositoryData getRepositoryData()
066    {
067        return getDataHolder().getRepositoryData();
068    }
069}