package wf.servitor.engine.dispatcher import org.apache.commons.jexl3.JexlContext import org.apache.commons.jexl3.introspection.JexlMethod import wf.servitor.engine.exception.UnresolvedRemoteCallException class NamespaceFaker( private val namespace: String, private val dispatchedValues: MutableList, val nextValueIndex: Int = dispatchedValues.size ) : JexlContext { override fun has(name: String) = true override fun get(name: String): Any { return CallExecutor { if (dispatchedValues.isNotEmpty()) { val first = dispatchedValues.first() dispatchedValues.removeAt(0) first } else { throw UnresolvedRemoteCallException(namespace, name, it.toList(), nextValueIndex) } } } override fun set(name: String, value: Any?) { throw UnsupportedOperationException() } class CallExecutor(val dispatchedValue: (Array) -> Any?) : JexlMethod { override fun tryInvoke(name: String?, obj: Any?, vararg params: Any?): Any { TODO("not implemented") } override fun isCacheable() = false; override fun getReturnType(): Class<*> = TODO() override fun tryFailed(rval: Any?) = true override fun invoke(obj: Any?, vararg params: Any?): Any? { return dispatchedValue(params); } } }