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.type; 017 018import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData; 019import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 020import org.ametys.runtime.model.exception.BadItemTypeException; 021import org.ametys.runtime.model.type.DataContext; 022import org.ametys.runtime.model.type.ElementType; 023 024/** 025 * Interface for types of elements stored in the repository 026 * @param <T> Type of the element value 027 */ 028public interface RepositoryElementType<T> extends ElementType<T>, RepositoryModelItemType 029{ 030 /** 031 * Read the value in the given repository data 032 * @param parentData repository data containing the value 033 * @param name the name of the element to read 034 * @return the value. Can return a T or a T[]. That's why the return type is Object 035 * @throws BadItemTypeException if the reading value doesn't match this element type 036 */ 037 public Object read(RepositoryData parentData, String name) throws BadItemTypeException; 038 039 /** 040 * Write the value into the given repository data 041 * @param parentData repository where to store the value. 042 * @param name the name of the element to write 043 * @param value the value to write. Can be a T or a T[]. That's why it is an Object 044 * @throws BadItemTypeException If the given value doesn't match this element type 045 */ 046 public void write(ModifiableRepositoryData parentData, String name, Object value) throws BadItemTypeException; 047 048 /** 049 * Retrieve the value to SAX for externalizable data 050 * @param value the value to SAX 051 * This view item gives context for the SAX event that will be generated here. 052 * @param context The context of the data to SAX 053 * @return the value to SAX for externalizable data 054 */ 055 public default Object externalizableValueToSAX(Object value, DataContext context) 056 { 057 return valueToJSONForClient(value, context); 058 } 059}