use std::io;
use std::sync::Arc;
use crate::IEngineConfiguration;
use crate::TemplateMode;
use crate::engine::TemplateData;
use crate::util::TemplateWriter;
use super::{IModelVisitor, ITemplateEvent};
pub trait IModel: Send + Sync {
fn get_template_data(&self) -> Option<&TemplateData> {
None
}
fn get_template_data_arc(&self) -> Option<Arc<TemplateData>> {
None
}
fn get_configuration(&self) -> &dyn IEngineConfiguration;
fn get_template_mode(&self) -> TemplateMode;
fn size(&self) -> usize;
fn get(&self, pos: usize) -> Arc<dyn ITemplateEvent>;
fn add(&mut self, event: Option<Arc<dyn ITemplateEvent>>) -> Result<(), IModelError>;
fn insert(
&mut self,
pos: usize,
event: Option<Arc<dyn ITemplateEvent>>,
) -> Result<(), IModelError>;
fn replace(
&mut self,
pos: usize,
event: Option<Arc<dyn ITemplateEvent>>,
) -> Result<(), IModelError>;
fn add_model(&mut self, model: Option<&dyn IModel>) -> Result<(), IModelError>;
fn insert_model(&mut self, pos: usize, model: Option<&dyn IModel>) -> Result<(), IModelError>;
fn remove(&mut self, pos: usize) -> Result<(), IModelError>;
fn reset(&mut self) -> Result<(), IModelError>;
fn clone_model(&self) -> Box<dyn IModel>;
fn accept(&self, visitor: &mut dyn IModelVisitor);
fn write(&self, writer: &mut dyn TemplateWriter) -> io::Result<()>;
}
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum IModelError {
#[error(
"Modifications are not allowed on immutable model objects. This model object is an immutable \
implementation of the org.thymeleaf.model.IModel interface, and no modifications are allowed in \
order to keep cache consistency and improve performance. To modify model events, convert first your \
immutable model object to a mutable one by means of the org.thymeleaf.model.IModel#cloneModel() method"
)]
ImmutableModel,
#[error("Model event index out of bounds: {0}")]
IndexOutOfBounds(usize),
#[error(
"Cannot insert event of type TemplateStart/TemplateEnd. These events can only be added \
to models internally during template parsing."
)]
TemplateBoundaryInsertion,
#[error(
"Cannot add model of class org.thymeleaf.engine.Model to the current template, as it was created using a different Template Engine Configuration."
)]
DifferentConfiguration,
#[error(
"Cannot add model of class org.thymeleaf.engine.Model to the current template, as it was created using a different Template Mode: {model_mode} instead of the current {current_mode}"
)]
DifferentTemplateMode {
model_mode: TemplateMode,
current_mode: TemplateMode,
},
#[error("Cannot handle template event type")]
UnsupportedEvent,
}