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.util.Locale; 019 020import org.xml.sax.ContentHandler; 021import org.xml.sax.SAXException; 022 023import org.ametys.plugins.repository.data.UnknownDataException; 024import org.ametys.plugins.repository.data.holder.group.impl.ModelLessComposite; 025import org.ametys.plugins.repository.data.holder.group.impl.ModelLessRepeater; 026import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 027import org.ametys.runtime.model.exception.BadItemTypeException; 028import org.ametys.runtime.model.exception.NotUniqueTypeException; 029import org.ametys.runtime.model.exception.UnknownTypeException; 030import org.ametys.runtime.model.type.ModelItemType; 031 032/** 033 * Interface for data containers without models 034 */ 035public interface ModelLessDataHolder extends DataHolder 036{ 037 /** 038 * {@inheritDoc} 039 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 040 */ 041 @Override 042 public ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException; 043 044 /** 045 * {@inheritDoc} 046 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 047 */ 048 @Override 049 public ModelLessRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException; 050 051 /** 052 * {@inheritDoc} 053 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 054 */ 055 @Override 056 public boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException; 057 058 /** 059 * Retrieves the value of the data at the given path 060 * The type of the value will be deduced from the stored data. 061 * 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 062 * @param <T> type of the value to retrieve. Should match the given data type 063 * @param dataPath path of the data 064 * @return the value of the data or <code>null</code> if not exists. 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. 065 * @throws IllegalArgumentException if the given data path is null or empty 066 * @throws UnknownTypeException if there is no compatible type with the data at the given data path 067 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 068 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 069 */ 070 public <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException; 071 072 /** 073 * Retrieves the value of the data at the given path, or the default value 074 * @param <T> type of the value to retrieve. Should match the given data type 075 * @param dataPath path of the data 076 * @param defaultValue default value 077 * @return the value of the data 078 * @throws IllegalArgumentException if the given data path is null or empty 079 * @throws UnknownTypeException if there is no compatible type with the data at the given data path 080 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 081 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 082 */ 083 public <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException; 084 085 /** 086 * Retrieves the value of the data at the given path 087 * @param <T> type of the value to retrieve. Should match the given data type 088 * @param dataPath path of the data 089 * @param dataTypeId type identifier of the data 090 * @return the value of the data or <code>null</code> if not exists 091 * @throws IllegalArgumentException if the given data path is null or empty 092 * @throws UnknownTypeException if the given type isn't available for this data holder's type extension point 093 * @throws BadItemTypeException if the given type doesn't match the type of the value stored in the repository at the given path 094 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 095 */ 096 public <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException; 097 098 /** 099 * Retrieves the value of the data at the given path, or the default value 100 * @param <T> type of the value to retrieve. Should match the given data type 101 * @param dataPath path of the data 102 * @param dataTypeId type identifier of the data 103 * @param defaultValue default value 104 * @return the value of the data 105 * @throws IllegalArgumentException if the given data path is null or empty 106 * @throws UnknownTypeException if the given type isn't available for this data holder's type extension point 107 * @throws BadItemTypeException if the given type doesn't match the type of the value stored in the repository at the given path 108 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 109 */ 110 public <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException; 111 112 /** 113 * Checks if the value of the data at the given path is multiple 114 * @param dataPath path of the data to check 115 * @return <code>true</code> if the value of the data is multiple, <code>false</code> otherwise 116 * @throws IllegalArgumentException if the given data path is null or empty 117 * @throws UnknownDataException the data at the given path does not exist 118 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 119 */ 120 public boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException; 121 122 /** 123 * Retrieves the type of the data at the given path 124 * @param dataPath path of the data 125 * @return the type of the data 126 * @throws IllegalArgumentException if the given data path is null or empty 127 * @throws UnknownDataException if there is no data in the repository at the given path 128 * @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 129 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) 130 * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple 131 */ 132 public ModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException; 133 134 /** 135 * {@inheritDoc} 136 * @throws UnknownTypeException if there is no compatible type with the saxed value 137 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) with the saxed value 138 */ 139 @Override 140 public default void toSAX(ContentHandler contentHandler) throws SAXException, UnknownTypeException, NotUniqueTypeException 141 { 142 DataHolder.super.toSAX(contentHandler); 143 } 144 145 /** 146 * {@inheritDoc} 147 * @throws UnknownTypeException if there is no compatible type with the saxed value 148 * @throws NotUniqueTypeException if there are many compatible types (there is no way to determine which type is the good one) with the saxed value 149 */ 150 @Override 151 public default void toSAX(ContentHandler contentHandler, Locale locale) throws SAXException, UnknownTypeException, NotUniqueTypeException 152 { 153 DataHolder.super.toSAX(contentHandler, locale); 154 } 155}