Interface IModel
- All Known Implementing Classes:
TemplateModel
Interface representing all model objects.
Models are sequences of events (ITemplateEvent
) normally representing a specific element
with all its body and nested elements, or even an entire document.
IModel
implementations are the classes used at the template engine for representing
templates or fragments.
From the user's code (e.g. custom processors), implementations of IModel
are created using an
IModelFactory
, obtained from ITemplateContext.getModelFactory()
.
- Since:
- 3.0.0
- Author:
- Daniel Fernández
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(IModelVisitor visitor) Accept a visitor implementingIModelVisitor
.void
add
(ITemplateEvent event) Adds an event at the end of the sequence.void
Add an entire model at the end of the sequence.Clones the model and all its events.get
(int pos) Retrieves a specific event from the model sequence.Returns the engine configuration that was used for creating this model.Returns the template mode used for creating this model.void
insert
(int pos, ITemplateEvent event) Inserts an event into a specific position in the sequence.void
insertModel
(int pos, IModel model) Inserts an entire model into a specific position in this model's sequence.void
remove
(int pos) Remove an event from the sequence.void
replace
(int pos, ITemplateEvent event) Replaces the event at the specified position with the one passed as argument.void
reset()
Remove all events from the model sequence.int
size()
The size of the model (number ofITemplateEvent
objects contained).void
Write this model (its events) through the specified writer.
-
Method Details
-
getConfiguration
IEngineConfiguration getConfiguration()Returns the engine configuration that was used for creating this model.
- Returns:
- the engine configuration.
-
getTemplateMode
TemplateMode getTemplateMode()Returns the template mode used for creating this model.
- Returns:
- the template mode.
-
size
int size()The size of the model (number of
ITemplateEvent
objects contained).- Returns:
- the size of the model.
-
get
Retrieves a specific event from the model sequence.
- Parameters:
pos
- the position (zero-based) of the event to be retrieved.- Returns:
- the retrieved event.
-
add
Adds an event at the end of the sequence.
- Parameters:
event
- the event to be added.
-
insert
Inserts an event into a specific position in the sequence.
- Parameters:
pos
- the position to insert the event (zero-based).event
- the event to be inserted.
-
replace
Replaces the event at the specified position with the one passed as argument.
- Parameters:
pos
- the position of the event to be replaced (zero-based).event
- the event to serve as replacement.
-
addModel
Add an entire model at the end of the sequence. This effectively appends the
model
argument's sequence to this one.- Parameters:
model
- the model to be appended.
-
insertModel
Inserts an entire model into a specific position in this model's sequence.
- Parameters:
pos
- the position to insert the mdoel (zero-based).model
- the model to be inserted.
-
remove
void remove(int pos) Remove an event from the sequence.
- Parameters:
pos
- the position (zero-based) of the event to be removed.
-
reset
void reset()Remove all events from the model sequence.
-
cloneModel
IModel cloneModel()Clones the model and all its events.
- Returns:
- the new model.
-
accept
Accept a visitor implementing
IModelVisitor
. This visitor will be executed for each event in the sequence.- Parameters:
visitor
- the visitor object.
-
write
Write this model (its events) through the specified writer.
- Parameters:
writer
- the writer that will be used for writing the model.- Throws:
IOException
- should any exception happen.
-