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.runtime.model.type; 017 018import java.io.IOException; 019import java.util.Optional; 020 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.runtime.model.ViewItem; 025import org.ametys.runtime.plugin.component.PluginAware; 026 027/** 028 * Interface for model item types 029 */ 030public interface ModelItemType extends PluginAware 031{ 032 /** 033 * Retrieves the identifier of the parameter type 034 * @return the identifier of the parameter type 035 */ 036 public String getId(); 037 038 /** 039 * Generates SAX events for the given value 040 * @param contentHandler the {@link ContentHandler} that will receive the SAX events 041 * @param tagName the tag name of the SAX event to generate. 042 * @param value the value to SAX 043 * @param context The context of the data to SAX 044 * @throws SAXException if an error occurs during the SAX events generation 045 * @throws IOException if an error occurs while reading a value using the I/O API 046 */ 047 public default void valueToSAX(ContentHandler contentHandler, String tagName, Object value, DataContext context) throws SAXException, IOException 048 { 049 valueToSAX(contentHandler, tagName, value, Optional.empty(), context); 050 } 051 052 /** 053 * Generates SAX events for the given value in edition mode. 054 * This method exist for legacy purposes because some types have to be saxed as JSON 055 * @param contentHandler the {@link ContentHandler} that will receive the SAX events 056 * @param tagName the tag name of the SAX event to generate. 057 * @param value the value to SAX 058 * @param viewItem The optional view item corresponding item that is currently saxed. 059 * This view item gives context for the SAX event that will be generated here. 060 * @param context The context of the data to SAX 061 * @throws SAXException if an error occurs during the SAX events generation 062 * @throws IOException if an error occurs while reading a value using the I/O API 063 */ 064 public void valueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) throws SAXException, IOException; 065 066 /** 067 * Generates SAX events for the given value 068 * @param contentHandler the {@link ContentHandler} that will receive the SAX events 069 * @param tagName the tag name of the SAX event to generate. 070 * @param value the value to SAX 071 * @param viewItem The optional view item corresponding item that is currently saxed. 072 * This view item gives context for the SAX event that will be generated here. 073 * @param context The context of the data to SAX 074 * @throws SAXException if an error occurs during the SAX events generation 075 * @throws IOException if an error occurs while reading a value using the I/O API 076 */ 077 public void valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) throws SAXException, IOException; 078}