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