-
Notifications
You must be signed in to change notification settings - Fork 2
/
Handler.kt
44 lines (37 loc) · 1.21 KB
/
Handler.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package staks
import javax.xml.stream.events.XMLEvent
/**
* Basic interface for everything that should handle [XMLEvent]s.
*/
interface Handler<T> {
/**
* Producer of value which was parser from XML.
*/
val value: () -> T
/**
* true if should not be matched after first match.
*/
val isSingular: Boolean
/**
* true if this concrete handler cares about these concrete event.
*/
fun matches(event: XMLEvent): Boolean
/**
* Handle the XMLEvent and fill the result if needed.
* It's responsibility of handler to leave XMLEventReader in consistent state — for example wait for
* corresponding closing tag.
* @throws IllegalArgumentException if can not build object
*/
fun process(ev: XMLEvent)
/**
* Clear the state: Most probably the handler is stateful, but it may be invoked several times if, for example,
* it' inside list — the same handler will be invoked on every list invocation.
*/
fun reset()
/**
* call handler to obtain earlier calculated value.
* @throws IllegalArgumentException if can not parse data ot ir's not available
* @return T
*/
operator fun invoke() = value.invoke()
}