001/*
002 *  Copyright 2019 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.Optional;
020
021import org.xml.sax.ContentHandler;
022import org.xml.sax.SAXException;
023
024import org.ametys.plugins.repository.AmetysObject;
025import org.ametys.plugins.repository.data.UnknownDataException;
026import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
027import org.ametys.plugins.repository.data.holder.group.impl.ModelLessComposite;
028import org.ametys.plugins.repository.data.type.RepositoryModelItemType;
029import org.ametys.runtime.model.exception.BadDataPathCardinalityException;
030import org.ametys.runtime.model.exception.BadItemTypeException;
031import org.ametys.runtime.model.exception.NotUniqueTypeException;
032import org.ametys.runtime.model.exception.UnknownTypeException;
033import org.ametys.runtime.model.type.DataContext;
034
035/**
036 * Model less {@link AmetysObject} that can handle data.
037 */
038public interface ModelLessDataAwareAmetysObject extends DataAwareAmetysObject, ModelLessDataHolder
039{
040    @Override
041    public ModelLessDataHolder getDataHolder();
042    
043    public default ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException
044    {
045        return getDataHolder().getComposite(compositePath);
046    }
047
048    public default boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
049    {
050        return DataAwareAmetysObject.super.hasValue(dataPath);
051    }
052
053    public default boolean hasNonEmptyValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
054    {
055        return DataAwareAmetysObject.super.hasNonEmptyValue(dataPath);
056    }
057
058    public default <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException
059    {
060        return getDataHolder().getValue(dataPath);
061    }
062    
063    public default <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException
064    {
065        return getDataHolder().getValue(dataPath, defaultValue);
066    }
067
068    public default <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException
069    {
070        return getDataHolder().getValueOfType(dataPath, dataTypeId);
071    }
072    
073    public default <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException
074    {
075        return getDataHolder().getValueOfType(dataPath, dataTypeId, defaultValue);
076    }
077    
078    public default boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException
079    {
080        return getDataHolder().isMultiple(dataPath);
081    }
082    
083    public default RepositoryModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException
084    {
085        return getDataHolder().getType(dataPath);
086    }
087    
088    public default void dataToSAX(ContentHandler contentHandler, DataContext context) throws SAXException, IOException, UnknownTypeException, NotUniqueTypeException
089    {
090        getDataHolder().dataToSAX(contentHandler, context);
091    }
092    
093    public default Optional<? extends ModelLessDataHolder> getParentDataHolder()
094    {
095        return getDataHolder().getParentDataHolder();
096    }
097    
098    public default ModelLessDataHolder getRootDataHolder()
099    {
100        return getDataHolder().getRootDataHolder();
101    }
102}