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