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 org.ametys.plugins.repository.AmetysObject;
019import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
020import org.ametys.plugins.repository.data.holder.group.impl.ModelAwareComposite;
021import org.ametys.plugins.repository.data.holder.group.impl.ModelAwareRepeater;
022import org.ametys.runtime.model.exception.BadDataPathCardinalityException;
023import org.ametys.runtime.model.exception.BadItemTypeException;
024import org.ametys.runtime.model.exception.UndefinedItemPathException;
025import org.ametys.runtime.model.type.ModelItemType;
026
027/**
028 * Model aware {@link AmetysObject} that can handle data.
029 */
030public interface ModelAwareDataAwareAmetysObject extends DataAwareAmetysObject, ModelAwareDataHolder
031{
032    @Override
033    public ModelAwareDataHolder getDataHolder();
034    
035    public default ModelAwareComposite getComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
036    {
037        return getDataHolder().getComposite(compositePath);
038    }
039
040    public default ModelAwareRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
041    {
042        return getDataHolder().getRepeater(repeaterPath);
043    }
044    
045    public default boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
046    {
047        return DataAwareAmetysObject.super.hasValue(dataPath);
048    }
049
050    public default <T extends Object> T getValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
051    {
052        return getDataHolder().getValue(dataPath);
053    }
054    
055    public default <T> T getValue(String dataPath, boolean useDefaultFromModel, T defaultValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
056    {
057        return getDataHolder().getValue(dataPath, useDefaultFromModel, defaultValue);
058    }
059    
060    public default boolean isMultiple(String path) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException
061    {
062        return getDataHolder().isMultiple(path);
063    }
064
065    public default ModelItemType getType(String dataPath) throws IllegalArgumentException, UndefinedItemPathException
066    {
067        return getDataHolder().getType(dataPath);
068    }
069}