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.holder; 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.data.UnknownDataException; 025import org.ametys.plugins.repository.data.holder.group.impl.ModelLessComposite; 026import org.ametys.plugins.repository.data.type.RepositoryModelItemType; 027import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 028import org.ametys.runtime.model.exception.BadItemTypeException; 029import org.ametys.runtime.model.exception.NotUniqueTypeException; 030import org.ametys.runtime.model.exception.UnknownTypeException; 031import org.ametys.runtime.model.type.DataContext; 032 033/** 034 * Interface for data containers without models 035 */ 036public interface ModelLessDataHolder extends DataHolder 037{ 038 /** 039 * {@inheritDoc} 040 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 041 */ 042 @Override 043 public ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException; 044 045 /** 046 * {@inheritDoc} 047 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 048 */ 049 @Override 050 public boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException; 051 052 /** 053 * {@inheritDoc} 054 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 055 */ 056 @Override 057 public boolean hasNonEmptyValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException; 058 059 /** 060 * Retrieves the value of the data at the given path 061 * The type of the value will be deduced from the stored data. 062 * In some cases, the type can be wrong. For example, it is impossible to know if a stored date is a date or a date time 063 * @param <T> type of the value to retrieve. Should match the given data type 064 * @param dataPath path of the data 065 * @return the value of the data or <code>null</code> if not exists or is empty. The object returned may be of a generic class defined by the storage. For example, an url may be returned as a String. Use the 2 arguments version to ensure to get the right kind of Object. 066 * @throws IllegalArgumentException if the given data path is null or empty 067 * @throws UnknownTypeException if there is no compatible type with the data at the given data path 068 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 069 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 070 */ 071 public <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException; 072 073 /** 074 * Retrieves the value of the data at the given path if exists and is not empty, or the default value 075 * @param <T> type of the value to retrieve. Should match the given data type 076 * @param dataPath path of the data 077 * @param defaultValue default value 078 * @return the value of the data, <code>null</code> if the data exists but is empty, or the given default value 079 * @throws IllegalArgumentException if the given data path is null or empty 080 * @throws UnknownTypeException if there is no compatible type with the data at the given data path 081 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 082 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 083 */ 084 public <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException; 085 086 /** 087 * Retrieves the value of the data at the given path 088 * @param <T> type of the value to retrieve. Should match the given data type 089 * @param dataPath path of the data 090 * @param dataTypeId type identifier of the data 091 * @return the value of the data or <code>null</code> if not exists or is empty 092 * @throws IllegalArgumentException if the given data path is null or empty 093 * @throws UnknownTypeException if the given type isn't available for this data holder's type extension point 094 * @throws BadItemTypeException if the given type doesn't match the type of the stored value at the given path 095 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 096 */ 097 public <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException; 098 099 /** 100 * Retrieves the value of the data at the given path if exists and is not empty, or the default value 101 * @param <T> type of the value to retrieve. Should match the given data type 102 * @param dataPath path of the data 103 * @param dataTypeId type identifier of the data 104 * @param defaultValue default value 105 * @return the value of the data, <code>null</code> if the data exists but is empty, or the given default value 106 * @throws IllegalArgumentException if the given data path is null or empty 107 * @throws UnknownTypeException if the given type isn't available for this data holder's type extension point 108 * @throws BadItemTypeException if the given type doesn't match the type of the stored value at the given path 109 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 110 */ 111 public <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException; 112 113 /** 114 * Checks if the value of the data at the given path is multiple 115 * @param dataPath path of the data to check 116 * @return <code>true</code> if the value of the data is multiple, <code>false</code> otherwise 117 * @throws IllegalArgumentException if the given data path is null or empty 118 * @throws UnknownDataException the data at the given path does not exist 119 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 120 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 121 */ 122 public boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, NotUniqueTypeException, BadDataPathCardinalityException; 123 124 /** 125 * Retrieves the type of the data at the given path 126 * @param dataPath path of the data 127 * @return the type of the data 128 * @throws IllegalArgumentException if the given data path is null or empty 129 * @throws UnknownDataException if there is no data stored at the given path 130 * @throws UnknownTypeException if there is no compatible type with the data at the given data path or if the data is a repeater entry but the composite type is not available 131 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 132 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 133 */ 134 public RepositoryModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException; 135 136 /** 137 * Generates SAX events for data contained in this {@link DataHolder} 138 * @param contentHandler the {@link ContentHandler} that will receive the SAX events 139 * @throws SAXException if an error occurs during the SAX events generation 140 * @throws IOException if an error occurs while reading a value using the I/O API 141 * @throws UnknownTypeException if there is no compatible type with the saxed value 142 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) with the saxed value 143 */ 144 public default void dataToSAX(ContentHandler contentHandler) throws SAXException, IOException, UnknownTypeException, NotUniqueTypeException 145 { 146 dataToSAX(contentHandler, DataContext.newInstance()); 147 } 148 149 /** 150 * Generates SAX events for data contained in this {@link DataHolder} 151 * @param contentHandler the {@link ContentHandler} that will receive the SAX events 152 * @param context The context of the data to SAX 153 * @throws SAXException if an error occurs during the SAX events generation 154 * @throws IOException if an error occurs while reading a value using the I/O API 155 * @throws UnknownTypeException if there is no compatible type with the saxed value 156 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) with the saxed value 157 */ 158 public void dataToSAX(ContentHandler contentHandler, DataContext context) throws SAXException, IOException, UnknownTypeException, NotUniqueTypeException; 159 160 @Override 161 public Optional<? extends ModelLessDataHolder> getParentDataHolder(); 162 163 @Override 164 public ModelLessDataHolder getRootDataHolder(); 165}