-
Notifications
You must be signed in to change notification settings - Fork 103
/
Boots.scala
38 lines (32 loc) · 1.05 KB
/
Boots.scala
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
package org.fusesource.scalate
package support
import org.fusesource.scalate.util.Objects
import scala.language.reflectiveCalls
/**
* A helper class for working with Boot style classes which
* take a TemplateEngine as a constructor argument and have a zero argument
* run method.
*/
object Boots {
def invokeBoot(clazz: Class[_], injectionParameters: List[AnyRef]): Unit = {
// Structural Typing to make Reflection easier.
type Boot = {
def run: Unit
}
lazy val bootClassName = clazz.getName
val o = try {
Objects.instantiate(clazz, injectionParameters).asInstanceOf[Boot]
} catch {
case e: VirtualMachineError => throw e
case e: ThreadDeath => throw e
case e: Throwable => throw new TemplateException("Failed to create the instance of class " + bootClassName, e)
}
try {
o.run
} catch {
case e: VirtualMachineError => throw e
case e: ThreadDeath => throw e
case e: Throwable => throw new TemplateException("Failed to invoke " + bootClassName + ".run() : " + e, e)
}
}
}